Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ui] Initialize CodeMirror on a div instead of textarea #16878

Merged
merged 1 commit into from
Sep 28, 2023

Conversation

hellendag
Copy link
Member

@hellendag hellendag commented Sep 28, 2023

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.

@hellendag
Copy link
Member Author

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@github-actions
Copy link

Deploy preview for dagit-storybook ready!

✅ Preview
https://dagit-storybook-esnwsiwty-elementl.vercel.app
https://dish-config-page-cm-bug.components-storybook.dagster-docs.io

Built with commit f4c2a66.
This pull request is being automatically deployed with vercel-action

Copy link
Contributor

@salazarm salazarm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@hellendag hellendag merged commit 538df91 into master Sep 28, 2023
@hellendag hellendag deleted the dish/config-page-cm-bug branch September 28, 2023 18:36
yuhan pushed a commit that referenced this pull request Sep 29, 2023
## 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.
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.

2 participants