sanity-io / sanity

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

Structure Tool crash when adding '&' character to url field #7455

Closed holjeffcomb closed 5 days ago

holjeffcomb commented 2 weeks ago

Describe the bug

When adding a value to a URL field, Sanity Studio crashes and I cannot delete the problematic entry. The only solution I've found to delete the entry is to use the Sanity CLI with: sanity documents delete <document id>.

To Reproduce

Steps to reproduce the behavior:

  1. Add a URL field to your schema, in my case it was:
    defineField({
    name: 'video',
    title: 'Video',
    type: 'url',
    }),
  2. Input a URL
  3. Sanity Studio crashes and you cannot edit the entry any further

Expected behavior

Sanity Studio should save this value without any problem.

Screenshots

Screenshot 2024-08-30 at 2 32 10 PM

Which versions of Sanity are you using?

@sanity/cli (global) 3.30.1 (latest: 3.56.0) @sanity/eslint-config-studio 4.0.0 (up to date) @sanity/vision 3.56.0 (up to date) sanity 3.56.0 (up to date)

What operating system are you using?

macOS Sonoma 14.4.1

Which versions of Node.js / npm are you running?

10.8.3 v21.7.1

jordanl17 commented 1 week ago

Hi @holjeffcomb, thank you for reporting.

We couldn’t reproduce it with the information provided, could you please share more information about your current setup. If you were able to provide a video showing the process, that would be most ideal.

Additionally, can you clarify whether you only see this error occur when & is typed, or when any input is entered?

Thanks

holjeffcomb commented 6 days ago

Hi @jordanl17, thank you for your reply.

I believe I have been able to track down the cause of the issue. The problem was not necessarily with the url type or the inclusion of certain characters like I initially thought, but more with how I was adding the preview attributes like so:

  preview: {
    select: {
      title: 'title',
      subtitle: 'description',
      media: 'video',
    },
  },

As you can see, I was trying to add a URL as the media, and this was causing the crash. I know that this isn't how media is meant to be declared, but it seems that the way Sanity handles this error could be improved.

Thank you.