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

fix: adds support for document types named using _id incompatible chars #49

Merged
merged 2 commits into from
Aug 13, 2024

Conversation

snorrees
Copy link
Contributor

The problem

Turns out that if you do both of these:

  • use characters in a type name that are incompatible with sanity Id, not in a-zA-Z0-9._-
  • prevent structure tool from crashing by remapping these structure types to url-compatible item ids

AI Assist will crash.

Example: type/with/id/incompatible/slash

The culprit

For each document type, we store instructions in a companion document.
The id for these companion documents is constructed directly from the type name. If the type name has id-incompatible characters, we are gonna have a bad time.

The fix

Ensure the companion document id does not contain illegal characters.

The complication (and workaround)

The current code extracts the type name from the companion document id in the inspector panel, as the document type is used various places.

When we replace illegal characters, we lose information, and cannot get back to the type name (and thus cannot resolve the type).

To work around this, we pass the document type into an existing context (with some type adjustments), so we can access it in the inspector.

Testing

The test studio has been adjusted to include one of these exotic type names & required structure tool changes, so we can ensure this works now.

Example
image

@snorrees snorrees requested a review from robinpyon August 12, 2024 18:12
Copy link

socket-security bot commented Aug 12, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@sanity/vision@3.53.0 Transitive: environment +41 6.19 MB bjoerge
npm/@types/react@18.3.3 None +2 1.69 MB types
npm/sanity@3.53.0 Transitive: environment, eval, filesystem, network, shell, unsafe +822 828 MB bjoerge

🚮 Removed packages: npm/@sanity/vision@3.52.0, npm/@types/react@18.2.75, npm/sanity@3.52.0

View full report↗︎

Copy link

@robinpyon robinpyon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Fascinating use case, this is something that should arguably be caught by the studio before it even hits AI Assist

@snorrees snorrees merged commit 85f9a26 into main Aug 13, 2024
10 checks passed
@snorrees snorrees deleted the id-fix branch August 13, 2024 09:26
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

Successfully merging this pull request may close these issues.

2 participants