Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Copy Pase of List elements b/w Playground & any Custom Instance is producing extra lines #3740

Closed
gaurav21r opened this issue Jan 17, 2023 · 11 comments

Comments

@gaurav21r
Copy link

gaurav21r commented Jan 17, 2023

Since this bug pertains to a base level feature (Lists & Clipboard) I'm flagging as URGENT

Lexical version: 0.6.0 to latest

Steps To Reproduce

  1. Make a list of any arbitrary depth in the playground https://playground.lexical.dev/

image

  1. Copy paste this list (along with the heading & any other element(s) ) in any arbitrary custom instance of Lexical. For example, the Rich Text sandbox in the website https://lexical.dev itself, will give this:

image

Link to code example: Codesandbox link of Rich Text Editor from the website itself: https://codesandbox.io/s/lexical-rich-text-example-5tncvy?from-embed

The current behavior

There is an extra \n being added to every list item that has a sub list.

The expected behavior

The playground editor and all other editors should behave consistently.

Probable cause.

I couldn't understand the code much but I think this line may be the offender.

// Multi-line plain text in rich text mode pasted as separate paragraphs

image

The comment seems to suggest something to the issue.

@gaurav21r gaurav21r changed the title Bug: Copy Pase of List elements b/w Playground & any Custom Instance is producing extra lines Bug: URGENT Copy Pase of List elements b/w Playground & any Custom Instance is producing extra lines Jan 17, 2023
@bschwartz10
Copy link

Experiencing the same behavior of the insertion of an empty editor-listitem when parsing html content back into the editor

parsing logic

const root = $getRoot()
const parser = new DOMParser()
const dom = parser.parseFromString(value, 'text/html')
const nodes = $generateNodesFromDOM(editor, dom)         
root.append(...nodes)

rendered text
Screen Shot 2023-01-19 at 11 58 56 AM

Lexical editor w/ extra empty editor-listitem
Screen Shot 2023-01-19 at 11 58 41 AM

HTML Output

<ol class="editor-list-ol">
    <li value="1" class="editor-listitem ltr" dir="ltr"><span data-lexical-text="true">It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s</span></li>
    <li value="2" class="editor-listitem ltr" dir="ltr"><span data-lexical-text="true">It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s</span></li>
    <li value="3" class="editor-listitem"><br></li>
// ^Extra editor-listitem
    <li value="4" class="editor-listitem editor-nested-listitem">
        <ol class="editor-list-ol">
            <li value="1" class="editor-listitem ltr" dir="ltr"><span data-lexical-text="true">Hows it going</span></li>
        </ol>
    </li>
</ol>

@gaurav21r
Copy link
Author

@trueadm @thegreatercurve As I mentioned should be easy to reproduce for you from the playground website and the lexical homepage. Please give some direction, whenever free.

@thegreatercurve thegreatercurve changed the title Bug: URGENT Copy Pase of List elements b/w Playground & any Custom Instance is producing extra lines Bug: Copy Pase of List elements b/w Playground & any Custom Instance is producing extra lines Jan 20, 2023
@thegreatercurve
Copy link
Contributor

@gaurav21r I think the issue is more to do with the list logic, which we're looking to refactor in the next couple of months. It's a long standing issue with how we are nesting lists #2951

@gaurav21r
Copy link
Author

@thegreatercurve Thanks for responding! Yes it does seem to be the long term fix for this issue. But can you suggest a temp workaround till then?

What I find intriguing is that if I copy the list in the playground and paste it (even in a separate playground instance) its working, similarly if I copy it from the CodeSandbox on the home page and paste it there only its working. Its only when its being transferred across each other that this bug happens. Maybe there is a Plugin in the Playground that's contributing to this?

@acywatson
Copy link
Contributor

acywatson commented Jan 20, 2023

@thegreatercurve Thanks for responding! Yes it does seem to be the long term fix for this issue. But can you suggest a >temp workaround till then?

What I find intriguing is that if I copy the list in the playground and paste it (even in a separate playground instance) its >working, similarly if I copy it from the CodeSandbox on the home page and paste it there only its working. Its only when its >being transferred across each other that this bug happens. Maybe there is a Plugin in the Playground that's contributing to >this?

This behavior is most likely because the bug you're seeing is with HTML Serialization. Lexical uses native JSON transfer format for most cases between Lexical instances, so the bug occurs when the paste content is HTML, but not when it's JSON.

@acywatson
Copy link
Contributor

Experiencing the same behavior of the insertion of an empty editor-listitem when parsing html content back into the editor

This is another indication that the HTML (De)Serialization is the problem.

@acywatson
Copy link
Contributor

Here ya go:

#3757

@gaurav21r
Copy link
Author

@acywatson Thanks a ton! Let me Pull master and confirm so we can close this!

@chalecki
Copy link

Thanks a lot @acywatson 🍺 !

@GermanJablo
Copy link
Contributor

I think the issue is more to do with the list logic, which we're looking to refactor in the next couple of months

hey @thegreatercurve or anyone else on the team. This information is critical to me. Could you tell me what the change will consist of please?

@acywatson
Copy link
Contributor

acywatson commented Jan 23, 2023

@egonbolton

#2951 (comment)

Most of the context is in this thread that you’re already involved in. There’s not much else. @thegreatercurve will own this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants