Decouple edit-session UI close from the data-commit/cleanup phase#328
Closed
Copilot wants to merge 2 commits into
Closed
Decouple edit-session UI close from the data-commit/cleanup phase#328Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
Copilot
AI
changed the title
[WIP] Decouple edit-session UI close from data commit and cleanup
Decouple edit-session UI close from the data-commit/cleanup phase
Jun 5, 2026
Bundle size impact
|
| Format | Base raw | PR raw | Δ raw | Base gzip | PR gzip | Δ gzip |
|---|---|---|---|---|---|---|
| esm | 54.18 KB | 54.50 KB | 🔺 +330 B (+0.59%) | 18.94 KB | 19.03 KB | 🔺 +95 B (+0.49%) |
| cjs | 55.66 KB | 55.99 KB | 🔺 +335 B (+0.59%) | 19.01 KB | 19.11 KB | 🔺 +104 B (+0.53%) |
Measured from build/index.{cjs,esm}.js. Gzip at level 9.
Owner
|
Replaced by #330 |
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.
JsonEditorawaitsonUpdatebefore committing, but closes the editor synchronously before the await — so during a deferred commit (confirm-modal hook, slow remote round-trip) value nodes flash the new typed value as if applied, and collection nodes re-derive children from the olddata. The naive fix (movecloseEditinto.then) breaks Tab-commit by running a stalecancelOpagainst the just-committed value, double-fires terminal events, and closes the wrong session.Two-phase commit in the editing store
src/contexts/EditingProvider.tsx— splitscloseEdit's coupled responsibilities:beginCommit()— clearscancelOpsynchronously (keeps Tab-commit safe) and registers the active path in acommittingPathsset. LeavescurrentlyEditingElementin place, soisEditingstays true and the editor stays visible.endCommit(path)— deregisters and clearscurrentlyEditingElementonly if it still points atpath. A Tab-drivenstartEdit(next)during the pending window leaves the new session untouched.startEdit's displacement logic skips itscancelEdit/cancelRenameemit for any session incommittingPaths— the node owns the terminal event from its own commit outcome, no double-fire.Node commit handlers
src/ValueNodeWrapper.tsx—handleEditusesbeginCommit()synchronously andendCommit(path)in the resolve callback. The localvaluebuffer naturally retains the user's typed value through the pending window.src/CollectionNode.tsx— same shape, plus the JSON buffer (stringifiedValue) is now cleared in the resolve callback rather than synchronously, so the open textarea keeps showing the typed JSON instead of re-deriving from olddata.Secondary edit paths (type-change, rename, add) keep the existing synchronous
closeEdit()— they don't surface the optimistic-display window in practice and the buffer mechanics differ. Worth a follow-up if uniformity becomes desirable.Tests
test/JsonEditor.test.tsxadds three regressions against aPromiseresolved on demand:confirmEditand closes.Existing Tab-commit / displaced-session /
editorRef.cancelguards still pass — the three documented failure modes (Tab-commit revert, double terminal events, wrong-session close) are covered.