[lexical-playground] Bug Fix: $convertLayoutContainerElement always returns null (#6813)#8207
[lexical-playground] Bug Fix: $convertLayoutContainerElement always returns null (#6813)#8207Prana-S wants to merge 1 commit intofacebook:mainfrom
Conversation
… by using domNode.style instead of getComputedStyle (facebook#6813)
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Hi @Prana-S! Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
etrepum
left a comment
There was a problem hiding this comment.
Tests don't pass type check
Description
What is the current behavior?
$convertLayoutContainerElement(used inimportDOM) always returnsnullbecause it callswindow.getComputedStyle(domNode)on an element that is not mounted in the document.getComputedStyleon a detached element returns empty strings for all CSS properties, sotemplateColumnsis always''(falsy) and the function returnsnullinstead of a validLayoutContainerNode.This means that copy-pasting or HTML-importing a layout container from Lexical's own
exportDOMoutput silently drops the node instead of restoring it.Issue: #6813
What is the new behavior?
$convertLayoutContainerElementnow reads the inline style directly viadomNode.style.getPropertyValue('grid-template-columns'), which works correctly on detached DOM elements (sinceexportDOMsets this as an inline style). The node is now properly reconstructed with the correcttemplateColumnsvalue.Changes
packages/lexical-playground/src/nodes/LayoutContainerNode.ts— Replacewindow.getComputedStyle(domNode)withdomNode.stylein$convertLayoutContainerElement. Remove the intermediatestyleAttributesvariable; readtemplateColumnsdirectly from the inline style in one step.packages/lexical-playground/src/__tests__/unit/LexicalLayoutContainerNode.test.ts(new file) — Add two unit tests:domNode.style.getPropertyValuereturns the correct value on a detached element whilewindow.getComputedStylereturns''(proving the root cause).LayoutContainerNoderound-trips correctly through create → read.How was this tested?
divwithstyle.gridTemplateColumns = '1fr 1fr 1fr'and confirmingdomNode.style.getPropertyValue(...)returns'1fr 1fr 1fr'whilewindow.getComputedStyle(domNode).getPropertyValue(...)returns''.yarn jest LexicalLayoutContainerNodeTest commands
or specifically:
Checklist