feat(docs): comments on documents - #65
Conversation
There was a problem hiding this comment.
pulkitxm has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 35 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughAdds document comments with database persistence, authorization, threaded replies, REST endpoints, optimistic client mutations, realtime synchronization, and a document-surface UI for rendering and managing comments. ChangesDocument comment foundation
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 6
🧹 Nitpick comments (2)
apps/web/src/lib/query/sync.ts (1)
26-38: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicate delta-merge logic for comments vs. doc comments.
docCommentDeltaSchema/applyDocCommentDeltaare copy-pasted fromcommentDeltaSchema/applyCommentDeltawith only thereactionsfield removed. Consider factoring the shared insert/update/delete/staleness logic into a generic helper parameterized by the entity shape, to avoid future divergence between the two code paths.Also applies to: 175-199
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/web/src/lib/query/sync.ts` around lines 26 - 38, Refactor the duplicated delta processing between docCommentDeltaSchema/applyDocCommentDelta and commentDeltaSchema/applyCommentDelta into a shared generic helper parameterized by the entity schema or shape. Preserve each entity’s distinct fields, including the absence of reactions for document comments, while centralizing insert, update, delete, and staleness handling so both paths remain behaviorally consistent.apps/web/src/features/docs/doc-comments.test.tsx (1)
107-116: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winTest doesn't exercise the composer's actual submit wiring.
Calling
createMutate(...)directly bypassesDocComments'sonSubmithandler that wires the composer tocreate.mutate. Consider driving this through the rendered composer (type text, click submit) so a regression in the actual wiring would be caught.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/web/src/features/docs/doc-comments.test.tsx` around lines 107 - 116, Update the optimistic comment test around DocComments to submit through the rendered doc-comment composer instead of calling createMutate directly: enter “Looks solid” in the composer, trigger its submit control, then retain the existing mutation-call and pending-comment assertions so the component’s onSubmit wiring is exercised.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/web/src/lib/query/use-doc-comments.ts`:
- Around line 13-26: Update useDocComments to consume
docCommentListSchema.nextCursor and support fetching subsequent comment pages,
exposing the accumulated comments and a way to request more results. Preserve
the existing disabled behavior when docId is null and ensure pagination stops
when nextCursor is absent, rather than silently returning only the first
DOC_COMMENT_PAGE_SIZE comments.
- Around line 46-48: Update the pending ID generation in the optimistic comment
flow to use Bun.randomUUIDv7() instead of the millisecond-based ISO timestamp,
while preserving the existing pending- prefix and onSuccess dedup/removal
behavior.
In `@apps/web/src/lib/realtime/delta-bridge.tsx`:
- Around line 105-113: Update patchDocCommentCaches to extract each cached
query’s docId and ignore actions whose incoming.docId differs before calling
applyDocCommentDelta. Pass the matching docId through the existing cache-update
flow so only the corresponding document’s comments are modified.
In `@packages/core/src/content/doc-comment-service.ts`:
- Around line 74-78: Validate page.cursor against an existing document comment
before adding the pagination filter, and return or throw the established
invalid-cursor error when no matching record exists. Update the cursor-handling
logic in the document comment pagination method, preserving the existing tuple
comparison only for valid cursors.
- Line 73: Update listDocComments to exclude replies whose root comment is
soft-deleted, not just comments matching docId and deletedAt. Extend the query
around the filters construction to join or otherwise validate the parent/root
comment’s deletedAt status, while preserving visibility of non-deleted roots and
their replies.
In `@packages/db/src/schema/content.ts`:
- Line 159: Update the docComment schema’s parentId definition to add a
self-referencing foreign key to the doc_comment table’s id, matching the
doc.parentId pattern and configuring onDelete: 'set null'.
---
Nitpick comments:
In `@apps/web/src/features/docs/doc-comments.test.tsx`:
- Around line 107-116: Update the optimistic comment test around DocComments to
submit through the rendered doc-comment composer instead of calling createMutate
directly: enter “Looks solid” in the composer, trigger its submit control, then
retain the existing mutation-call and pending-comment assertions so the
component’s onSubmit wiring is exercised.
In `@apps/web/src/lib/query/sync.ts`:
- Around line 26-38: Refactor the duplicated delta processing between
docCommentDeltaSchema/applyDocCommentDelta and
commentDeltaSchema/applyCommentDelta into a shared generic helper parameterized
by the entity schema or shape. Preserve each entity’s distinct fields, including
the absence of reactions for document comments, while centralizing insert,
update, delete, and staleness handling so both paths remain behaviorally
consistent.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: e27d7a87-fe99-4977-ab52-27497e5b1b9d
📒 Files selected for processing (17)
apps/web/src/app/api/docs/[id]/comments/[commentId]/route.tsapps/web/src/app/api/docs/[id]/comments/route.tsapps/web/src/features/docs/doc-comments.test.tsxapps/web/src/features/docs/doc-comments.tsxapps/web/src/features/docs/doc-surface.tsxapps/web/src/lib/query/keys.tsapps/web/src/lib/query/schemas.tsapps/web/src/lib/query/sync.test.tsapps/web/src/lib/query/sync.tsapps/web/src/lib/query/use-doc-comments.tsapps/web/src/lib/realtime/delta-bridge.tsxpackages/core/src/content/doc-comment-service.test.tspackages/core/src/content/doc-comment-service.tspackages/core/src/index.tspackages/core/src/realtime/backfill.tspackages/db/src/schema/content.tspackages/shared/src/events/sync.ts
There was a problem hiding this comment.
pulkitxm has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
Add threaded, realtime comments to the internal document reading view, mirroring issue comments.