Skip to content

Conversation

@yujonglee
Copy link
Contributor

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.

@netlify
Copy link

netlify bot commented Nov 18, 2025

Deploy Preview for hyprnote ready!

Name Link
🔨 Latest commit a7a98aa
🔍 Latest deploy log https://app.netlify.com/projects/hyprnote/deploys/691d0b044067530008daa030
😎 Deploy Preview https://deploy-preview-1721--hyprnote.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link

coderabbitai bot commented Nov 18, 2025

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

📥 Commits

Reviewing files that changed from the base of the PR and between 6f46a83 and a7a98aa.

📒 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)
📝 Walkthrough

Walkthrough

Adds 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

Cohort / File(s) Summary
Desktop note-input editors
apps/desktop/src/components/main/body/sessions/note-input/enhanced/editor.tsx, apps/desktop/src/components/main/body/sessions/note-input/raw.tsx
Import and use isValidTiptapContent to validate parsed JSON before applying as initial editor content; preserve existing parse-error fallback to EMPTY_TIPTAP_DOC.
TipTap core editor
packages/tiptap/src/editor/index.tsx
Replace truthiness checks of initialContent with isValidTiptapContent checks for initial/apply-content and external-sync flows; only call markNewContent / set content when validation passes.
Shared validation utilities
packages/tiptap/src/shared/utils.ts
Add exported type-guard isValidTiptapContent(content: unknown): content is JSONContent that asserts a non-null object with type === "doc" and a content array shape.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Files to pay extra attention to:
    • packages/tiptap/src/editor/index.tsx — two conditional branches updated; verify external-sync and focused-editor behavior match intended semantics.
    • packages/tiptap/src/shared/utils.ts — ensure the type-guard covers all valid TipTap JSON variants used across the codebase.
    • apps/desktop/.../enhanced/editor.tsx and raw.tsx — confirm consistent parsing/error paths and that fallback behavior remains correct.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main change: validating Tiptap doc JSON before editor initialization.
Description check ✅ Passed The description clearly explains the problem, solution, and implementation details of adding Tiptap content validation to prevent crashes.

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.

Copy link

@coderabbitai coderabbitai bot left a 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 initialContent

Importing isValidTiptapContent and using it after JSON.parse so that only doc-shaped values reach setInitialContent (with all other/failed cases converging to EMPTY_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 notes

Reusing EMPTY_TIPTAP_DOC and isValidTiptapContent here 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, sessionId is 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 contract

Using shared.isValidTiptapContent(initialContent) for the initial content option and before calling markNewContent / setContent ensures 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 initialContent is 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 to EMPTY_TIPTAP_DOC, you could add an explicit else branch that calls setContent(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

📥 Commits

Reviewing files that changed from the base of the PR and between 8953a96 and ea7a3d0.

📒 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 guard

The 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.

@yujonglee yujonglee force-pushed the validate-tiptap-doc-fallback branch from ea7a3d0 to 6f46a83 Compare November 18, 2025 23:55
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.
@yujonglee yujonglee force-pushed the validate-tiptap-doc-fallback branch from 6f46a83 to a7a98aa Compare November 19, 2025 00:10
@yujonglee yujonglee merged commit be4f038 into main Nov 19, 2025
9 of 10 checks passed
@yujonglee yujonglee deleted the validate-tiptap-doc-fallback branch November 19, 2025 00:11
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.

2 participants