Bug: Lexical nodes not persisting styles present in original HTML
See original GitHub issueLexical version: 0.4.1
Steps To Reproduce
- Generate HTML using Lexical APIs
- Use generated HTML from step 1 and provide to Lexical editor. use generateNode API provided by Lexical.
- Resulting content in editor will not have style which it supposed to have
Following HTML was generated by Lexical and saved in DB. We provide it as is to Lexical and generate nodes (https://lexical.dev/docs/concepts/serialization) from it
<p class="RMXContentTheme__paragraph"
data-lexical-node-type="paragraph"
data-lexical-node-json='{"children":[],"direction":"ltr","format":"","indent":0,"type":"paragraph","version":1}'
data-lexical-editor-key="rpoel">
<span
data-lexical-node-type="text"
data-lexical-node-json='{"detail":0,"format":0,"mode":"normal","style":"color: #e00000;background-color: #f8e71c;","text":"manish","type":"text","version":1}'
data-lexical-editor-key="rpoel"
style="color: rgb(224, 0, 0); background-color: rgb(248, 231, 28)">
Hello World
</span>
</p>
The current behavior
After deserializing HTML content its NOT PERSISTING style properties which were present in HTML
<p
class="RMXContentTheme__paragraph"
data-lexical-node-type="paragraph"
data-lexical-node-json='{"children":[],"direction":"ltr","format":"","indent":0,"type":"paragraph","version":1}'
data-lexical-editor-key="qktmf">
<span
data-lexical-node-type="text"
data-lexical-node-json='{"detail":0,"format":0,"mode":"normal","style":"","text":"manish","type":"text","version":1}'
data-lexical-editor-key="qktmf">
Hello World
</span>
</p>
The expected behavior
After deserializing HTML content it SHOULD PERSIST style properties which were present in HTML
<p class="RMXContentTheme__paragraph"
data-lexical-node-type="paragraph"
data-lexical-node-json='{"children":[],"direction":"ltr","format":"","indent":0,"type":"paragraph","version":1}'
data-lexical-editor-key="rpoel">
<span
data-lexical-node-type="text"
data-lexical-node-json='{"detail":0,"format":0,"mode":"normal","style":"color: #e00000;background-color: #f8e71c;","text":"manish","type":"text","version":1}'
data-lexical-editor-key="rpoel"
style="color: rgb(224, 0, 0); background-color: rgb(248, 231, 28)">
Hello World
</span>
</p>
Issue Analytics
- State:
- Created a year ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
React Lexical nodes not persisting styles present in original ...
I am using Lexical APIs for serialisation and deserialisation to generate following HTML from editor. <p class="RMXContentTheme__paragraph" data ...
Read more >Bug: $generateNodesFromDOM does not apply styles ...
When using $generateNodesFromDOM to convert HTML to Lexical, styles such as underline or align are not being applied.
Read more >3.2.5 Content models — HTML5 - W3C
Inter-element whitespace, comment nodes, and processing instruction nodes must be ignored when establishing whether an element's contents match the element's ...
Read more >ReferenceError: can't access lexical declaration 'X' before ...
The JavaScript exception "can't access lexical declaration `variable' before initialization" occurs when a lexical variable was accessed ...
Read more >Troubleshooting Geo - GitLab Docs
If the user interface is not working, or you are unable to sign in, ... found a secondary node named "Shanghai" GitLab Geo...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@zurfyx Thanks for prompt response and fix! It will be great if you can let us know way to persist text-alignment?
It’s already being stored in parent by lexical itself. When we use generated HTML as initial state, aligned text is not rendered by editor even if
data-lexical-json
attributes is present on parent tag.let me know your thoughts on this.