fix(undo): keep undo history when toggling markdown write/preview and request-script tabs - #10351
Open
jackkav wants to merge 1 commit into
Open
fix(undo): keep undo history when toggling markdown write/preview and request-script tabs#10351jackkav wants to merge 1 commit into
jackkav wants to merge 1 commit into
Conversation
…preview and request-script tabs Toggling markdown write<->preview or the pre/after-response script tabs unmounts and remounts a CodeEditor while it is hidden. Undo (and, for markdown, the content) was clobbered: - persistState bailed out early when the hidden editor reported a zero-size viewport, so it never saved the undo history. Now it always persists history (and cursor/selections/marks); only the layout-dependent scroll position is skipped when invalid. - The editor-state cache now also persists/restores the editor VALUE, so content stays consistent with the restored undo stack even when defaultValue lags (the markdown editor feeds CodeEditor a debounced-onChange-backed internal value). - The request-pane description and pre/after-response script editors used a volatile React key that remounted them on every revalidation, resetting state and clobbering undo. They now use stable per-request keys (their content does not depend on env/response). Also corrects the markdown editor's TabList aria-label (was 'Request scripts tabs'). Covered by an e2e smoke test: both markdown write/preview and pre/after-response script toggles keep undo working after switching back.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes CodeMirror undo/content state being lost when toggling UI tabs that hide/unmount editors (Markdown Write↔Preview and Pre-request↔After-response scripts) by making the editor-state cache resilient to hidden editors and by eliminating volatile React keys that caused unnecessary remounts.
Changes:
- Persist editor history/cursor/selection/marks even when the editor is hidden (only skip invalid scroll state), and persist/restore the editor value to keep it consistent with the restored undo stack.
- Replace volatile
uniqueKey-based keys with stable per-request/per-script keys for request description and request scripts editors to prevent state clobbering on revalidation. - Add a Playwright smoke test to verify value + undo history survive these toggles; also correct the Markdown editor TabList aria-label.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/insomnia/src/ui/components/panes/request-pane.tsx | Uses stable per-request/per-script keys to avoid remounts that reset editor state. |
| packages/insomnia/src/ui/components/markdown-editor.tsx | Fixes TabList aria-label for correct accessibility naming and test targeting. |
| packages/insomnia/src/ui/components/.client/codemirror/editor-state-cache.ts | Extends cached editor state to include persisted editor value. |
| packages/insomnia/src/ui/components/.client/codemirror/code-editor.tsx | Persists state on hidden/unmounting editors and restores cached value before history. |
| packages/insomnia-smoke-test/tests/smoke/editor-toggle-undo.test.ts | Adds E2E coverage ensuring toggling editors preserves value and undo stack. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
✅ Circular References ReportGenerated at: 2026-08-07T16:00:39.783Z Summary
Click to view all circular references in PR (9)Click to view all circular references in base branch (9)Analysis✅ No Change: This PR does not introduce or remove any circular references. This report was generated automatically by comparing against the |
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
Undo history (and, for the markdown editor, the content) was clobbered when you toggle markdown Write↔Preview or the Pre-request↔After-response script tabs. This fixes both.
Why
Each of those toggles unmounts and remounts a
CodeEditorwhile it's hidden. The editor-state cache (historyKey) is supposed to carry undo across that remount, but three things broke it:persistStatebailed out on hidden editors. It early-returned when the editor reported a zero-size viewport (a hidden/unmounting editor always does), so it never saved the undo history. The URL bar (OneLineEditor) has no such guard, which is why it survived and these didn't.CodeEditoran internaldefaultValuethat lags behind (it's updated via a debouncedonChange), so on remount the editor re-seeded from stale/empty content and the restored history no longer matched.uniqueKey, so any revalidation remounted them and reset their state.How
persistState(code-editor.tsx) now always persists history/cursor/selections/marks; only the layout-dependent scroll position is skipped when invalid.defaultValuelag. Restored beforesetHistory, whose replacement discards the throwaway history the re-seed creates.TabListaria-label (was a copy-pastedRequest scripts tabs).Test
New e2e smoke test editor-toggle-undo.test.ts: editing then toggling write↔preview (markdown) and pre↔after-response (scripts) keeps the value + undo stack, and Cmd/Ctrl+Z still undoes after switching back. Both pass locally;
tsc+ ESLint clean.