Skip to content

Enhancements to live comments #2269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 42 commits into
base: master
Choose a base branch
from

Conversation

Soxasora
Copy link
Member

@Soxasora Soxasora commented Jul 7, 2025

Description

Continues #2115 and #791
UX and logic enhancements to the Live Comments system

  • Recursively show all new comments of a thread
  • Recursively show all new comments of a new comment
  • Highlight newly injected comments
  • Change the favicon when there are new comments
  • Fix deepest comment not updating because it lacks nested comments structure (item.comments.*)
  • Logic enhancements

WIP:

  • Scroll to the new comment
  • Automatically show new comments when user is not on the page

Media

Recursive injection of nested new comments

Screen.Recording.2025-07-15.at.13.23.33.mp4

Single injection: TODO video

Mobile experience: TODO video

Additional Context

To enable further enhancements and changes to the live comments system, parts of the original code are being changed.

Count all new comments

For threads/nested comments, we might not have direct new comments, but we could have them in deeper levels.
By transversing the comment structure recursively we can check if there are nested new comments and show the "show all new comments" button.

Show all new comments of a thread button

It shows all new comments of a thread/nested comment by recursively checking all child (new)comments for even newer comments and deduping along the way if they're already present in the comments field of an Item.

As new comments can arrive but the button might still be stuck with the first Item snapshot we passed, for every recursion it checks the cache for an updated version of the item, ensuring that we're getting all new comments, at every level.

Highlight newly injected comments

Highlighting is based on time (commentsViewedAt < item.createdAt), this might work as-is but this data is only available if we are visiting an Item with client-side navigation.
For this reason, new comments feature the injected field, which becomes true when we actually inject them and becomes false when we hover/click on a highlighted new comment.
Also, injecting a new comment updates the commentsViewedAt local storage field, so that on the next visit, we avoid marking intentionally injected comments as new unread comments.

Another challenge was the fact that we don't highlight individual comments that we didn't read yet, but we highlight the whole new thread.
New comments are injected intentionally by the user, so every new comment is highlighted, not just the thread.

Deduplication

Something that wasn't quite right was that on the previous version of live comments, the hook deduped new comments against the comments field of an Item, and the button had to dedupe again because of unintended cache changes. Now only the button dedupes when it actually needs to inject the comments, and the hook dedupes only the newComments field.

TODO

Favicon:

  • evaluate re-usage of useHasNewNotes
  • decide if prop-drilling is a necessary evil
  • create favicon: ✅
  • analyze favicon not working on client-side navigation

Scroll:

  • all

Auto-show:

  • all

Checklist

Are your changes backward compatible? Please answer below:
For example, a change is not backward compatible if you removed a GraphQL field or dropped a database column.

Yes, these are completely new additions, no breakage or changes on the way comments and comment injection works.

On a scale of 1-10 how well and how have you QA'd this change and any features it might affect? Please answer below:
5, WIP and in iterative QA

For frontend changes: Tested on mobile, light and dark mode? Please answer below:
Yes, iterative QA

Did you introduce any new environment variables? If so, call them out explicitly here:
n/a

Soxasora and others added 30 commits April 18, 2025 05:34
…fix leak on useEffect because of missing sort

atomic apollo cache manipulations; manage top sort not being present in item query cache
queue nested comments without a parent, retry on the next poll
fix commit messages
… dropped comments;

ui: show amount of new comments

refactor: correct function positioning;

cleanup: useless logs
…Comments readFragment fallback to received comment
…ss dedupe on ShowNewComments, count nested ncomments from fresh new comments
Soxasora and others added 10 commits July 5, 2025 17:08
…ates; fix: nested comment structures

- new comments indicator for bottomed-out replies
- ncomments sync for parent and its ancestors
- limited comments fragment for comments that don't have CommentsRecursive
- reduce cache complexity by removing useless roundtrips

ux: live comments indicator on bottomedOut replies

fix: dedupe newComments before displaying ShowNewComments to avoid false positives

enhance: store ids of new comments in the cache, instead of carrying full comments that would get discarded anyway

hotfix: newComments deduplication ID mismatch, filter null comments from freshNewComments

fix: ncomments not updating for all comment levels; refactor: share Reply update ancestors' ncomments function with ShowNewComments

cleanup: better naming to indicate the total number of comments including nested comments

fix: increment parent comment ncomments

cleanup: Items that will have comments will always have a structure where item.comments is true

cleanup: reduce code complexity checking the nested comment update result instead of preventively reading the fragment

cleanup: avoid double-updating ncomments on parent

fix: don't use CommentsRecursive for bottomed-out comments

cleanup: better fragment naming; add TODO for absolute bottom comments
fixes:
- sync local commentsViewedAt on comment injection, to avoid double outline on item re-visit
- avoid double highlighting when client-side visiting an item and injecting a new comment

cleanups:
- move ShowNewComments functions to dedicated lib/comments.js
- bust auto-show enhancement due to bad useEffect usage

todos:
- two recursive counts might be too much
@Soxasora Soxasora force-pushed the live_comments_enhancements branch from f8ec5f4 to 25e8e12 Compare July 14, 2025 18:12
Soxasora added 2 commits July 14, 2025 21:44
- lib/comments.js explanations for its functions
- itemUpdateQuery, commentUpdateFragment, getLatestCommentCreatedAt on comments.js
- format too many imports from comments.js

todo:
- we're not deduping comments for isThread, which forces us at this state, to dedupe twice
…on in every case but top level; cleanups

cleanups:
- better separation of concerns for lib/comments.js
- don't show new comment count, avoiding useless complexity
- simpler topLevel/nested logic
- add comments
@Soxasora Soxasora force-pushed the live_comments_enhancements branch from 6fba7fb to 1700652 Compare July 15, 2025 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant