[lexical] Chore: make unable to find active editor state error more descriptive about potential dependency issue#5996
[lexical] Chore: make unable to find active editor state error more descriptive about potential dependency issue#5996AlessioGr wants to merge 7 commits intofacebook:mainfrom
Conversation
… about potential dependency issue
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
scripts/error-codes/codes.json
Outdated
| "13": "Cannot use method in read-only mode.", | ||
| "14": "One or more transforms are endlessly triggering additional transforms. May have encountered infinite recursion caused by transforms that have their preconditions too lose and/or conflict with each other.", | ||
| "15": "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().", | ||
| "15": "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(). This issue can also occur if you have a mismatching or more than one copy of lexical in the same app.", |
There was a problem hiding this comment.
If I'm not mistaken, this file is actually generated and you have to change this at the invariant callsite, then run npm run extract-codes
There was a problem hiding this comment.
that is correct, this is a generated file
There was a problem hiding this comment.
@etrepum @acywatson check it out again! Had to fix the extract-codes script first, as it was sending files like package.json to babel through the ast parser which then threw an error. Now it only handles ts/js files.
codes.json got a lot smaller now, strings like "getLatest() on clone node" are not present anymore. But I also cannot find them anywhere else in the codebase, so that's probably expected
| 'synchronously during the callback of ' + | ||
| 'editor.update() or editorState.read().', | ||
| 'editor.update() or editorState.read(). ' + | ||
| 'This issue can also occur if you have a mismatching ' + |
There was a problem hiding this comment.
IMO, this is more technically correct:
| 'This issue can also occur if you have a mismatching ' + | |
| 'This issue can also occur if you have more than one copy of lexical in the same JS bundle ' + | |
| 'or you're trying to update/read state of lexical that belongs to another JS bundle.' |
|
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 |
etrepum
left a comment
There was a problem hiding this comment.
Based on the output of codes.json I don't think this script is working correctly (probably not your fault). I would expect only new codes to be added to the map, and old codes should have the same index.
The reason for this is that the website's lookup tool should work with any prod version of lexical. In order for that to be the case, the ids for any given error message must be stable, and old entries should persist even if they are no longer present in the source code.
I think in this case the best approach for a PR would be to only change the error messages in the source code, and leave the matter of updating the error-codes script (and the json file) to work correctly can be handled separately.
This error message can be kinda similar to the React hooks error message:
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