Skip to content

fix(xiaohongshu): scope note interaction selectors to .interact-container#839

Open
y4h2 wants to merge 1 commit intojackwener:mainfrom
y4h2:fix/xiaohongshu-note-likes-selector
Open

fix(xiaohongshu): scope note interaction selectors to .interact-container#839
y4h2 wants to merge 1 commit intojackwener:mainfrom
y4h2:fix/xiaohongshu-note-likes-selector

Conversation

@y4h2
Copy link
Copy Markdown

@y4h2 y4h2 commented Apr 6, 2026

Summary

xiaohongshu note was returning wrong like/collect/comment counts for any note that had user comments.

Root cause

The DOM selectors .like-wrapper .count / .collect-wrapper .count / .chat-wrapper .count are not unique to the post's main interaction bar. Every comment in the comment section also renders a .like-wrapper > .count for its own like button (and the comment count input has .chat-wrapper). document.querySelector returns the first match, which on a note with comments is a comment's count, not the post's.

In practice the post's true counts live inside .interact-container, while comment-level counts are scattered throughout the comment list above/below it. Whether the bug fired depended on DOM order, which is why the bug surfaced inconsistently across different notes.

Fix

Scope each selector to .interact-container:

- const likes    = clean(document.querySelector('.like-wrapper .count'))
- const collects = clean(document.querySelector('.collect-wrapper .count'))
- const comments = clean(document.querySelector('.chat-wrapper .count'))
+ const likes    = clean(document.querySelector('.interact-container .like-wrapper .count'))
+ const collects = clean(document.querySelector('.interact-container .collect-wrapper .count'))
+ const comments = clean(document.querySelector('.interact-container .chat-wrapper .count'))

Verification

Tested on three notes that previously returned wrong values:

Note Before (likes) After (likes) Real value
A (notId 69d15115...) 2 74 74 ✓
B (noteId 69c176ea...) 1 796 796 ✓
C (noteId 69cc56c3...) 1 269 269 ✓

All three now match the values displayed on xiaohongshu.com.

Test plan

  • Run opencli xiaohongshu note <url> against several notes with comments
  • Verify likes / collects / comments match what's shown on the page
  • Maintainer: run existing test suite (note.test.ts if any)

…iner

The .like-wrapper / .collect-wrapper / .chat-wrapper class names are
also used by every comment's like/reply buttons in the comment section.
querySelector returned the FIRST match — which on a note with comments
is a comment's count, not the post's. As a result, `xiaohongshu note`
returned wrong like/collect/comment counts for any note that had user
comments.

Scoping each selector to .interact-container (the post's main
interaction bar) returns the correct post-level counts.

Verified on multiple notes:
- Note A: was returning likes=2, now correctly returns likes=74
- Note B: was returning likes=1, now correctly returns likes=796
- Note C: was returning likes=1, now correctly returns likes=269
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