-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
Soxasora
wants to merge
42
commits into
stackernews:master
Choose a base branch
from
Soxasora:live_comments_enhancements
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
+489
−21
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…new comment; cleanup: resolvers, logs
…omments are there
…bility change, light cleanup
… comment injection
… use of constants, general cleanup
…he correct Item query
…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
… queue comments via state
… 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
…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
…do: two recursive counts might be too much
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
f8ec5f4
to
25e8e12
Compare
- 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
6fba7fb
to
1700652
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Continues #2115 and #791
UX and logic enhancements to the Live Comments system
item.comments.*
)WIP:
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 anItem
.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 theitem
, 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 anItem
with client-side navigation.For this reason, new comments feature the
injected
field, which becomestrue
when we actually inject them and becomesfalse
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 thenewComments
field.TODO
Favicon:
useHasNewNotes
Scroll:
Auto-show:
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