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

Unknown list item style "normal" while using Sanity #9

Open
kamerat opened this issue May 29, 2022 · 5 comments
Open

Unknown list item style "normal" while using Sanity #9

kamerat opened this issue May 29, 2022 · 5 comments

Comments

@kamerat
Copy link

kamerat commented May 29, 2022

Using the default Sanity bullet list, this warning comes in the console:

Unknown list item style "normal", specify a component for it in the 'components.listItem' prop

const content = [
    {
        "_key": "3a27e049b445",
        "_type": "block",
        "children": [
            {
                "_key": "3542518d9367",
                "_type": "span",
                "marks": [],
                "text": "This is a list item"
            }
        ],
        "level": 1,
        "listItem": "bullet",
        "markDefs": [],
        "style": "normal"
    }
]

<PortableText value={content} />
@kamerat
Copy link
Author

kamerat commented Oct 18, 2022

Sanity's default default style has the name of normal. When adding a list(bullet or number) the normal style is applied to this block by default unless set to something else.

There are three workarounds for this issue if you are using Sanity:

  1. Create a bullet type in Sanity
     {
         title: 'Block',
         type: 'block',
         styles: [
            //...
             { title: 'Bullet', value: 'bullet' }, //<-- Adding a custom style of tyle bullet will also surpress warning if used on bullet list
         ],
         lists: [{ title: 'Bullet', value: 'bullet' }],
     },
    
  2. Use a custom list component
     <script lang="ts">
         import { PortableText, DefaultListItem } from '@portabletext/svelte'
         const content = [...]
     </script>
     
     <PortableText
         value={content}
         components={{
             listItem: {
                 bullet: DefaultListItem,
                 number: DefaultListItem,
                 normal: DefaultListItem //<-- Adding "normal" as key and defaultListItem as value will supress the warning
             }
         }}
     />
    
  1. Using onMissingComponent prop
    <script lang="ts">
        import { PortableText} from '@portabletext/svelte'
        const content = [...]
    </script>
    
    <PortableText
        value={content}
        onMissingComponent={false}
    />
    

The second option above would be recomended as it is nontrivial to add "bullet style" to all bullet points in the sanity WYSIWYG editor. It will display the default list normally, just without a warning.

This is also the default action of this component if it comes across a list with an undefined list style as seen here.

@kamerat kamerat changed the title Unknown list item style "normal" Unknown list item style "normal" while using Sanity Oct 18, 2022
@fschroiff
Copy link

You would also need to add other styles when you go for option two, like h2, h3 etc.

@progone
Copy link

progone commented May 6, 2023

@kamerat
Did the solution work for you?

@kamerat
Copy link
Author

kamerat commented May 9, 2023

Hi @progone. Yes indeed. I currently use solution 2 as stated in my previous pos :) Works well.

@Renkas
Copy link

Renkas commented Apr 13, 2024

Why isn't normal: DefaultListItem there by default?

What a waste of time for every developer that uses Sanity with Svelte to have to debug this error and do it manually

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

4 participants