lexical icon indicating copy to clipboard operation
lexical copied to clipboard

[lexical-table] Bug Fix: table cell background copy paste not working

Open jvithlani opened this issue 10 months ago • 9 comments

Description

While copy pasting a table cell with backgruond color, the backgruond color doesnt carry forward with the table details

Test plan

Before

https://github.com/user-attachments/assets/25566569-33e2-4753-b990-eb1b99a6e264

After

https://github.com/user-attachments/assets/746f285c-56f9-479c-aa94-57ab6421cade

Insert relevant screenshots/recordings/automated-tests

jvithlani avatar Feb 22 '25 09:02 jvithlani

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 22, 2025 6:50am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 22, 2025 6:50am

vercel[bot] avatar Feb 22 '25 09:02 vercel[bot]

Hi @jvithlani!

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 [email protected]. Thanks!

facebook-github-bot avatar Feb 22 '25 09:02 facebook-github-bot

You'll need to sign the CLA before we can run the tests and possibly merge this PR

etrepum avatar Feb 22 '25 18:02 etrepum

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

facebook-github-bot avatar Feb 22 '25 23:02 facebook-github-bot

It doesn't look like this change passes the existing e2e test suite (possibly because the tests should change to accommodate this new behavior), and there are no new tests that verify that it works now. Further work will have to be done here before it can be merged.

etrepum avatar Feb 24 '25 01:02 etrepum

@jvithlani are you planning on finishing this one?

ivailop7 avatar Mar 02 '25 23:03 ivailop7

Hey @ivailop7, yes ill wrap this up, was a little caught up. Will finish it this week

jvithlani avatar Mar 03 '25 04:03 jvithlani

@ivailop7 @etrepum i see unrelated tests failing, which are working fine on local, can you guys help me fix it

jvithlani avatar Mar 04 '25 09:03 jvithlani

Doesn’t look unrelated? This is the failing test

[chromium] › packages/lexical-playground/tests/e2e/CopyAndPaste/html/TablesHTMLCopyAndPaste.spec.mjs:351:3 › HTML Tables CopyAndPaste › Copy + paste - Merge Grids

etrepum avatar Mar 04 '25 15:03 etrepum

@etrepum i need some help here, i had left this as it looked like a longer debug. I went through the flow, as im trying to mutate the node by setting the background color, a new dom element is being created and replaced, which doesnt have the TableCellSelected class. This was working fine till now as no properties are being imported on pasting.

My concern here is although the table is still selected in the lexical's selection, why didnt the tableObserver update the classes of the new DOM created in the tableCell, i also tried adding a $updateDOMForSelection(editor, tableObserver.getTable(), selection); but this also doesnt help, any help would be much appreciated

jvithlani avatar May 22 '25 10:05 jvithlani

@etrepum tiny bump here

jvithlani avatar May 26 '25 06:05 jvithlani

@jvithlani the tests are still failing.

Edit: Nevermind, I see Bob has commented on this already.

ivailop7 avatar May 26 '25 20:05 ivailop7

@ivailop7 waiting for Bob's reply

jvithlani avatar May 26 '25 20:05 jvithlani

I probably won’t have time to look into this for a few days, this level of question is basically asking me to fix it. It’s a long holiday weekend in the US.

etrepum avatar May 26 '25 20:05 etrepum

The reason why the DOM for those cells is being recreated is because updateDOM is returning true due to the background color change. TableCellNode doesn't implement the optimization where the DOM is updated in-place rather than recreated, it simply throws away the DOM whenever anything changes and recreates it. The DOM does need to be recreated when the tag changes (e.g. td to th) but otherwise more code could be added here to implement that optimization.

$updateDOMForSelection isn't working correctly here because it's built with the assumption that these cells aren't also changing identity. It should probably be implemented as a mutation listener or something like that so that these updates take place after the DOM for those elements are reconciled. This is the result of incorrect code being refactored to fix bugs rather than rearchitected to be correct.

etrepum avatar May 28 '25 18:05 etrepum

Closing as stale, please re-open when/if you intend to complete it.

etrepum avatar Sep 03 '25 22:09 etrepum