sanity-io / sanity

Sanity Studio – Rapidly configure content workspaces powered by structured content
https://www.sanity.io
MIT License
5.07k stars 410 forks source link

Portable Text Editor causes page to freeze and toolbar doesn't update based on prop change #7043

Open vitorussui opened 1 week ago

vitorussui commented 1 week ago

Hi all! I have been trying to add custom behavior to <PortableTextInput /> when connecting it to an input component in the blocks array field. In my case I need to update the list of visible custom types that the user is allowed to insert into the editor based on another field called template. I am able to get that field via useFormValue(['template', 'title'].

When using:

<PortableTextInput {...props} schemaType={resolvedSchemaType} />
//or
props.renderDefault({ ...props, schemaType: resolvedSchemaType })

the block editor's toolbar is always an update behind what's being passed to the schemaType prop. This means it doesn't show the correct custom block types. If I keep changing the selected template it shows the available types for the previous selection. You always need to expand or collapse the editor to get the updated toolbar.

I tried using different hooks to track state changes and force an update using the hideToolbar prop, which works, but then causes the page to completely freeze and crash when you try activating a decorator (by either clicking on an icon or using a shortcut like Cmd + B). This doesn't happen when you already have a selected text.

Below is an example of the allowed custom types for a certain template.

image

I'm using:

Thank you!

christianhg commented 4 days ago

Thanks a lot for the thorough description of the problems you are facing. I believe there are multiple independent issues at play here. I noticed the same freezing behaviour today when toggling decorators in an empty editor - definitely something to fix. I haven't experienced the off-by-one update issue related to the toolbar, but it sounds like something we'll have to reproduce internally and investigate.

LiFaytheGoblin commented 14 hours ago

I have also experienced freezing with the portable text editor. It seems I am getting out of memory errors. This issue is since I upgraded Sanity from 3.38 to 3.47.