mdx-editor / editor

A rich text editor React component for markdown
https://mdxeditor.dev
MIT License
1.91k stars 145 forks source link

[BUG] Unable to find an active editor state. #400

Closed zasuh closed 6 months ago

zasuh commented 6 months ago

Describe the bug I'm using MDX Editor with Next.js (Pages router) and get the following error in my browser when simply trying to render the editor. Not using any styling or anything else, just trying to render the editor in a component. I've added the necessary code into next config, but it didn't resolve the issue.

Error: Unable to find an active editor state. State helpers or node methods can only be used synchronously during the callback of editor.update() or editorState.read().

Reproduction

To Reproduce

Expected behavior I expect the editor to work as it did before and not crash the page when clicking inside the input.

Screenshots

Desktop (please complete the following information):

Additional context

zasuh commented 6 months ago

Even tried using the example code from the docs and still having this issue

const innerRef = useRef<MDXEditorMethods>(null);

<MDXEditor
          ref={innerRef}
          markdown="hello world"
          onChange={console.log} />
zasuh commented 6 months ago

Also tried using dynamic imports, same issue

const MDXEditor = dynamic(() => import('@mdxeditor/editor').then((mod) => mod.MDXEditor), {
  ssr: false,
});
petyosi commented 6 months ago

Not sure I follow what you describe. Is this some sort of a regression? Did the error appear after an upgrade? What's different than https://github.com/mdx-editor/mdx-editor-in-next-pages?

zasuh commented 6 months ago

The error appeared after upgrading to v2. The only difference between your example and mine is that you are using server components and I'm not, also I'm on pages router.

petyosi commented 6 months ago

I have created two sample repos, one with app router and one with pages router. The one I linked specifically is using the pages router. Can you fork it and reproduce the problem there? I'm not going to be able to help you otherwise.

Debnathweb commented 6 months ago

Same problem when i am running https://github.com/mdx-editor/mdx-editor-in-cra this example on @nx/react app, client side using "@mdxeditor/editor": "2.18.0" version and same example working with this version on cra app

petyosi commented 6 months ago

@Debnathweb I'm afraid that I don't understand what you mean, nor I can help without being able to reproduce the problem on my side. Since I have not heard back from @zasuh I'm closing this.

Debnathweb commented 6 months ago

i will create a reproduction today

Debnathweb commented 6 months ago

this error solved for me, I think this was happening because lexical was in the dependencies on my nx repo, tried other things, but after removing all lexical packages its solved.