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

[lexical] Chore: make unable to find active editor state error more descriptive about potential dependency issue #5996

Open AlessioGr opened 2 weeks ago

AlessioGr commented 2 weeks ago

This error message can be kinda similar to the React hooks error message:

Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:

  1. You might have mismatching versions of React and the renderer (such as React DOM)
  2. You might be breaking the Rules of Hooks
  3. You might have more than one copy of React in the same app See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.

E.g. If people have multiple versions of lexical installed, where the lexical editor is initialized by one version of lexical, but their own custom nodes are initialized by a different version, this error message will occur.

This happens to SO many people after they upgrade my package and forget to make sure their lexical version matches the one which my package is using.

Adding this hint to the error message will give them a chance to figure out why this might be happening

vercel[bot] commented 2 weeks ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 1, 2024 4:33pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 1, 2024 4:33pm
StyleT commented 2 weeks ago

If it happens often to the users of your library - may I ask if you place Lexical as dependency or peerDependency in package.json? It shall be the latter with range of versions supported