Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ui] Initialize CodeMirror on a div instead of textarea (#16878)
## Summary & Motivation Handling a bug reported by a user: https://dagster.slack.com/archives/C01U954MEER/p1695890039223599. When viewing the "Configuration" page under "Deployment", the read-only CodeMirror renders correctly. If you navigate away, however, the CodeMirror remains rendered in the DOM, though unstyled and jammed into the top of the page. This is because we're using `CodeMirror.fromTextArea`, which creates a target div for the CodeMirror instance independent of the `textarea` we render for the component. This div is uncontrolled by React, so when we navigate away, the React-controlled textarea is unmounted, but the CodeMirror target div remains in the DOM. To resolve this, use the CodeMirror constructor API instead. In this way, we can pass a div to serve as the CM target, which will be unmounted correctly when navigating away. Also switch to using a `useRef` instead of the ref function, which is currently being executed every time any of the prop values changes -- which is a lot. The ref function re-execution leads to mounting/unmounting the rendered node, which isn't useful to us and could be problematic. The CodeMirror instantiation now takes place within in an effect instead. ## How I Tested These Changes View Configuration page, then navigate to Daemons. Verify that the CodeMirror doesn't linger in the DOM. View Launchpad, verify that editable CodeMirrors continue to behave correctly.
- Loading branch information
538df91
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deploy preview for dagit-storybook ready!
✅ Preview
https://dagit-storybook-oh3ou6ohe-elementl.vercel.app
Built with commit 538df91.
This pull request is being automatically deployed with vercel-action