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

Uncaught promise when using useMonaco() #440

Open
willdady opened this issue Jan 4, 2023 · 10 comments
Open

Uncaught promise when using useMonaco() #440

willdady opened this issue Jan 4, 2023 · 10 comments

Comments

@willdady
Copy link

willdady commented Jan 4, 2023

When I add these lines:

  const monaco = useMonaco();
  useEffect(() => {
    if (monaco) {
      console.log('here is the monaco instance:', monaco);
    }
  }, [monaco]);

I get the following error in my browser console:

Uncaught (in promise) {type: 'cancelation', msg: 'operation is manually canceled'}
@suren-atoyan
Copy link
Owner

Do you use React 18 with strict mode?

@willdady
Copy link
Author

willdady commented Jan 5, 2023

Yes, 18.2. It's a Next.js (13.0.7) app. Not sure about strict mode.

@suren-atoyan
Copy link
Owner

could you please check this?

@stefanbugge
Copy link

I get the same error in the console. I am using React 18 in strict mode but not Next.js

@cbn-falias
Copy link

Same error but probably a different case with React 18 and no Next.js.

  • Custom loader based on this
  • React.StrictMode
  • Loading it with React.lazy()

If I don't load it lazy it would work but that's not an option in my project.


Works:

  • CDN + No strict mode
  • Custom loader + Strict mode

Doesn't work:

  • CDN + Strict mode
  • Custom loader + Strict mode + Lazy

@AtharvaUmbarkar
Copy link

I am also getting the same error.
I am using NextJS 13 with the useMonaco() hook, with Strict Mode: On.
Btw, I am already using the "use client" directive on top of the code given below to render the component client side.

image
Here's how I am using it. This usage also gives the "default props on functional components are depreciated" warning

@mathieu-anderson
Copy link

We are encountering this issue as well: Aiven-Open/klaw#1464

I have been able to ascertain that this console.error seems to happen unconditionally when calling useMonaco: in this minimal example, it seems to always be there https://codesandbox.io/s/sleepy-moore-3mct7n?file=/src/App.js:123-132

@mathieu-anderson
Copy link

I also ascertained that the console.error only happens when using StrictMode.

Debbl added a commit to Debbl/code-diff that referenced this issue Sep 3, 2023
@wb-wenbei
Copy link

The same error with React 18 in strict mode, not Next.js

@moiri
Copy link

moiri commented Aug 28, 2024

I get the same error when updating the JSON schema with useEffect().

  • React 18.3.1
  • Strict mode: off
  • @monaco-editor/react: 4.6.0
import React, { useEffect } from 'react';
import Editor, { useMonaco } from '@monaco-editor/react';

interface IConfigEditor {
    value: string;
    path?: string;
    schemaUri?: string;
}

export const ConfigEditor: React.FC<IConfigEditor> = props => {
    const monaco = useMonaco();

    useEffect(() => {
        if (monaco && props.path && props.schemaUri) {
            monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
                validate: true,
                enableSchemaRequest: true,
                schemas: [
                    {
                        uri: props.schemaUri,
                        fileMatch: [props.path],
                    },
                ],
            });
        }
    }, [monaco, props.path, props.schemaUri]);
    return (
        <Editor
            path={props.path}
            language="json"
            value={props.value}
        />
    )
};

Edit:
I solved the problem in non-strict mode by using the beforeMount handler of the Editor component to initialize the schemas and a useEffect() hook to update the schema list. It still fails in strict mode, though.

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

No branches or pull requests

8 participants