fix(editor): block cross-boundary edits before they reach the server - #676
Open
weprintmoney wants to merge 1 commit into
Open
fix(editor): block cross-boundary edits before they reach the server#676weprintmoney wants to merge 1 commit into
weprintmoney wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What a user experiences today
Open an artifact in the visual editor, select text that crosses a paragraph or
inline-element boundary (a heading into the next paragraph, a word that spans an
<em>chip), and the editor accepts the selection — it even shows "1 unsavedchange." But when you save, the server refuses: "the selection crosses formatting
or element boundaries in the source — edit a smaller run of plain text, or open
the source editor."
For a non-technical reviewer who can't see markup, this message has no actionable
interpretation. And "Edit 1 of 2 failed" leaves it unclear whether the other edit
applied.
Value
language ("that selection crosses an element boundary — try selecting within a
single paragraph"), not after the user has finished composing their change.
it can no longer report ambiguous "Edit N of M failed" mixed outcomes for that
slot.
that stay within a single block continue to work exactly as before.
Technical root cause and fix
The anchor client's
setEditModeentered edit mode on any selection, includingones that span multiple
editContainerForblocks. The server's boundary checkonly fires at save time.
Fix: in
setEditMode'sfromSelectionbranch(
packages/core/src/anchor-client.ts), detect when the selection's start and endnodes belong to different edit containers. When they do:
setEditMode(false)).edit-blockedevent withreason: "cross-boundary".use-inline-edit.tsalready listens foredit-blockedand surfaces a toast fromBLOCKED_COPY. Added a"cross-boundary"entry to that map with a human-readableexplanation, and exported the map so it can be unit-tested.
The anchor client is a compiled bundle;
node scripts/build-anchor-client.mjswasrun after the source change and
node scripts/check-anchor-client.mjsconfirmedthe bundle is in sync.
Test plan
paragraphs → confirm toast fires immediately (no "1 unsaved change" flash).
normally.
pnpm testinapps/web—use-inline-edit.test.tsassertsBLOCKED_COPY["cross-boundary"]is defined and contains "boundary".node scripts/check-anchor-client.mjsexits 0.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.