microsoft / microsoft/monaco-editor

[Bug] Unmounting component in react throws error

Open
#4,779 5 comments 8 reactions 1 assignee View on GitHub

@hediet is already working on this.

Since Dec 16, 2024.

bug diff-editor
Dominant language
JavaScript
Stars
46.8k
Forks
4.1k
Avg merge
17h 58m
Merged PRs (30d)
1

Description

Reproducible in vscode.dev or in VS Code Desktop?
  • Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
Monaco Editor Playground Link

No response

Monaco Editor Playground Code

Reproduction Steps

Using React; mounting the editor component then removing the component from the react DOM throws an error. This did not occur in version 0.50.0 but has started in 0.52.2
Our rendering code looks like:

import type { EditorProps } from "@monaco-editor/react";
import type { FunctionComponent } from "react";
import Editor from "@monaco-editor/react";
import { useUserSettings } from "../hooks/settings/useUserSettings";

const ResizableEditor: FunctionComponent<
  EditorProps & {
    height: string | number;
    border?: string | number;
  }
> = (props) => {
  const { userSettingsState } = useUserSettings();

  return (
    <div style={{ height: props.height, position: "relative", paddingLeft: props.width }}>
        <Editor
          {...props}
          theme={userSettingsState.theme === "dark" ? "vs-dark" : "light"}
          options={{
            ...props.options,
            automaticLayout: true,
          }}
        />
    </div>
  );
};

export { ResizableEditor };
Actual (Problematic) Behavior
Uncaught Error: TextModel got disposed before DiffEditorWidget model got reset Error: TextModel got disposed before DiffEditorWidget model got reset at UniqueContainer.value (http://localhost:3000/@fs/Users/buster.major/Projects/FlywayDesktop/app/node_modules/.vite/deps/chunk-BDJUYZEV.js?v=bde8a730:118452:29) at Emitter._deliver (http://localhost:3000/@fs/Users/buster.major/Projects/FlywayDesktop/app/node_modules/.vite/deps/chunk-BDJUYZEV.js?v=bde8a730:2465:20) at Emitter._deliverQueue (http://localhost:3000/@fs/Users/buster.major/Projects/FlywayDesktop/app/node_modules/.vite/deps/chunk-BDJUYZEV.js?v=bde8a730:2474:16) at Emitter.fire (http://localhost:3000/@fs/Users/buster.major/Projects/FlywayDesktop/app/node_modules/.vite/deps/chunk-BDJUYZEV.js?v=bde8a730:2495:16) at _a7.dispose (http://localhost:3000/@fs/Users/buster.major/Projects/FlywayDesktop/app/node_modules/.vite/deps/chunk-BDJUYZEV.js?v=bde8a730:33272:29) at I (http://localhost:3000/@fs/Users/buster.major/Projects/FlywayDesktop/app/node_modules/.vite/deps/@monaco-editor_react.js?v=bde8a730:605:72) at http://localhost:3000/@fs/Users/buster.major/Projects/FlywayDesktop/app/node_modules/.vite/deps/@monaco-editor_react.js?v=bde8a730:560:189 at safelyCallDestroy (http://localhost:3000/@fs/Users/buster.major/Projects/FlywayDesktop/app/node_modules/.vite/deps/chunk-GSKIDCVT.js?v=bde8a730:16796:13) at commitHookEffectListUnmount (http://localhost:3000/@fs/Users/buster.major/Projects/FlywayDesktop/app/node_modules/.vite/deps/chunk-GSKIDCVT.js?v=bde8a730:16923:19) at commitPassiveUnmountInsideDeletedTreeOnFiber (http://localhost:3000/@fs/Users/buster.major/Projects/FlywayDesktop/app/node_modules/.vite/deps/chunk-GSKIDCVT.js?v=bde8a730:18333:17)
Expected Behavior

Should not error

Additional Context

This did not occur in version 0.50.0 but has started in 0.52.2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.