Repository navigation
[lexical-playground] Bug Fix: a closed collapsible container no longer exports as open - #8994
Merged
Merged
Conversation
…r exports as open
## Description
`CollapsibleContainerNode.exportDOM` stringifies the open flag into the
attribute value:
```ts
element.setAttribute('open', this.__open.toString());
```
`open` is an HTML **boolean** attribute: the element is open because the
attribute is *present*, whatever its value. `open="false"` is therefore open —
in every browser, in jsdom, and in `HTMLDetailsElement.open`. A collapsed
container exported to HTML came back expanded, and rendered expanded anywhere
the exported markup was viewed.
The import rule reads the property, so it sees exactly that:
```ts
return [$createCollapsibleContainerNode(el.open).append(titleNode, contentNode)];
```
`createDOM` and `updateDOM` in the same class already get this right —
`setAttribute('open', '')` when opening and `removeAttribute('open')` when
closing. Only `exportDOM` stringified. Emit the attribute only when the
container is open, matching them.
`exportJSON` is unaffected (it serializes a real boolean), so this is purely
the HTML path — copy/paste of a collapsed container between editors, and any
`$generateHtmlFromNodes` output.
## Test plan
Three new cases in
`packages/lexical-playground/__tests__/unit/CollapsibleContainerNode.test.ts`:
an `open=true` / `open=false` round trip (the `true` case passes before and
after — it is the control the `false` case is held to), plus a direct
assertion on the exported markup.
The existing import tests feed hand-written HTML (`<details open>`,
`open="true"`, or the attribute absent), so none of them ever exercised the
`open="false"` string this code produced.
### Before
```
$ npx vitest run packages/lexical-playground/__tests__/unit/CollapsibleContainerNode.test.ts
✓ round-trips open=true through HTML 9ms
× round-trips open=false through HTML 6ms
× does not write a value for the boolean open attribute 3ms
⎯⎯⎯⎯⎯⎯⎯ Failed Tests 2 ⎯⎯⎯⎯⎯⎯⎯
AssertionError: expected true to be false // Object.is equality
AssertionError: expected '<details class="Collapsible__containe…' not to contain 'open='
Expected: "open="
```
### After
```
$ npx vitest run packages/lexical-playground
Test Files 17 passed (17)
Tests 274 passed (274)
```
LeSingh1
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 9, 2026 01:48
|
@LeSingh1 is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
etrepum
approved these changes
Aug 9, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
CollapsibleContainerNode.exportDOMstringifies the open flag into theattribute value:
openis an HTML boolean attribute: the element is open because theattribute is present, whatever its value.
open="false"is therefore open —in every browser, in jsdom, and in
HTMLDetailsElement.open. A collapsedcontainer exported to HTML came back expanded, and rendered expanded anywhere
the exported markup was viewed.
The import rule reads the property, so it sees exactly that:
createDOMandupdateDOMin the same class already get this right —setAttribute('open', '')when opening andremoveAttribute('open')whenclosing. Only
exportDOMstringified. Emit the attribute only when thecontainer is open, matching them.
exportJSONis unaffected (it serializes a real boolean), so this is purelythe HTML path — copy/paste of a collapsed container between editors, and any
$generateHtmlFromNodesoutput.Test plan
Three new cases in
packages/lexical-playground/__tests__/unit/CollapsibleContainerNode.test.ts:an
open=true/open=falseround trip (thetruecase passes before andafter — it is the control the
falsecase is held to), plus a directassertion on the exported markup.
The existing import tests feed hand-written HTML (
<details open>,open="true", or the attribute absent), so none of them ever exercised theopen="false"string this code produced.Before
After