Skip to content

fix(comments): continue sparse comment updates before stopping#61

Merged
tomcasaburi merged 3 commits into
masterfrom
fix/sparse-comment-followup
Jun 7, 2026
Merged

fix(comments): continue sparse comment updates before stopping#61
tomcasaburi merged 3 commits into
masterfrom
fix/sparse-comment-followup

Conversation

@tomcasaburi

@tomcasaburi tomcasaburi commented Jun 7, 2026

Copy link
Copy Markdown
Member

Summary

  • Continue one-shot comment updates once when a CID-only comment first resolves with sparse immutable data.
  • Make refresh wait for that sparse follow-up so callers receive mutable thread data such as replies.
  • Cover one-shot loading, live auto-update, refresh, and reset cleanup behavior with regression tests.

Verification

  • yarn build
  • yarn test
  • yarn test:coverage
  • yarn lint exits 0 with existing warnings
  • node scripts/verify-hooks-stores-coverage.mjs still reports existing hook/store coverage gaps outside this fix; the new sparse follow-up cleanup path is covered

Notes

The regression tests fail without the source fix because sparse CID-only comments receive only one update() call, then pass with the fix because the mutable follow-up runs before stopping.


Note

Medium Risk
Changes comment lifecycle timing (when live comments stop and when refresh resolves), which can affect reply/thread display; scope is limited to the comments store with broad regression tests.

Overview
Fixes CID-only comments that finish their first update() with only immutable IPFS fields (timestamp without updatedAt) and were stopped too early, so mutable thread data (e.g. replyCount, replies) never loaded.

The comments store now tracks a one-shot sparse follow-up: after a successful update that still looks sparse, it triggers one more update() when the comment is in one-shot load, auto-update, or refresh flows. refreshComment / waitForCommentUpdateCycle stay pending until that follow-up completes (or fails). Follow-up state is cleared on stop, reset, and update errors; comment.update rejections now normalize errors, try to emit on the live comment, and record them in store errors instead of only tracing.

Adds a createSparseComment test helper and regression tests for add, auto-update, refresh, reject paths, and cleanup on reset/stop/refresh.

Reviewed by Cursor Bugbot for commit 625f3e6. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of comment updates and data loading to ensure comments display complete information after initial load.
    • Enhanced comment refresh functionality to properly resolve follow-up updates.
  • Tests

    • Expanded test coverage for comment update and loading scenarios.

@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR extends the comments store to track and handle sparse comment follow-up updates. When a comment update lacks updatedAt but has timestamp, the store now requests a conditional follow-up update and coordinates multi-stage refresh cycles through event handlers, error handlers, and store reset logic.

Changes

Sparse comment follow-up tracking

Layer / File(s) Summary
Sparse follow-up state tracking and helpers
src/stores/comments/comments-store.ts
Module-level sparseCommentFollowupRequested map tracks pending follow-up requests per comment CID; helper predicates determine when to trigger and await follow-ups based on updatedAt presence and flag state.
Sparse follow-up update event and error handling
src/stores/comments/comments-store.ts
"updatingstatechange" event handler conditionally triggers sparse follow-up on first success and clears the flag on subsequent completion; requestCommentUpdate error handler clears the flag and logs errors.
Reset logic for sparse follow-up bookkeeping
src/stores/comments/comments-store.ts
resetCommentsStore deletes sparseCommentFollowupRequested entries to prevent test state leakage.
Test helper and sparse follow-up lifecycle tests
src/stores/comments/comments-store.test.ts
createSparseComment helper mocks comments with controlled update behavior; four tests verify one-shot lifecycle, auto-update continuation, refresh resolution, and reset cleanup for sparse follow-ups.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • bitsocialnet/bitsocial-react-hooks#31: Introduced the auto-update/start-stop/refresh machinery that this PR extends with sparse follow-up tracking.
  • bitsocialnet/bitsocial-react-hooks#32: Also modifies comment lifecycle logic in the same store file (addCommentToStore/startCommentAutoUpdate/refreshComment/reset), so the sparse follow-up tracking and that PR's live-comment cleanup are directly related store update flows.

Poem

🐰 A sparse comment waits for its mutable twin,
Tracking requests with a map tucked within,
When updatedAt arrives at the gate,
The follow-up completes—oh, how great!
Two-stage updates dance, tests verify clean.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: ensuring sparse comment updates continue running before the comment update stops.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/sparse-comment-followup

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread src/stores/comments/comments-store.ts
@tomcasaburi

Copy link
Copy Markdown
Member Author

Addressed the valid Cursor Bugbot finding in 359f7d0.

The store now clears pending sparse-follow-up bookkeeping whenever it intentionally stops a live comment, so a stopped in-flight sparse follow-up cannot suppress the next update cycle. Added regression coverage for both unsubscribe/stop and refresh-while-a-follow-up-is-pending paths; those two tests fail against the previous PR commit and pass with the fix.

Verification run after the change:

  • yarn build
  • yarn type-check
  • yarn lint exits 0 with existing warnings
  • yarn test
  • yarn test:coverage
  • node scripts/verify-hooks-stores-coverage.mjs still reports existing repo-wide hook/store coverage gaps; no new sparse follow-up path is uncovered

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 359f7d0. Configure here.

Comment thread src/stores/comments/comments-store.ts
@tomcasaburi

Copy link
Copy Markdown
Member Author

Addressed the remaining valid Cursor Bugbot finding about sparse follow-up update rejections.

What changed:

  • A rejected comment.update() now clears sparse follow-up bookkeeping, records/emits the update error for existing refresh waiters, and runs the one-shot stop cleanup so live comments do not keep listening forever.
  • Added regression coverage for both failure modes: one-shot sparse follow-up cleanup and refreshComment() rejecting instead of hanging.
  • Added defensive tests for update errors when a legacy comment cannot emit errors or its error emitter throws.

Evidence:

  • The new sparse rejection tests pass with the fix.
  • With only the source fix temporarily reversed, those same tests fail: the one-shot comment is not stopped, and refresh times out instead of rejecting with the update error.

Verification:

  • yarn prettier
  • yarn test src/stores/comments/comments-store.test.ts
  • focused sparse rejection tests, including the temporary reverse-source failure proof
  • yarn build
  • yarn type-check
  • yarn lint (0 errors; existing warning backlog remains)
  • yarn test (1096 passed, 6 skipped)
  • yarn test:coverage (1096 passed, 6 skipped)
  • node scripts/verify-hooks-stores-coverage.mjs still reports the repo's existing hook/store coverage gaps; comments-store.ts is back to the known pre-existing uncovered line 86 only.

@tomcasaburi tomcasaburi merged commit 0d20b32 into master Jun 7, 2026
8 checks passed
@tomcasaburi tomcasaburi deleted the fix/sparse-comment-followup branch June 7, 2026 05:22
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