Skip to content

[lexical-playground] Bug Fix: a closed collapsible container no longer exports as open - #8994

Merged
etrepum merged 1 commit into
meta:mainfrom
LeSingh1:fix/collapsible-open-attribute
Aug 9, 2026
Merged

etrepum merged 1 commit into
meta:mainfrom
LeSingh1:fix/collapsible-open-attribute

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Description

CollapsibleContainerNode.exportDOM stringifies the open flag into the
attribute value:

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:

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)

…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)
```
@vercel

vercel Bot commented Aug 9, 2026

Copy link
Copy Markdown

@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.

@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 9, 2026
@etrepum
etrepum added this pull request to the merge queue Aug 9, 2026
Merged via the queue into meta:main with commit e7fd56e Aug 9, 2026
44 checks passed
@etrepum etrepum mentioned this pull request Aug 31, 2026
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants