Skip to content

[lexical-list] Bug Fix: remove the stale depth theme class when a list changes depth - #9077

Merged
etrepum merged 1 commit into
meta:mainfrom
nithin42:fix-list-depth-theme-class
Aug 20, 2026
Merged

etrepum merged 1 commit into
meta:mainfrom
nithin42:fix-list-depth-theme-class

Conversation

@nithin42

Copy link
Copy Markdown
Contributor

Description

$setListThemeClassNames picks the depth class for a list out of the theme's ulDepth / olDepth array, then tries to strip the depth classes belonging to the other levels:

if (listLevelClassName !== undefined) {
  classesToAdd.push(...normalizeClassNames(listLevelClassName));
  for (let i = 0; i < listLevelsClassNames.length; i++) {
    if (i !== normalizedListDepth) {
      classesToRemove.push(node.__tag + i);
    }
  }
}

The removal list is built from node.__tag + i, i.e. the literal strings "ul0", "ul1", "ol0" and so on. Those are not the theme's class names, they're just the tag with an index glued on, so they are never present on the element and removeClassNamesFromElement does nothing.

That is invisible on a freshly created element, because createDOM starts from a clean class list. It shows up through updateDOM, which reuses the existing element: when a list changes depth the new depth class is added while the old one stays, and the element ends up with two conflicting depth classes. Since these classes exist to set list-style-type per level (see packages/lexical-tailwind/src/index.ts, where ulDepth maps to list-disc / list-[circle] / list-[square]), the list renders with whichever marker wins by CSS order rather than the one for its actual depth.

$setListItemThemeClassNames in LexicalListItemNode.ts does the equivalent removal correctly, pushing the real theme class names, so the two functions currently disagree.

Fix

Push the actual theme class names, matching what the add path directly above already does:

classesToRemove.push(...normalizeClassNames(listLevelsClassNames[i]));

normalizeClassNames is already imported in this file.

Test plan

Added packages/lexical-list/src/__tests__/unit/ListNodeDepthThemeClass.test.ts. It builds a top level list, checks the element has the depth-1 class, then nests it one level deeper so the same element is updated in place, and checks the class list.

npx vitest --project unit --no-watch packages/lexical-list

On main the second assertion fails with:

expected 'my-ul-list-class depth-1 depth-2' to be 'my-ul-list-class depth-2'

With this change it passes, and the whole lexical-list unit suite is green (11 files, 126 tests).

…t changes depth

$setListThemeClassNames built the class names to remove by concatenating the tag with the index (ul0, ul1, ...) instead of reading them out of the theme's ulDepth/olDepth array. Those strings are never on the element, so the removal did nothing and a list whose DOM element is reused across a depth change kept both depth classes.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 19, 2026
@vercel

vercel Bot commented Aug 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview Aug 19, 2026 5:35pm
lexical-playground Ready Ready Preview Aug 19, 2026 5:35pm

Request Review

@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Aug 20, 2026
@etrepum
etrepum added this pull request to the merge queue Aug 20, 2026
Merged via the queue into meta:main with commit d4c8fdb Aug 20, 2026
48 checks passed
@etrepum etrepum mentioned this pull request Aug 31, 2026

This branch was successfully deployed

2 active deployments
Preview – lexical — c647dd59 Deployed Aug 19, 2026 by vercel[bot]
Preview – lexical-playground — c647dd59 Deployed Aug 19, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants