Skip to content

[6.x] Refresh CodeMirror instance when switching tabs#14199

Merged
jasonvarga merged 2 commits into6.xfrom
codemirror-visibility-observer
Mar 11, 2026
Merged

[6.x] Refresh CodeMirror instance when switching tabs#14199
jasonvarga merged 2 commits into6.xfrom
codemirror-visibility-observer

Conversation

@duncanmcclean
Copy link
Copy Markdown
Member

This pull request fixes an issue where the Code field doesn't render correctly when placed in a tab other than the main one. The field appears empty when switching to the tab, and focusing into it causes the content to be superimposed on the line numbers.

This was happening because CodeMirror initializes when the component is mounted, but if the element is hidden (in a non-active tab), it can't calculate its dimensions correctly. When the tab becomes visible, CodeMirror doesn't know it needs to recalculate its layout.

This PR fixes it by adding an IntersectionObserver to detect when the editor becomes visible and calling refresh() on the CodeMirror instance to recalculate its dimensions. It also adds proper cleanup of the CodeMirror instance in onBeforeUnmount.

Before

CleanShot.2026-03-10.at.15.26.16.mp4

After

CleanShot.2026-03-10.at.15.26.48.mp4

Fixes #14194

@jasonvarga jasonvarga merged commit ec212fe into 6.x Mar 11, 2026
18 checks passed
@jasonvarga jasonvarga deleted the codemirror-visibility-observer branch March 11, 2026 13:50
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.

Code field instantiation issue when used in other tabs

2 participants