[lexical-list] Bug Fix: Merge nested list into parent <li> during HTML export#8313
Conversation
…L export Nested lists were exported as separate <li> elements, causing incorrect numbering in ordered lists. The wrapper <li> containing only a nested list is now merged into the previous <li> sibling during exportDOM. Closes facebook#7207
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Fails ci-check |
|
CI is green now — fixed the type check issue. |
etrepum
left a comment
There was a problem hiding this comment.
This seems to work in the case where it's nested once but if there are multiple levels of nesting without interleaving content it looks like it's still creating the ul -> li -> ul -> li nesting
| name: 'Empty editor state', | ||
| }, | ||
| { | ||
| // Regression #7207: nested list should be inside parent <li>, not a separate <li> |
There was a problem hiding this comment.
Regression means that the behavior changed in an undesirable way, I don't think it worked like this previously
| // Regression #7207: nested list should be inside parent <li>, not a separate <li> | |
| // #7207: nested list should be inside parent <li>, not a separate <li> |
There was a problem hiding this comment.
Fixed the comment.
| after(containerElement) { | ||
| if (containerElement instanceof HTMLElement) { | ||
| const prevSibling = containerElement.previousElementSibling; | ||
| if (prevSibling) { |
There was a problem hiding this comment.
Might make sense to check the type of this element to make sure it's doing the right thing
There was a problem hiding this comment.
Added instanceof HTMLLIElement on prevSibling so it only merges into an actual list item — let me know if you had a different check in mind.
commit 5d1bc33 Author: Sathvik Veerapaneni <98241593+Sathvik-Chowdary-Veerapaneni@users.noreply.github.com> Date: Thu Apr 23 13:12:21 2026 -0400 [lexical-list] Bug Fix: Merge nested list into parent <li> during HTML export (facebook#8313) Co-authored-by: Bob Ippolito <bob@redivi.com> commit 2c37dc2 Author: Bob Ippolito <bob@redivi.com> Date: Thu Apr 23 07:14:14 2026 -0700 [lexical-clipboard][lexical-rich-text][lexical-plain-text] Bug Fix: Drag-and-drop within the same block (facebook#8373) Co-authored-by: Claude <noreply@anthropic.com> commit ca2aa31 Author: Bob Ippolito <bob@redivi.com> Date: Thu Apr 23 07:12:43 2026 -0700 [lexical][lexical-utils][lexical-list] Bug Fix: Clean up and test $insertNodeToNearestRootAtCaret edge cases (facebook#8384) commit 207648e Author: Bob Ippolito <bob@redivi.com> Date: Thu Apr 23 07:11:52 2026 -0700 [lexical-html][lexical-playground] Feature: Implement a well-defined ordering for DOMRenderExtension overrides and add $decorateDOM (facebook#8368) commit 1ca42f1 Author: Agyei Holy <agyeiholy978@gmail.com> Date: Wed Apr 22 15:39:37 2026 -0500 [lexical][lexical-code-core][lexical-list][lexical-table][lexical-yjs] Refactor: make runtime style updates CSP-safe (facebook#8372) commit ca0ce82 Author: Bob Ippolito <bob@redivi.com> Date: Wed Apr 22 12:57:28 2026 -0700 [lexical-list] Bug Fix: Ensure that ListItemNode always has a ListItem parent (facebook#8382) commit f4c44e1 Author: Sherry <potatowagon@meta.com> Date: Thu Apr 23 00:28:54 2026 +0530 [lexical-markdown] Bug Fix: Code spans take precedence over inline formatting in shortcuts (facebook#8381) commit 4a43cb0 Author: Sergey Gorbachev <grbchv.s@gmail.com> Date: Wed Apr 22 18:31:21 2026 +0300 [lexical-playground] Feature: HTML conversion button (facebook#8379)
commit 5d1bc33 Author: Sathvik Veerapaneni <98241593+Sathvik-Chowdary-Veerapaneni@users.noreply.github.com> Date: Thu Apr 23 13:12:21 2026 -0400 [lexical-list] Bug Fix: Merge nested list into parent <li> during HTML export (facebook#8313) Co-authored-by: Bob Ippolito <bob@redivi.com> commit 2c37dc2 Author: Bob Ippolito <bob@redivi.com> Date: Thu Apr 23 07:14:14 2026 -0700 [lexical-clipboard][lexical-rich-text][lexical-plain-text] Bug Fix: Drag-and-drop within the same block (facebook#8373) Co-authored-by: Claude <noreply@anthropic.com> commit ca2aa31 Author: Bob Ippolito <bob@redivi.com> Date: Thu Apr 23 07:12:43 2026 -0700 [lexical][lexical-utils][lexical-list] Bug Fix: Clean up and test $insertNodeToNearestRootAtCaret edge cases (facebook#8384) commit 207648e Author: Bob Ippolito <bob@redivi.com> Date: Thu Apr 23 07:11:52 2026 -0700 [lexical-html][lexical-playground] Feature: Implement a well-defined ordering for DOMRenderExtension overrides and add $decorateDOM (facebook#8368) commit 1ca42f1 Author: Agyei Holy <agyeiholy978@gmail.com> Date: Wed Apr 22 15:39:37 2026 -0500 [lexical][lexical-code-core][lexical-list][lexical-table][lexical-yjs] Refactor: make runtime style updates CSP-safe (facebook#8372) commit ca0ce82 Author: Bob Ippolito <bob@redivi.com> Date: Wed Apr 22 12:57:28 2026 -0700 [lexical-list] Bug Fix: Ensure that ListItemNode always has a ListItem parent (facebook#8382) commit f4c44e1 Author: Sherry <potatowagon@meta.com> Date: Thu Apr 23 00:28:54 2026 +0530 [lexical-markdown] Bug Fix: Code spans take precedence over inline formatting in shortcuts (facebook#8381) commit 4a43cb0 Author: Sergey Gorbachev <grbchv.s@gmail.com> Date: Wed Apr 22 18:31:21 2026 +0300 [lexical-playground] Feature: HTML conversion button (facebook#8379)
Description
When exporting nested lists with
$generateHtmlFromNodes, the nested<ol>/<ul>was wrapped in a separate<li>element instead of being placed inside the parent<li>. This caused duplicate numbering in ordered lists:In Lexical's model, a nested list is stored as a separate ListItemNode whose only child is a ListNode. During
exportDOM, this wrapper now uses anaftercallback to move the nested list into the previous<li>sibling and remove the empty wrapper.Closes #7207
Closes #2951
Test plan
Before
Nested ordered lists produce duplicate numbering due to an extra
<li>wrapping the nested list.After
Nested lists are correctly placed inside the parent
<li>, producing correct numbering.Added a unit test for nested ordered list HTML export. Updated existing test expectations across 5 files to match the corrected HTML structure.
All existing tests pass (2740 passed, 0 failed).