Handling unknown / unregistered node types
- Dominant language
- TypeScript
- Stars
- 23.9k
- Forks
- 2.2k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 55
Description
I searched in Google and in Issues but did not find unfortunately any discussion on this.
A usecase:
- import in a Lexical-based editor some markdown or serialized editor-state in JSON
- not all node types used are actually registered in the editor, so an error is thrown
Is there a way to configure Lexical to handle gracefully unknown node types?
I could imagine several meaningful strategies for different usecases:
1. ignore/skip nodes with unknown node types
2. render unknown node types as some opaque thing and preserve the original content in subsequent serializations (so that the unknown node can survive deserialization/serialization)
3. import as a node of another type, e.g. import code node as paragraph node
The strategies (1) and (2) can be used in a quite generic way and not require much of additional configuration.
---
Some of my actual use cases:
- E.g. in https://github.com/facebook/lexical/discussions/7177, I made a CLI tool to render some node types from a deserialized JSON, and it would be practical to be able to ignore/skip the unknown nodes (e.g. EmojiNode from the default document exported from Playground) or replace them with some special values like ``.
- For markdown specifically, I added markdown import in https://github.com/facebook/lexical/tree/main/examples/react-rich and trying to import some markdown using triple-backticks. But it throws because I have not registered yet the CodeNode from `lexical/code`. But it could also be reasonable to import it as bare text/paragraph to display something reasonable and at least show the rest of the document
Thank you!
Contributor guide
Assessment
This issue has not been assessed yet.