[editor] Improve EditContext API - #1006
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Keep EditProvider mounted while File, diff, and CodeView surfaces enter and leave edit mode. Each session now receives its own editor from the provider factory without remounting the rendered surface. Expose edit and editOptions across editable React surfaces, route CodeView items through the shared context, and migrate docs apps, examples, generated snapshots, and lifecycle coverage.
An edit-enabled CodeView item could render read-only when no editor factory was available. Assert the factory when a mounted item needs a new editor, without scanning the full item collection. Preserve active sessions when the factory changes and cover vanilla, React, and virtualized paths.
React CodeView callers could pass selection controls through both props and options, but the wrapper silently discarded the option values. Remove the React-managed selection keys from the public options type and cover controlled, uncontrolled, and provider-mounted selection flows.
End an edit session before the next render frame and the queued onAttach callback could run against a cleaned editor, breaking imperative setup such as marker installation. Track pending notifications by attachment generation, cancel them during cleanup, and only deliver once to a live session. Preserve recycle behavior and persisted-state restoration across repeated teardown.
Edit a diff, then switch between unified and split layouts: Reset became disabled even though the edited contents remained. An edit immediately after a reset could also be ignored. Remove the stale debounce window now that onChange is synchronous. Keep layout changes within the current session, while Reset and surface switches still remount from pristine input.
Keep files, diffs, items, and styles stable at module scope while memoizing component options with useMemo. Correct public type imports and make the snippets compile under strict TypeScript settings. Clarify per-surface editor creation and CodeView completion semantics, including the teardown paths that remain silent. Refresh demo comments and callback wiring to match the current edit-session lifecycle.
Cover File and FileDiff session creation, option replacement, cleanup, and instance preservation with the same lifecycle assertions. Keep wrapper coverage focused on edit-option forwarding and verify sibling callbacks stay isolated. Exercise CodeView completion behavior for changed and unchanged sessions across edit-off, collapse, removal, direct cleanup, and React unmount.
Describe the stable onChange callback consistently in both Agent UI starter states. Refresh the generated mock session data so its displayed diff matches the source snapshots.
amadeus
force-pushed
the
amadeus/edit-context-improvement
branch
from
July 20, 2026 18:37
50b0c90 to
988dc77
Compare
necolas
reviewed
Jul 20, 2026
necolas
approved these changes
Jul 20, 2026
amadeus
added a commit
that referenced
this pull request
Jul 21, 2026
* feat(diffs): Create editors per React edit session Keep EditProvider mounted while File, diff, and CodeView surfaces enter and leave edit mode. Each session now receives its own editor from the provider factory without remounting the rendered surface. Expose edit and editOptions across editable React surfaces, route CodeView items through the shared context, and migrate docs apps, examples, generated snapshots, and lifecycle coverage. * fix(diffs): Validate CodeView editor factories on attachment An edit-enabled CodeView item could render read-only when no editor factory was available. Assert the factory when a mounted item needs a new editor, without scanning the full item collection. Preserve active sessions when the factory changes and cover vanilla, React, and virtualized paths. * fix(diffs): Keep React CodeView selection prop-driven React CodeView callers could pass selection controls through both props and options, but the wrapper silently discarded the option values. Remove the React-managed selection keys from the public options type and cover controlled, uncontrolled, and provider-mounted selection flows. * bugfix(UniversalRenderingManager): improve idempotency, add some tests * fix(diffs): Keep deferred onAttach within its edit session End an edit session before the next render frame and the queued onAttach callback could run against a cleaned editor, breaking imperative setup such as marker installation. Track pending notifications by attachment generation, cancel them during cleanup, and only deliver once to a live session. Preserve recycle behavior and persisted-state restoration across repeated teardown. * fix(docs): Preserve Live Editing state across layout changes Edit a diff, then switch between unified and split layouts: Reset became disabled even though the edited contents remained. An edit immediately after a reset could also be ignored. Remove the stale debounce window now that onChange is synchronous. Keep layout changes within the current session, while Reset and surface switches still remount from pristine input. * docs(diffs): Correct React examples and edit guidance Keep files, diffs, items, and styles stable at module scope while memoizing component options with useMemo. Correct public type imports and make the snippets compile under strict TypeScript settings. Clarify per-surface editor creation and CodeView completion semantics, including the teardown paths that remain silent. Refresh demo comments and callback wiring to match the current edit-session lifecycle. * test(diffs): Strengthen React edit lifecycle coverage Cover File and FileDiff session creation, option replacement, cleanup, and instance preservation with the same lifecycle assertions. Keep wrapper coverage focused on edit-option forwarding and verify sibling callbacks stay isolated. Exercise CodeView completion behavior for changed and unchanged sessions across edit-off, collapse, removal, direct cleanup, and React unmount. * docs(diffs): Refresh Agent UI edit callback snapshots Describe the stable onChange callback consistently in both Agent UI starter states. Refresh the generated mock session data so its displayed diff matches the source snapshots. * lmao fixed
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.
Overall this branch converts the 1:1 editor context API into a function factory context to make edit more developer friendly to implement.
TL;DR
So it was kinda buggin me that to use edit in react involved this architecture:
Basically this created a scenario where you had to create an edit context for every File/FileDiff. It also created situations where if you want to toggle edit on or off, and didn't want to pay the cost for an editor instance when it wasn't used, you'd essentially have to remount FileDiff (changing parent/child relationships in react is always an automatic re-mount).
Of course, part of the reason this is necessary is because we don't want to force people to import/use the Editor codebase if they aren't going to use it.
When I worked through adding support for CodeView, I took a slightly different approach -- you create an
editFactoryfunction that then CodeView would automatically use to create Editor instances on demand for items.I feel like this is a much cleaner solution for the React API so I did a bit of an agentic port to rework EditContext to supply a factory function, and utilize that to automatically generate instances on demand.
I also changed the
contentEditableprop toeditwhich feels more on brand for how we are making the feature.So now, when building out a page that uses diffs, that might also selectively edit, you can just do
The Longer Version:
<EditProvider editor={editor}>with<EditProvider createEditor={factory}>, exportCreateEditor,EditProviderProps, anduseCreateEditor, and removeuseEditor.contentEditabletoeditonFile,FileDiff,MultiFileDiff, andPatchDiff, and add per-surfaceeditOptions;UnresolvedFileremains non-editable.CodeVieweditor creation into the nearestEditProvider, add CodeView-leveleditOptions, preserve per-item editors across virtualization, and keep vanillaCodeViewOptions.createEditorunchanged.CodeViewchanges through item-awareonItemEditChangeandonItemEditCompletecallbacks, with completion limited to changed sessions ending through edit-off, collapse, or removal.controlledSelectionandonSelectedLinesChangekeys from React CodeView'soptionsobject; controlled prop-based and uncontrolled selection remain supported.Editor.onAttachcallbacks from outliving their edit sessions, preserve correct delivery across virtualization, and make shared render scheduling idempotent.editand memoizededitOptions, fix Live Editing state across layout changes, and refresh the Agent UI starter/generated artifacts.