sanity-io / orderable-document-list

Drag-and-drop Document Ordering without leaving the Editing surface
MIT License
75 stars 22 forks source link

Sanity AI Assist can fill in an orderRank value and crash the entire application #89

Open thijs-justacodename opened 7 months ago

thijs-justacodename commented 7 months ago

Describe the bug When using Sanity AI Assist, using an instruction that "changes the document", we've seen that it entered a numerical value into an orderRank field. Instead of 0|00001, Sanity AI Assist inserted 1. This crashed the entire Sanity application with the following error:

Error: undefined is not an object (evaluating 'n.indexof')

parse@https://vev-cms.sanity.studio/static/sanity-9d8b5920.js:6932:288611
parse@https://vev-cms.sanity.studio/static/sanity-9d8b5920.js:6932:296693
JF3@https://vev-cms.sanity.studio/static/sanity-9d8b5920.js:8375:34507

Debugging step by step showed that orderRank field is expected to be a string. Since we have not defined newItemPosition, it defaults to after, which triggers a query to find the highest order rank to use for initialValue. Since this happens upon loading the schema, the entire application fails to start.

To Reproduce

  1. Have a schema that has orderRank field, and newItemPosition not enabled
  2. Create two document
  3. In the most recently created document, use Sanity AI Assist to translate all fields in the document to some language (or manually set the orderRank field value to 1 if using Sanity AI to reproduce is too difficult).
  4. Observe that the Sanity application crashes

Expected behavior

  1. The application not to crash.

Possible remediations

  1. The orderRankField to have options: { aiAssist: { exclude: true } } defined
  2. Maybe some hardening against unexpected values in the orderRank field

Screenshots Scherm_afbeelding 2024-03-12 om 13 03 30

Which versions of Sanity are you using?

@sanity/cli (global) 3.32.0 (up to date) @sanity/assist 2.0.2 (latest: 2.0.3) @sanity/color-input 3.1.1 (up to date) @sanity/orderable-document-list 1.2.1 (up to date) @sanity/ui 2.0.7 (latest: 2.0.10) @sanity/vision 3.32.0 (up to date) sanity 3.32.0 (up to date)

What operating system are you using? MacOS

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