payload icon indicating copy to clipboard operation
payload copied to clipboard

Data from nested lists in richt text is incorrect

Open AlessioGr opened this issue 3 years ago • 6 comments

Bug Report

Nested lists from the rich text fields are rendering incorrectly. In Payload: image In my frontend: image This is the incorrect HTML it generates: image And this is what it's supposed to generate (ignore the ::marker or spans, just look at the structure): image.

The <ul> of the second level would kinda need to be part of the first level; however, it's not. This is the relevant part of the data from the rest API.

{
    "type":"li",
    "children":[
        {
            "text":"A"
        }
    ]
},
{
    "type":"li",
    "children":[
    {
        "type":"ul",
        "children":[
            {
                "type":"li",
                "children":[
                {
                    "text":"B"
                }
                ]
            },
            {
                "type":"li",
                "children":[
                {
                    "type":"ul",
                    "children":[
                        {
                            "type":"li",
                            "children":[
                            {
                                "text":"C"
                            }
                            ]
                        },
                        {
                            "type":"li",
                            "children":[
                            {
                                "text":"C"
                            }
                            ]
                        }
                    ]
                }
                ]
            }
        ]
    }
    ]
},

As you can see, "B" is not part of "A" here. Not sure if that's an issue with what the rest API outputs or with how it's rendered (I just followed what's explained in your docs there).

AlessioGr avatar Apr 30 '22 21:04 AlessioGr

Hey @AlessioGr — Payload I believe is currently outputting correctly formatted JSON for nested lists — however, browsers have weirdness with nested lists, which is what you're showing in your screenshot. Basically, if you have an li within an li, you'll get two bullets.

The solution is to use CSS, and to do something like this in your HTML serializer, which disables list style if there is an embedded list:

case 'li':
  const hasListChildren = node.children ? node.children.find((child) => child?.type && ['ul', 'ol'].includes(child.type)) : false;
  return (
    <li
      key={i}
      style={{ listStyle: hasListChildren ? 'none' : undefined }}
    >
      <Serialize
        content={node.children}
      />
    </li>
  );

jmikrut avatar May 02 '22 13:05 jmikrut

Hey @AlessioGr — Payload I believe is currently outputting correctly formatted JSON for nested lists — however, browsers have weirdness with nested lists, which is what you're showing in your screenshot. Basically, if you have an li within an li, you'll get two bullets.

The solution is to use CSS, and to do something like this in your HTML serializer, which disables list style if there is an embedded list:

case 'li':
  const hasListChildren = node.children ? node.children.find((child) => child?.type && ['ul', 'ol'].includes(child.type)) : false;
  return (
    <li
      key={i}
      style={{ listStyle: hasListChildren ? 'none' : undefined }}
    >
      <Serialize
        content={node.children}
      />
    </li>
  );

Hey, that could work visually. Semantically I don't think it's correct too, though. Shouldn't the second-level <li> be nested inside an <ul> in the top-level <li>? Because right now, they are on the same level. So instead of:

<li>
  A
</li>
<li>
  <ul>
    <li>
      B
    </li>
  </ul>
</li>

It should be:

<li>
  A
  <ul>
    <li>
      B
    </li>
  </ul>
</li>

to be semantically correct, shouldn't it?

EDIT: See https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML/HTML_text_fundamentals#nesting_lists or https://stackoverflow.com/questions/5899337/proper-way-to-make-html-nested-list

AlessioGr avatar May 02 '22 13:05 AlessioGr

Ah I see what you're saying. That makes sense, because the nested list is likely semantically connected to the A topic, vs. starting a completely separate idea within a new list item.

Let me see what we can do about this! Good call!

jmikrut avatar May 02 '22 13:05 jmikrut

@jmikrut Do you think the weird behaviour about the indent/outdent feature, that I show in the video below, might be related to this issue :)?

Video: https://user-images.githubusercontent.com/4012401/188283007-92e96d94-2dc9-4b51-8d4b-2c924c5e1b41.mp4

katywings avatar Sep 03 '22 18:09 katywings

@katywings it sure is!

We are going to tackle this issue next. Give us a few days here and I will report back with our progress. Thanks for the video - this is super helpful!

jmikrut avatar Sep 08 '22 00:09 jmikrut

Thanks @katywings for the video. Just came across this / likely related issue on the editor.

When exiting indented list formatting to add some regular text after the list, caret/text remains indented. And when doing "unindents" it messes up the indents on the list above.

Repro steps for this:

  1. Start creating bullet list. Add 3 entries
  2. Indent each entry a level deeper than the previous entry
  3. Press enter for new line (creates 4th list entry)
  4. Press button "bullet list format" to exit/stop list formatting (bullet is removed - list formatting should stop now?)
  5. Observe: Caret remains indented
  6. Press button "unindent" until caret reaches the base level
  7. Observe: previously created list's indents are altered

jamov avatar Sep 09 '22 09:09 jamov

@jmikrut How is this going?

Stupidism avatar Nov 09 '22 23:11 Stupidism

Hey @Stupidism we're going to address this after launch week! Got some other features prioritized over this issue at the moment. But it is indeed on our radar.

jmikrut avatar Nov 11 '22 12:11 jmikrut

When is launch week? a week in a month? @jmikrut

Stupidism avatar Nov 14 '22 02:11 Stupidism

When is launch week? a week in a month? @jmikrut

I think this was referred: https://payloadcms.com/blog/launch-week

jamov avatar Nov 14 '22 09:11 jamov

this resolved yet? @jmikrut

TomDoFuture avatar Dec 10 '22 01:12 TomDoFuture

Hallelujah it's a Christmas miracle.

I just wasted about 1,000,000 brain cells on fixing this issue but it is now done and will be released shortly!

jmikrut avatar Dec 23 '22 16:12 jmikrut

🤩🎉

falko100 avatar Dec 23 '22 16:12 falko100

@jmikrut Thank you so much for your work! I wish you an amazzzing Christmas with lots of payload in form of Christmas presents 🥳

katywings avatar Dec 23 '22 16:12 katywings

Awesome, thank you @jmikrut! Happy holidays to you and everyone 🎄

jamov avatar Dec 23 '22 16:12 jamov

Still buggy:

Reproduced in demo page: https://demo.payloadcms.com/admin/collections/forms/645b61a2c76a997a0c0952eb

image image

Stupidism avatar May 10 '23 09:05 Stupidism