You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: Additional break line when initializing or copy/pasting in the editor with break lines #3677
When I initialize the Lexical editor from an DOM like <p><br></p>, passing through generateNodesFromDOM and inserting the generated nodes to the editor, it imports it with an additional break line like <p><br><br></p>. This makes the editor have more break lines than expected. It is also curious that both count as one character if I delete them and count the characters.
When copying or initializing some text with break lines, it duplicates them, making the text different from the expected one.
The expected behavior
When copying or initializing some text with break lines, the number of break lines is exactly the same as the one inserted in the editor.
Reacted by Filip Juruković, Trung Nguyen, Piotr Chalecki, Brett Schwartz, Ashish Rawat, Sean Schaefer, Oleksandr Danylchenko, clayton, alexz-spotnana, Keith and 5 more
Reacted by Rabi C Shah, ipreacher, Tanay Wagh, alexz-spotnana and Keith
I'm facing the same issue. I've noticed $generateNodesFromDOM is adding an extra <br /> tag for each "empty" paragraph. If you put any character, eg. period or even empty space - the problem does not exist
@almazkaliyev the point is not to remove every <br> from the generated HTML, I want to keep the exact number of break lines from a copy/paste and when initialising the editor with some previous HTML saved from the database.
Reacted by Piotr Chalecki, Almaz Kaliyev, Tanay Wagh, Oleksandr Danylchenko, robFraser1111, Michael Zerihun and Heggria
I've found that a single empty paragraph converted to HTML with $generateHtmlFromNodes will result in <p><br></p>.
However when converting back from HTML to Lexical nodes with $generateNodesFromDOM and then updating the contents of the editor's root node, I end up with the following HTML in the ContentEditable element: <p><br><br></p>.
Reacted by alexz-spotnana, Keith and Raul Silva
Reacted by Oleksandr Danylchenko, Raul Silva and Vincent Rubinetti
@oleksandr-danylchenko and @ferugi - I am experiencing both of your observations reproducibly as well. @thegreatercurve - Let me know if anything we can do to help (ie test cases, repo steps, etc.)
This is my function to initialize the editor state from HTML. Since the lexical's renderer adds additional tags, this function does the opposite – decreases the number of tags by 1 in the parsed DOM and then parses DOM to nodes and inserts them into the editor.
Reacted by Michael Zerihun, Matthew Whiteley, Jay, Philip Fabianek, Anton Savkulych, Joep Verweij, kudafruit, Dhruv Sharma, Faith Morante, Zoltan Felhazi and 3 more
Reacted by Philip Fabianek, Dhruv Sharma, Faith Morante and Jakkapat Paijit
Reacted by Ba-stian, Philip Fabianek, Dhruv Sharma, Jakkapat Paijit and Santhana Krishnan
Activity
chalecki commentedon Jan 16, 2023
I'm facing the same issue. I've noticed
$generateNodesFromDOMis adding an extra<br />tag for each "empty" paragraph. If you put any character, eg. period or even empty space - the problem does not existrabishah commentedon Jan 19, 2023
Facing the same issue, exactly as @chalecki .
willwang888 commentedon Jan 20, 2023
Facing the same issue!
chalecki commentedon Jan 23, 2023
I think it was introduced in #590 in commit f38d4d5 .
Commenting on this line https://github.com/facebook/lexical/blob/main/packages/lexical/src/LexicalReconciler.ts#L324 does the trick I think but I lack knowledge on the overall flow so would be best to hear from @trueadm more on this behavior
almazkaliyev commentedon Jan 23, 2023
maybe this can helps u
mariofpalb commentedon Jan 24, 2023
@almazkaliyev the point is not to remove every
<br>from the generated HTML, I want to keep the exact number of break lines from a copy/paste and when initialising the editor with some previous HTML saved from the database.sagarchoudhary96 commentedon Feb 22, 2023
@thegreatercurve do we have any updates for the fix for this issue ?
obinmatt commentedon Mar 10, 2023
@thegreatercurve any updates? 😄
oleksandr-danylchenko commentedon Mar 15, 2023
Having the same issue. An empty text field has the
<p><br></pby default$generateHtmlFromNodesresultferugi commentedon Apr 12, 2023
I've found that a single empty paragraph converted to HTML with
$generateHtmlFromNodeswill result in<p><br></p>.However when converting back from HTML to Lexical nodes with
$generateNodesFromDOMand then updating the contents of the editor's root node, I end up with the following HTML in the ContentEditable element:<p><br><br></p>.Fixed line breaks showing an empty content in nested editors
Fixed line breaks showing an empty content in nested editors (#603)
keithhackbarth commentedon Apr 25, 2023
@oleksandr-danylchenko and @ferugi - I am experiencing both of your observations reproducibly as well.
@thegreatercurve - Let me know if anything we can do to help (ie test cases, repo steps, etc.)
rjullian commentedon May 9, 2023
I'm facing a similar issue and would really appreciate any updates on the progress made toward resolving it. Thanks.
alexz-spotnana commentedon May 12, 2023
This is my function to initialize the editor state from HTML. Since the lexical's renderer adds additional
tags, this function does the opposite – decreases the number of
tags by 1 in the parsed DOM and then parses DOM to nodes and inserts them into the editor.
Does work for me, but checked on some basic HTML fragments that fit my needs.
gajanan999 commentedon Feb 1, 2024
HI ,
I am facing this issue still in version 0.12.0
kazimirchuk commentedon Feb 15, 2024
Facing the same issue version 0.12.4
rtrevisanlectra commentedon Feb 28, 2024
Hello, same issue in version 0.13.1
mustafamoe commentedon Mar 10, 2024
Same issue in version 0.13.1
dpr10 commentedon Apr 2, 2024
Hello, I'm having the same issue but found a workaround, if you clear the editor before the insertion, the line break is removed.
Michael7141 commentedon Apr 11, 2024
bless your soul;
cuz u set mine on fire
CogitoBurrito commentedon Jun 12, 2024
Listen to this man and if you don't want the focus state after clear, just add
Please fix this!
Pnlvfx commentedon Oct 10, 2024
how is this bug still exist after 2 years?
Dhruv97Sharma commentedon Oct 30, 2024
Because the temporary fix to clear the editor (root) before selection works well, thanks @dpr10