Skip to content

[lexical-playground] Bug Fix: $convertLayoutContainerElement always returns null (#6813)#8207

Open
Prana-S wants to merge 1 commit intofacebook:mainfrom
Prana-S:fix-layout-container-null-6813
Open

[lexical-playground] Bug Fix: $convertLayoutContainerElement always returns null (#6813)#8207
Prana-S wants to merge 1 commit intofacebook:mainfrom
Prana-S:fix-layout-container-null-6813

Conversation

@Prana-S
Copy link

@Prana-S Prana-S commented Mar 11, 2026

Description

What is the current behavior?

$convertLayoutContainerElement (used in importDOM) always returns null because it calls window.getComputedStyle(domNode) on an element that is not mounted in the document. getComputedStyle on a detached element returns empty strings for all CSS properties, so templateColumns is always '' (falsy) and the function returns null instead of a valid LayoutContainerNode.

This means that copy-pasting or HTML-importing a layout container from Lexical's own exportDOM output silently drops the node instead of restoring it.

Issue: #6813

What is the new behavior?

$convertLayoutContainerElement now reads the inline style directly via domNode.style.getPropertyValue('grid-template-columns'), which works correctly on detached DOM elements (since exportDOM sets this as an inline style). The node is now properly reconstructed with the correct templateColumns value.

Changes

  • packages/lexical-playground/src/nodes/LayoutContainerNode.ts — Replace window.getComputedStyle(domNode) with domNode.style in $convertLayoutContainerElement. Remove the intermediate styleAttributes variable; read templateColumns directly from the inline style in one step.
  • packages/lexical-playground/src/__tests__/unit/LexicalLayoutContainerNode.test.ts (new file) — Add two unit tests:
    1. Asserts that domNode.style.getPropertyValue returns the correct value on a detached element while window.getComputedStyle returns '' (proving the root cause).
    2. Asserts that a LayoutContainerNode round-trips correctly through create → read.

How was this tested?

  • Verified the fix locally by:
    • Manually constructing a detached div with style.gridTemplateColumns = '1fr 1fr 1fr' and confirming domNode.style.getPropertyValue(...) returns '1fr 1fr 1fr' while window.getComputedStyle(domNode).getPropertyValue(...) returns ''.
    • Running the repo's unit test suite: yarn jest LexicalLayoutContainerNode
  • Added two unit tests covering the exact failure case described in the issue.

Test commands

cd packages/lexical-playground
yarn test

or specifically:

yarn jest LexicalLayoutContainerNode

Checklist

… by using domNode.style instead of getComputedStyle (facebook#6813)
@vercel
Copy link

vercel bot commented Mar 11, 2026

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

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Mar 11, 2026 1:56am
lexical-playground Ready Ready Preview, Comment Mar 11, 2026 1:56am

Request Review

@meta-cla
Copy link

meta-cla bot commented Mar 11, 2026

Hi @Prana-S!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@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 Mar 11, 2026
@meta-cla
Copy link

meta-cla bot commented Mar 11, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

Copy link
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests don't pass type check

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