Skip to content

Fix unacceptable path error on empty paragraph text insertion#157

Merged
hackerwins merged 2 commits into
mainfrom
fix/empty-block-unacceptable-path
Apr 23, 2026
Merged

Fix unacceptable path error on empty paragraph text insertion#157
hackerwins merged 2 commits into
mainfrom
fix/empty-block-unacceptable-path

Conversation

@hackerwins

@hackerwins hackerwins commented Apr 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Fix YorkieError: unacceptable path when inserting text or pressing Enter in an empty paragraph that has no inline children in the Yorkie tree
  • Handle edge case in insertText and splitBlock where block node has zero inline children by creating inline node before editing

Root Cause

A block in the Yorkie tree can end up with no inline children (exact cause still under investigation — see follow-up below). When insertText or splitBlock is called on such a block, resolveBlockNodeOffset returns {inlineIndex: 0, charOffset: 0} and editByPath([...blockPath, 0, 0]) fails because the path doesn't exist.

Confirmed in production on doc-07bdceb6-dd90-4d05-854c-dbb0b4a62f6a (shared link b08e15ab):

Block[0]: <block><inline>안녕하세요.</inline></block>   ← OK
Block[1]: <block></block>                              ← NO INLINE CHILDREN
Block[2]: <block><inline>반갑습니다.</inline></block>   ← OK

Fix

  • insertText: When block has no inline children, insert a new <inline> node containing the text instead of editing at a nonexistent path
  • splitBlock: 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

  • Investigate how a block ends up with no inline children in the Yorkie tree (concurrent edits? GC? prior code version?)
  • Document key: doc-07bdceb6-dd90-4d05-854c-dbb0b4a62f6a, MongoDB doc_id: 69e9ecaa6aeafa99f1b3748f

Test plan

  • pnpm verify:fast passes
  • New test: should insertText into a block with no inline children in Yorkie tree — reproduces the exact YorkieError: unacceptable path
  • New test: should splitBlock on a block with no inline children in Yorkie tree
  • New test: should allow insertText into the empty block created by split-at-end
  • New test: should allow insertText after splitting an empty block (double Enter)
  • All existing YorkieDocStore tests pass

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed text insertion errors occurring in certain document structures.
    • Resolved block splitting (Enter key) failures in edge case scenarios.
    • Improved overall editor stability and resilience during complex document operations.

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]>
@coderabbitai

coderabbitai Bot commented Apr 23, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@hackerwins has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 53 minutes and 22 seconds before requesting another review.

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

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1362b816-5c0a-4833-bcf8-b999b5b7fc88

📥 Commits

Reviewing files that changed from the base of the PR and between ac95a33 and cbd314d.

📒 Files selected for processing (1)
  • packages/frontend/src/app/docs/yorkie-doc-store.ts
📝 Walkthrough

Walkthrough

The pull request adds defensive guards to insertText and splitBlock methods in YorkieDocStore to handle blocks with missing or zero inline children. When inline children are absent, these methods now create new inline nodes and apply appropriate styling rather than attempting native CRDT operations, preventing unacceptable path errors.

Changes

Cohort / File(s) Summary
Implementation Changes
packages/frontend/src/app/docs/yorkie-doc-store.ts
Enhanced insertText with guard logic to insert new inline nodes for blocks lacking inline children; modified splitBlock to create missing inline nodes and apply block attributes (headingLevel, list fields) in fallback scenarios while preserving original CRDT split logic when inlines are present.
Test Coverage
packages/frontend/tests/app/docs/yorkie-doc-store.test.ts
Added four new test cases covering edge scenarios: text insertion after block splits, double-enter flows on empty blocks, splitting blocks with manually removed inlines, and inserting text into blocks with missing inline children, verifying no errors occur and documents reflect changes correctly.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Poem

🐰 A bunny's delight when blocks lose their way,
With inlines gone missing, we craft them new today!
No more "unacceptable" paths to despair,
Just fallback creation, with styled flair! 🎨✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: preventing an 'unacceptable path error' that occurs when inserting text into empty blocks by adding guards that create missing inline nodes.
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.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/empty-block-unacceptable-path

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.

@github-actions

github-actions Bot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Verification: verify:self

Result: ✅ PASS in 119.7s

Lane Status Duration
sheets:build ✅ pass 13.0s
docs:build ✅ pass 8.0s
verify:fast ✅ pass 60.3s
frontend:build ✅ pass 15.4s
verify:frontend:chunks ✅ pass 0.3s
backend:build ✅ pass 4.8s
cli:build ✅ pass 1.8s
verify:entropy ✅ pass 16.1s

Verification: verify:integration

Result: ✅ PASS

@coderabbitai coderabbitai 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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between d3486fc and ac95a33.

📒 Files selected for processing (2)
  • packages/frontend/src/app/docs/yorkie-doc-store.ts
  • packages/frontend/tests/app/docs/yorkie-doc-store.test.ts

Comment thread packages/frontend/src/app/docs/yorkie-doc-store.ts Outdated
Comment thread packages/frontend/src/app/docs/yorkie-doc-store.ts
@codecov

codecov Bot commented Apr 23, 2026

Copy link
Copy Markdown

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]>
@hackerwins
hackerwins merged commit 6192257 into main Apr 23, 2026
1 check passed
@hackerwins
hackerwins deleted the fix/empty-block-unacceptable-path branch April 23, 2026 10:57
@hackerwins hackerwins mentioned this pull request May 1, 2026
3 tasks
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