facebook / lexical

Lexical is an extensible text editor framework that provides excellent reliability, accessibility and performance.
https://lexical.dev
MIT License
17.5k stars 1.45k forks source link

Bug: 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(). #5934

Open muhammadmudasir1 opened 3 weeks ago

muhammadmudasir1 commented 3 weeks ago

i create reactjs app which works fine but after i use react.lazy at multiple location not in editor and create a build it give the 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(). at getActiveEditorState (http://localhost:3000/static/js/bundle.js:755073:13) at $getRoot (http://localhost:3000/static/js/bundle.js:748462:26) at $rootTextContent (http://localhost:3000/static/js/bundle.js:747214:65) at $isRootTextContentEmpty (http://localhost:3000/static/js/bundle.js:747236:14) at $canShowPlaceholder (http://localhost:3000/static/js/bundle.js:747268:8) at http://localhost:3000/static/js/bundle.js:747308:16 at readEditorState (http://localhost:3000/static/js/bundle.js:740294:12) at EditorState.read (http://localhost:3000/static/js/bundle.js:741394:12) at canShowPlaceholderFromCurrentEditorState (http://localhost:3000/static/js/bundle.js:723705:61) at http://localhost:3000/static/js/bundle.js:723709:109

etrepum commented 3 weeks ago

This can happen if you have imported multiple versions of Lexical, unfortunately the callstack isn't enough information to help you with this issue. Can you reproduce this error and post the reproduction to github, stackblitz, or codesandbox so it can be inspected by someone else?

caskEqui commented 2 weeks ago

Ref this, I suddenly started getting this same error on some occassions... It works fine in storybook ( with the same data). But when using in application it gives this error : Uncaught Error: Unable to find an active editor. This method can only be used synchronously during the callback of editor.update(). I´ve made sure that we use only one version of lexical. Any ideas on what to try? How to make sure that editor has value?! Only change we´ve made is converting to Vite. Anything there that should be mentioned to remember?

etrepum commented 2 weeks ago

Make sure you are only using import or only using require. Mixing both could cause problems. Are you using any third party packages that depend on lexical? Can you post a small project that reproduces this error?

Lexical is tested with vite, so as long as there isn't strange configuration that wouldn't cause a problem on its own.