-
Notifications
You must be signed in to change notification settings - Fork 415
Validate Tiptap doc JSON before initializing editor #1721
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
Conversation
✅ Deploy Preview for hyprnote ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Warning Rate limit exceeded@yujonglee has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 22 minutes and 7 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughAdds a runtime type-guard for TipTap JSON content and applies it when initializing or setting editor content in desktop note-input components and the core TipTap editor, falling back to an empty TipTap document when validation or parsing fails. Changes
Sequence Diagram(s)sequenceDiagram
participant External as External content source
participant Editor as TipTap Editor
participant Utils as isValidTiptapContent
External->>Editor: provide initialContent (JSON string / object)
Editor->>Utils: parse & validate content
alt valid content
Utils-->>Editor: valid
Editor->>Editor: setContent(validContent)
Editor->>Editor: markNewContent() %% indicated for external-sync path
else invalid or parse error
Utils-->>Editor: invalid
Editor->>Editor: setContent(EMPTY_TIPTAP_DOC)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
apps/desktop/src/components/main/body/sessions/note-input/raw.tsx (1)
8-11: JSON parsing + validation correctly gate editor initialContentImporting
isValidTiptapContentand using it afterJSON.parseso that only doc-shaped values reachsetInitialContent(with all other/failed cases converging toEMPTY_TIPTAP_DOC) is a solid way to avoid invalid editor state from persisted data.If you ever need to debug or migrate bad stored values, consider adding lightweight logging/telemetry in the
!isValidTiptapContent(parsed)branch; otherwise the silent fallback here looks intentional and UX-friendly.Also applies to: 24-40
apps/desktop/src/components/main/body/sessions/note-input/enhanced/editor.tsx (1)
5-6: Consistent validation/fallback pattern for enhanced notesReusing
EMPTY_TIPTAP_DOCandisValidTiptapContenthere gives the enhanced editor the same protection against malformed content as the raw editor, which should prevent the crash scenario while keeping behavior consistent across entry points.If this parse/validate/fallback pattern shows up in more places, you might eventually extract a small helper (e.g.
safeParseTiptapDoc(string)) to keep things DRY. Also,sessionIdis declared in the props type but unused in this component; consider removing it from the type if it’s truly not needed to avoid confusion.Also applies to: 9-12, 17-35
packages/tiptap/src/editor/index.tsx (1)
99-106: Guarding editor content with isValidTiptapContent aligns the core editor with the new safety contractUsing
shared.isValidTiptapContent(initialContent)for the initialcontentoption and before callingmarkNewContent/setContentensures that only doc-shaped values flow into the editor, while everything else falls back to or leaves in-place a safe document. This directly addresses the invalid-content crash without changing the public API.Behavior-wise, when an invalid
initialContentis received after mount, the editor now keeps the existing document rather than explicitly resetting to an empty one; if you’d prefer to always normalize bad inputs toEMPTY_TIPTAP_DOC, you could add an explicitelsebranch that callssetContent(EMPTY_TIPTAP_DOC)there, but the current choice is reasonable and conservative.Also applies to: 126-149
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
apps/desktop/src/components/main/body/sessions/note-input/enhanced/editor.tsx(2 hunks)apps/desktop/src/components/main/body/sessions/note-input/raw.tsx(2 hunks)packages/tiptap/src/editor/index.tsx(2 hunks)packages/tiptap/src/shared/utils.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
apps/desktop/src/components/main/body/sessions/note-input/enhanced/editor.tsx (1)
packages/tiptap/src/shared/utils.ts (2)
isValidTiptapContent(10-17)EMPTY_TIPTAP_DOC(8-8)
apps/desktop/src/components/main/body/sessions/note-input/raw.tsx (1)
packages/tiptap/src/shared/utils.ts (2)
isValidTiptapContent(10-17)EMPTY_TIPTAP_DOC(8-8)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: Redirect rules - hyprnote
- GitHub Check: Header rules - hyprnote
- GitHub Check: Pages changed - hyprnote
- GitHub Check: fmt
🔇 Additional comments (1)
packages/tiptap/src/shared/utils.ts (1)
10-17: isValidTiptapContent implements the intended minimal doc-shape guardThe check cleanly rejects non-objects and malformed values while allowing only
{ type: "doc", content: [...] }-shaped inputs, which is exactly what the callers need before passing data into the editor.
ea7a3d0 to
6f46a83
Compare
Prevent crashes caused by invalid or empty Tiptap JSON when navigating notes by validating parsed content before passing it to the editor. If the parsed JSON isn't a valid Tiptap `doc` with a `content` array, fall back to EMPTY_TIPTAP_DOC. This adds an isValidTiptapDoc helper and uses it in editor and raw input components to avoid RangeError from malformed or empty node content. Validate tiptap content correctly Fix incorrect validation function name and implementation for Tiptap JSON content. - Rename isValidTiptapDoc to isValidTiptapContent where used so components check the correct predicate. - Change editor initialization and content-setting logic to use isValidTiptapContent before using incoming content, falling back to EMPTY_TIPTAP_DOC when invalid. - Simplify the validation implementation to correctly verify that the value is an object with type === "doc" and an array content, preventing empty-string or malformed values from being passed to Tiptap which caused RangeError: Invalid content for node doc. These changes prevent invalid/empty payloads from being treated as valid Tiptap documents and avoid runtime errors in the Editor component.
6f46a83 to
a7a98aa
Compare
Prevent crashes caused by invalid or empty Tiptap JSON when navigating notes by validating parsed content before passing it to the editor. If the parsed JSON isn't a valid Tiptap
docwith acontentarray, fall back to EMPTY_TIPTAP_DOC. This adds an isValidTiptapDoc helper and uses it in editor and raw input components to avoid RangeError from malformed or empty node content.Validate tiptap content correctly
Fix incorrect validation function name and implementation for Tiptap JSON content.
These changes prevent invalid/empty payloads from being treated as valid Tiptap documents and avoid runtime errors in the Editor component.