fix: avoid Sanity 5 document-context crash in tool dialogs - #79
Open
wdtamagi wants to merge 1 commit into
Open
Conversation
Since Sanity 5, the core `FormField` renders `FormDivergenceIndicator` and `FormNodeDivergenceDetail`, both of which call `useDocumentDivergences()` unconditionally. That hook throws when rendered outside a document pane: useDocumentDivergences must be used within a DocumentDivergencesContext This plugin renders `<FormField>` inside its standalone tool dialogs (the 'Add project' and access-token forms), so opening either dialog crashes the Studio on Sanity 5. Replace the core `FormField` with a local, context-free shim built from @sanity/ui (Stack + Text) that preserves the same title/description layout without depending on document-editing context. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Sanity 5, opening either of the plugin's tool dialogs (Add project or the Vercel Access Token form) crashes the Studio:
Root cause
Since Sanity 5, the core
FormFieldexported fromsanityrendersFormDivergenceIndicatorandFormNodeDivergenceDetail, and both calluseDocumentDivergences()unconditionally. That hook throws when rendered outside a document pane (noDocumentDivergencesContextprovider).This plugin uses
<FormField>inside its standalone tool dialogs (src/deploy-form.tsxandsrc/vercel-deploy.tsx), which are not inside a document pane — so the hook throws and the whole tool view errors out.Fix
Add a small, context-free
FormFieldshim (src/form-field.tsx) built from@sanity/ui(Stack+Text) that reproduces the same title/description layout without depending on document-editing context. Swap the twoimport { FormField } from 'sanity'usages to the local shim.src/form-field.tsx(new)src/deploy-form.tsx— import swapsrc/vercel-deploy.tsx— import swap (keepsuseColorSchemeValuefromsanity)No other
sanityimports are affected; they're all context-free.Verification
npm run build(pkg-utils build --strict --check) passes.