Fix unacceptable path error on empty paragraph text insertion#157
Conversation
When a block in the Yorkie tree has no inline children (e.g. due to prior edits or concurrent operations), insertText and splitBlock called editByPath with a path referencing a nonexistent inline node, causing "YorkieError: unacceptable path". Handle this edge case by checking for inline children before resolving the block node offset. When no inlines exist, insertText creates a new inline node with the text, and splitBlock restores the empty inline before inserting a new block. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 53 minutes and 22 seconds. ⌛ 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. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe pull request adds defensive guards to Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Verification: verify:selfResult: ✅ PASS in 119.7s
Verification: verify:integrationResult: ✅ PASS |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/frontend/src/app/docs/yorkie-doc-store.ts`:
- Around line 1111-1116: The no-inline fallback is copying targetInline.style
(via const style = targetInline?.style ?? {}) and may carry image metadata into
the typed-text inline; change the code that prepares style before calling
buildInlineNode({ text, style }) to remove any image-specific fields (e.g.,
delete or omit style.image / style.imageUrl) so the fallback inline is created
without image metadata; update the logic around targetInline/style used by
tree.editByPath and buildInlineNode to pass a sanitizedStyle (clone of
targetInline.style with image removed) instead of the raw style.
- Around line 1448-1459: The no-inline split fallback currently builds
afterAttrs with only id, type and serialized style; update it to also preserve
block-level attributes like listKind, listLevel and headingLevel from the
original block when present (i.e., extend afterAttrs to include block.listKind,
block.listLevel, block.headingLevel as appropriate) so that
tree.styleByPath(afterPath, afterAttrs) and the new node created by
buildBlockNode(...) retain those attributes; ensure serializeBlockStyle remains
used for style details and that the values come from the existing block object
(refer to afterAttrs, serializeBlockStyle, buildBlockNode, tree.editByPath,
tree.styleByPath, block, newBlockId, newBlockType).
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0a7a8598-f0d6-4e7e-b385-2c23d970cd7a
📒 Files selected for processing (2)
packages/frontend/src/app/docs/yorkie-doc-store.tspackages/frontend/tests/app/docs/yorkie-doc-store.test.ts
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Strip image metadata from inline style in the insertText fallback to prevent image attributes leaking into typed-text inlines. Preserve listKind, listLevel, and headingLevel in the splitBlock fallback to match the normal split path behavior. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Summary
YorkieError: unacceptable pathwhen inserting text or pressing Enter in an empty paragraph that has no inline children in the Yorkie treeinsertTextandsplitBlockwhere block node has zero inline children by creating inline node before editingRoot Cause
A block in the Yorkie tree can end up with no inline children (exact cause still under investigation — see follow-up below). When
insertTextorsplitBlockis called on such a block,resolveBlockNodeOffsetreturns{inlineIndex: 0, charOffset: 0}andeditByPath([...blockPath, 0, 0])fails because the path doesn't exist.Confirmed in production on
doc-07bdceb6-dd90-4d05-854c-dbb0b4a62f6a(shared linkb08e15ab):Fix
insertText: When block has no inline children, insert a new<inline>node containing the text instead of editing at a nonexistent pathsplitBlock: When block has no inline children, restore an empty inline and insert a new block instead of using CRDT split (which requires an inline path)Follow-up
doc-07bdceb6-dd90-4d05-854c-dbb0b4a62f6a, MongoDB doc_id:69e9ecaa6aeafa99f1b3748fTest plan
pnpm verify:fastpassesshould insertText into a block with no inline children in Yorkie tree— reproduces the exactYorkieError: unacceptable pathshould splitBlock on a block with no inline children in Yorkie treeshould allow insertText into the empty block created by split-at-endshould allow insertText after splitting an empty block (double Enter)🤖 Generated with Claude Code
Summary by CodeRabbit