Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Guide for migrating forms from the legacy JsonForm/FormModel system to the new TanStack-based form system.
.claude/skills/migrate-frontend-forms/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-02 | ✗→✓ | ▲ Improved | 125% | 0% |
| case-03 | ✗→✓ | ▲ Improved | 143% | 0% |
| case-07 | ✗→✓ | ▲ Improved | 226% | 0% |
| case-08 | ✗→✓ | ▲ Improved | 131% | 0% |
| case-10 | ✗→✓ | ▲ Improved | 193% | 0% |
This skill helps migrate forms from Sentry's legacy form system (JsonForm, FormModel) to the new TanStack-based system.
| Old System | New System | Notes | | -------------------- | --------------------- | ---------------------------------------------------- | | saveOnBlur: true | AutoSaveForm | Default behavior | | confirm | confirm prop | string \| ((value) => string \| undefined) | | showHelpInTooltip | variant="compact" | On layout components | | disabledReason | disabled="reason" | String shows tooltip | | extraHelp | JSX in layout | Render <Text> below field | | getData | mutationFn | Transform data in mutation function | | mapFormErrors | Request error adapter | Explicit for regular forms; provided for auto-save | | saveMessage | onSuccess | Show toast in mutation onSuccess callback | | formatMessageValue | onSuccess | Control toast content in onSuccess callback | | resetOnError | onError | Call form.reset() in mutation onError | | saveOnBlur: false | useScrapsForm | Use regular form with explicit Save button | | (automatic) | form.reset() | Call after successful mutation if form stays on page | | help | hintText | On layout components | | label | label | On layout components | | required | required | On layout + Zod schema |
confirm propOld:
tsx{ name: 'require2FA', type: 'boolean', confirm: { true: 'Enable 2FA for all members?', false: 'Allow members without 2FA?', }, isDangerous: true, }
New:
tsx<AutoSaveForm name="require2FA" confirm={value => value ? 'Enable 2FA for all members?' : 'Allow members without 2FA?' } {...} >
variant="compact"Old:
tsx{ name: 'field', help: 'This is help text', showHelpInTooltip: true, }
New:
tsx<field.Layout.Row label="Field" hintText="This is help text" variant="compact" >
disabled="reason"Old:
tsx{ name: 'field', disabled: true, disabledReason: 'Requires Business plan', }
New:
tsx<field.Input disabled="Requires Business plan" {...} />
Old:
tsx{ name: 'sensitiveFields', help: 'Main help text', extraHelp: 'Note: These fields apply org-wide', }
New:
tsx<field.Layout.Stack label="Sensitive Fields" hintText="Main help text"> <field.TextArea {...} /> <Text size="sm" variant="muted"> Note: These fields apply org-wide </Text> </field.Layout.Stack>
mutationFnThe getData function transformed field data before sending to the API. In the new system, handle this in the mutationFn.
Old:
tsx// Wrap field value in 'options' key { name: 'sentry:csp_ignored_sources_defaults', type: 'boolean', getData: data => ({options: data}), } // Or extract/transform specific fields { name: 'slug', getData: (data: {slug?: string}) => ({slug: data.slug}), }
New:
tsx<AutoSaveForm name="sentry:csp_ignored_sources_defaults" schema={schema} initialValue={project.options['sentry:csp_ignored_sources_defaults']} mutationOptions={{ mutationFn: data => { // Transform data before API call (equivalent to getData) const transformed = {options: data}; return fetchMutation({ url: `/projects/${organization.slug}/${project.slug}/`, method: 'PUT', data: transformed, }); }, }} > {field => ( <field.Layout.Row label="Use default ignored sources"> <field.Switch checked={field.state.value} onChange={field.handleChange} /> </field.Layout.Row> )} </AutoSaveForm>
Simpler pattern - If you just need to wrap the value:
tsxmutationOptions={{ mutationFn: fieldData => { return fetchMutation({ url: `/projects/${org}/${project}/`, method: 'PUT', data: {options: fieldData}, // getData equivalent }); }, }}
Important: Typing mutations correctly
The mutationFn should be typed with the API's data type (e.g., Partial<Organization>, Partial<Project>), not the schema-inferred type. The schema is for client-side field validation only — the mutation receives whatever the API endpoint accepts. Tying the mutation to the schema couples two unrelated concerns and can cause type errors when the schema types don't exactly match the API types.
tsx// ❌ Don't use generic types - breaks field type narrowing mutationOptions={{ mutationFn: (data: Record<string, unknown>) => { return fetchMutation({url: '/user/', method: 'PUT', data: {options: data}}); }, }} // ❌ Don't tie mutation type to the zod schema mutationOptions={{ mutationFn: (data: Partial<z.infer<typeof preferencesSchema>>) => { return fetchMutation({url: '/user/', method: 'PUT', data: {options: data}}); }, }} // ✅ Use the API's data type mutationOptions={{ mutationFn: (data: Partial<UserDetails>) => { return fetchMutation({url: '/user/', method: 'PUT', data: {options: data}}); }, }}
Make sure the zod schema's types are compatible with (i.e., assignable to) the API type. For example, if the API expects a string union like 'off' | 'low' | 'high', use z.enum(['off', 'low', 'high']) instead of z.string().
NEVER pass call-site generics to useMutation, mutationOptions, or any TanStack Query function. This applies to ALL generics — data, error, variables, AND context. Types must be inferred, not asserted. See the full rules in static/AGENTS.md under "TanStack Query Type Inference."
tsx// ❌ Generics on useMutation — NEVER do this const mutation = useMutation<CodeOwner, RequestError, [Payload]>({ mutationFn: ([payload]) => fetchMutation({url, method: 'POST', data: payload}), }); // ❌ Generics on mutationOptions — NEVER do this either mutationOptions<unknown, RequestError, Variables, MyContext>({...}) // ❌ Explicit context type — inferred from onMutate return type MyContext = {changeId: string}; // ❌ RequestError as error generic — it's a type assertion in disguise // Other things can go wrong that would NOT yield a RequestError // ✅ Type the mutationFn payload; fetchMutation<T> carries the return type const mutation = useMutation({ mutationFn: (payload: {codeMappingId: string; raw: string}) => fetchMutation<CodeOwner>({ url: `/projects/${org}/${project}/codeowners/`, method: 'POST', data: payload, }), }); // ✅ Context is inferred from onMutate, error is Error by default mutationOptions({ mutationFn: (variables: MyVars) => fetchMutation<MyResponse>({...}), onMutate: async () => { return {changeId: uniqueId()}; // context type inferred from this }, onError: (_error, _vars, context) => { // context?.changeId is typed automatically // _error is Error — use runtime narrowing for RequestError }, })
requestErrorToFieldErrors + setFieldErrorsThe mapFormErrors function transformed API error responses into field-specific errors. In the new system, convert Sentry API errors with requestErrorToFieldErrors, then pass the Scraps FieldErrors result to setFieldErrors.
Do not pass RequestError directly to setFieldErrors. Scraps does not depend on Sentry's API client types.
Old:
tsx// Form-level error transformer function mapMonitorFormErrors(responseJson?: any) { if (responseJson.config === undefined) { return responseJson; } // Flatten nested config errors to dot notation const {config, ...rest} = responseJson; const configErrors = Object.fromEntries( Object.entries(config).map(([key, value]) => [`config.${key}`, value]) ); return {...rest, ...configErrors}; } <Form mapFormErrors={mapMonitorFormErrors} {...}>
New:
tsximport {setFieldErrors} from '@sentry/scraps/form'; import {RequestError} from 'sentry/utils/requestError/requestError'; const form = useScrapsForm({ ...defaultFormOptions, defaultValues: {...}, validators: {onDynamic: schema}, onSubmit: async ({value, formApi}) => { try { await mutation.mutateAsync(value); } catch (error) { if (!(error instanceof RequestError)) { return; } // Keep custom mapping only when the legacy form reshaped the response. const responseJson = error.responseJSON; if (responseJson?.config) { // Flatten nested errors to dot notation const {config, ...rest} = responseJson; const errors: Record<string, {message: string}> = {}; for (const [key, value] of Object.entries(rest)) { errors[key] = {message: Array.isArray(value) ? value[0] : String(value)}; } for (const [key, value] of Object.entries(config)) { errors[`config.${key}`] = {message: Array.isArray(value) ? value[0] : String(value)}; } setFieldErrors(formApi, errors); } } }, });
Simpler pattern - For flat error responses:
tsximport {setFieldErrors} from '@sentry/scraps/form'; import {RequestError} from 'sentry/utils/requestError/requestError'; import {requestErrorToFieldErrors} from 'sentry/utils/requestError/requestErrorToFieldErrors'; onSubmit: async ({value, formApi}) => { try { await mutation.mutateAsync(value); } catch (error) { if (!(error instanceof RequestError)) { addErrorMessage(t('Unable to save changes.')); return; } const handled = setFieldErrors( formApi, requestErrorToFieldErrors(error, formApi.state.values) ); if (!handled) { addErrorMessage(t('Unable to save changes.')); } } },
requestErrorToFieldErrors accepts RequestError. Narrow unknown errors at the Sentry call site before conversion. The adapter filters response keys against formApi.state.values and returns the Scraps field-error shape. Use a direct FieldErrors object only when the migration needs custom response reshaping, such as the nested config example above.
For AutoSaveForm, standard request error handling is automatic. The Sentry form error provider uses requestErrorToFieldErrors for field errors and getRequestErrorUserMessage for request detail or status messages. Do not add the regular-form catch block to each auto-save field.
> Note: setFieldErrors supports nested paths with dot notation: 'config.schedule': {message: 'Invalid schedule'}
onSuccessThe saveMessage showed a custom toast/alert after successful save. In the new system, handle this in the mutation's onSuccess callback.
Old:
tsx{ name: 'fingerprintingRules', saveOnBlur: false, saveMessageAlertVariant: 'info', saveMessage: t('Changing fingerprint rules will apply to future events only.'), }
New:
tsximport {addSuccessMessage} from 'sentry/actionCreators/indicator'; <AutoSaveForm name="fingerprintingRules" schema={schema} initialValue={project.fingerprintingRules} mutationOptions={{ mutationFn: data => fetchMutation({...}), onSuccess: () => { // Custom success message (equivalent to saveMessage) addSuccessMessage(t('Changing fingerprint rules will apply to future events only.')); }, }} >
onSuccessThe formatMessageValue controlled how the changed value appeared in success toasts. Setting it to false disabled showing the value entirely (useful for large text fields). In the new system, you control this directly in onSuccess.
Old:
tsx{ name: 'fingerprintingRules', saveMessage: t('Rules updated'), formatMessageValue: false, // Don't show the (potentially huge) value in toast }
New:
tsxmutationOptions={{ mutationFn: data => fetchMutation({...}), onSuccess: () => { // Just show the message, no value (equivalent to formatMessageValue: false) addSuccessMessage(t('Rules updated')); }, }} // Or if you want to show a formatted value: onSuccess: (data) => { addSuccessMessage(t('Slug changed to %s', data.slug)); },
onErrorThe resetOnError option reverted fields to their previous value when a save failed. In the new system, call form.reset() in the mutation's onError callback.
Old:
tsx// Form-level reset on error <Form resetOnError apiEndpoint="/auth/" {...}> // Or field-level (BooleanField always resets on error) <FormField resetOnError name="enabled" {...}>
New (with useScrapsForm):
tsxconst form = useScrapsForm({ ...defaultFormOptions, defaultValues: {password: ''}, validators: {onDynamic: schema}, onSubmit: async ({value}) => { try { await mutation.mutateAsync(value); } catch (error) { // Reset form to previous values on error (equivalent to resetOnError) form.reset(); throw error; // Re-throw if you want error handling to continue } }, });
New (with AutoSaveForm):
tsx<AutoSaveForm name="enabled" schema={schema} initialValue={settings.enabled} mutationOptions={{ mutationFn: data => fetchMutation({...}), onError: () => { // The field automatically shows error state via TanStack Query // If you need to reset the value, you can pass a reset callback }, }} >
> Note: AutoSaveForm with TanStack Query already handles error states gracefully - the mutation's isError state is reflected in the UI. Manual reset is typically only needed for specific UX requirements like password fields.
When using useScrapsForm for a form that stays on the page after save, call form.reset() after a successful mutation. This re-syncs the form with updated defaultValues so it becomes pristine again — any UI that depends on the form being dirty (like conditionally shown Save/Cancel buttons) will update correctly.
tsxonSubmit: ({value}) => mutation .mutateAsync(value) .then(() => form.reset()) .catch(() => {}),
> Note: AutoSaveForm handles this automatically. You only need to add this when using useScrapsForm.
useScrapsFormFields with saveOnBlur: false showed an inline alert with Save/Cancel buttons instead of auto-saving. This was used for dangerous operations (slug changes) or large text edits (fingerprint rules).
In the new system, use a regular form with useScrapsForm and an explicit Save button. This preserves the UX of showing warnings before committing.
Old:
tsx{ name: 'slug', type: 'string', saveOnBlur: false, saveMessageAlertVariant: 'warning', saveMessage: t("Changing a project's slug can break your build scripts!"), }
New:
tsximport {Alert} from '@sentry/scraps/alert'; import {Button} from '@sentry/scraps/button'; import {defaultFormOptions, useScrapsForm} from '@sentry/scraps/form'; const slugSchema = z.object({ slug: z.string().min(1, 'Slug is required'), }); function SlugForm({project}: {project: Project}) { const mutation = useMutation({ mutationFn: (data: {slug: string}) => fetchMutation({url: `/projects/${org}/${project.slug}/`, method: 'PUT', data}), }); const form = useScrapsForm({ ...defaultFormOptions, defaultValues: {slug: project.slug}, validators: {onDynamic: slugSchema}, onSubmit: ({value}) => mutation.mutateAsync(value).catch(() => {}), }); return ( <form.AppForm form={form}> <form.AppField name="slug"> {field => ( <field.Layout.Stack label="Project Slug"> <field.Input value={field.state.value} onChange={field.handleChange} /> </field.Layout.Stack> )} </form.AppField> {/* Warning shown before saving (equivalent to saveMessage) */} <Alert variant="warning"> {t("Changing a project's slug can break your build scripts!")} </Alert> <Flex gap="sm" justify="end"> <form.ResetButton>Reset</form.ResetButton> <form.SubmitButton>Save</form.SubmitButton> </Flex> </form.AppForm> ); }
When to use this pattern:
Submit through the form, not around it. Follow the SlugForm pattern above — the mutation runs in onSubmit and the Save button is <form.SubmitButton>. Don't render <form.AppForm> without an onSubmit and trigger the mutation from a standalone <Button onClick>:
tsx// ❌ Form is never submitted; mutation fires from a separate button const form = useScrapsForm({ ...defaultFormOptions, defaultValues, validators: {onDynamic: schema}, // no onSubmit }); return ( <form.AppForm form={form}> <form.AppField name="codeMappingId">{...}</form.AppField> <Button onClick={() => mutation.mutate(...)}>Save</Button> </form.AppForm> );
A form that's never actually submitted bypasses validation, pending/disabled state, and field-error wiring.
Sentry's SettingsSearch allows users to search for individual settings fields. When migrating forms, you must preserve this searchability by wrapping migrated forms with FormSearch.
FormSearch ComponentFormSearch is a build-time marker component — it has zero runtime behavior and simply renders its children unchanged. Its route prop is read by a static extraction script to associate form fields with their navigation route, enabling them to appear in SettingsSearch results.
tsximport {FormSearch} from 'sentry/components/core/form'; <FormSearch route="/settings/account/details/"> <FieldGroup title={t('Account Details')}> <AutoSaveForm name="name" schema={schema} initialValue={user.name} mutationOptions={...}> {field => ( <field.Layout.Row label={t('Name')} hintText={t('Your full name')} required> <field.Input /> </field.Layout.Row> )} </AutoSaveForm> </FieldGroup> </FormSearch>
Props:
| Prop | Type | Description | | ---------- | ----------- | ---------------------------------------------------------------------------------------------------- | | route | string | The settings route for this form (e.g., '/settings/account/details/'). Used for search navigation. | | children | ReactNode | The form content — rendered unchanged at runtime. |
Rules:
route must match the settings page URL exactly (including trailing slash).FormSearch, not individual fields.<AutoSaveForm> or <form.AppField> inside a FormSearch will be indexed. Make sure label and hintText are plain string literals or t() calls — computed/dynamic strings will be skipped by the extractor.After adding or updating FormSearch wrappers, regenerate the field registry so that search results stay up to date:
bashpnpm run extract-form-fields
This script (./scripts/extractFormFields.ts) scans all TSX files, finds <FormSearch> components, extracts field metadata (name, label, hintText, route), and writes the generated registry to static/app/views/settings/fieldRegistry.generated.ts. Commit this generated file alongside your migration PR — it is part of the source tree.
> Run the command after any change to forms inside a FormSearch wrapper (adds, removals, label changes). The generated file is checked in and should not be edited manually.
If the legacy JsonForm being migrated was already indexed by SettingsSearch (i.e., it had entries in sentry/data/forms), you must add a FormSearch wrapper to the new form so search functionality is preserved. The old and new sources coexist — new registry entries take precedence over old ones for the same route + field combination — but once you remove the legacy form the old entries will disappear.
Legacy select fields often started with an empty/undefined value and required a selection. In the new system, use .nullable().refine() in the schema, type defaultValues with z.input<typeof schema>, and call schema.parse(value) in onSubmit.
Old:
tsx{ name: 'provider', type: 'select', required: true, choices: [['github', 'GitHub'], ['launchdarkly', 'LaunchDarkly']], }
New:
tsxconst schema = z.object({ provider: z .enum(['github', 'launchdarkly']) .nullable() .refine(v => v !== null, 'Provider is required'), }); // z.input accepts null; z.output (after refine) does not const defaultValues: z.input<typeof schema> = { provider: null, }; const form = useScrapsForm({ ...defaultFormOptions, defaultValues, validators: {onDynamic: schema}, onSubmit: ({value}) => { // schema.parse narrows null away — mutation receives z.output return mutation.mutateAsync(schema.parse(value)).catch(() => {}); }, });
This pattern is necessary whenever a required field has no meaningful initial value. The z.input / z.output distinction ensures the form accepts null as default while the mutation receives the validated, non-null type.
| Feature | Usage | Reason | | ----------- | ------- | ------------------------------------------------------------------------------------- | | allowUndo | 3 forms | Undo in toasts adds complexity with minimal benefit. Use simple error toasts instead. |
useMutation — type the mutationFn payload and use fetchMutation<T> for the return typeuseScrapsForm with a Save button: mutation runs in onSubmit, triggered by <form.SubmitButton> (no form that's never submitted)help → hintText on layoutsshowHelpInTooltip → variant="compact"disabledReason → disabled="reason string"extraHelp → additional JSX in layoutconfirm object to function: (value) => message | undefinedgetData in mutationFnRequestError before requestErrorToFieldErrors, then call setFieldErrorsAutoSaveForm, use the app-provided request error handlingmapFormErrors reshaped the API responsesaveMessage in onSuccess callbacksaveOnBlur: false fields to regular forms with Save buttonform.reset() after successful mutation (for forms that stay on page)onSuccess cache updates merge with existing data (use updater function) — some API endpoints may return partial objects<FormSearch route="..."> if the old form was searchable in SettingsSearchpnpm run extract-form-fields and commit the updated fieldRegistry.generated.ts| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→fail | 22,338 | 18,151 | -19% | 1 | 1 | 0% | 3,603 | 9,161 | +154% | 0 | 0 | — |
case-02 | fail→pass | 25,110 | 18,308 | -27% | 1 | 1 | 0% | 4,205 | 9,452 | +125% | 0 | 0 | — |
case-03 | fail→pass | 22,938 | 19,153 | -17% | 1 | 1 | 0% | 3,913 | 9,491 | +143% | 0 | 0 | — |
case-04 | pass→pass | 10,329 | 8,889 | -14% | 1 | 1 | 0% | 1,031 | 7,005 | +579% | 0 | 0 | — |
case-05 | fail→fail | 22,307 | 17,269 | -23% | 1 | 1 | 0% | 3,502 | 8,962 | +156% | 0 | 0 | — |
case-06 | pass→fail | 15,470 | 10,313 | -33% | 1 | 1 | 0% | 2,286 | 7,328 | +221% | 0 | 0 | — |
case-07 | fail→pass | 16,790 | 12,173 | -27% | 1 | 1 | 0% | 2,341 | 7,643 | +226% | 0 | 0 | — |
case-08 | fail→pass | 19,927 | 9,847 | -51% | 1 | 1 | 0% | 3,112 | 7,178 | +131% | 0 | 0 | — |
case-09 | pass→pass | 18,608 | 6,129 | -67% | 1 | 1 | 0% | 2,437 | 7,544 | +210% | 0 | 0 | — |
case-10 | fail→pass | 17,411 | 8,991 | -48% | 1 | 1 | 0% | 2,418 | 7,084 | +193% | 0 | 0 | — |
case-11 | fail→pass | 10,349 | 10,230 | -1% | 1 | 1 | 0% | 1,879 | 7,329 | +290% | 0 | 0 | — |
case-12 | fail→pass | 13,757 | 8,958 | -35% | 1 | 1 | 0% | 2,159 | 7,072 | +228% | 0 | 0 | — |
case-13 | fail→pass | 21,443 | 14,402 | -33% | 1 | 1 | 0% | 2,921 | 8,336 | +185% | 0 | 0 | — |
case-14 | fail→pass | 17,296 | 16,647 | -4% | 1 | 1 | 0% | 3,516 | 8,865 | +152% | 0 | 0 | — |
case-15 | fail→pass | 14,745 | 5,332 | -64% | 1 | 1 | 0% | 2,750 | 7,323 | +166% | 0 | 0 | — |
case-16 | fail→pass | 16,267 | 5,912 | -64% | 1 | 1 | 0% | 2,007 | 7,502 | +274% | 0 | 0 | — |
case-17 | pass→pass | 15,032 | 10,978 | -27% | 1 | 1 | 0% | 1,708 | 7,399 | +333% | 0 | 0 | — |
case-18 | fail→pass | 15,279 | 12,495 | -18% | 1 | 1 | 0% | 2,848 | 9,120 | +220% | 0 | 0 | — |
case-19 | fail→pass | 19,730 | 11,801 | -40% | 1 | 1 | 0% | 2,782 | 7,699 | +177% | 0 | 0 | — |
case-20 | fail→pass | 23,975 | 16,739 | -30% | 1 | 1 | 0% | 3,032 | 8,962 | +196% | 0 | 0 | — |
case-21 | fail→pass | 25,531 | 9,838 | -61% | 1 | 1 | 0% | 4,868 | 7,238 | +49% | 0 | 0 | — |
case-22 | fail→pass | 27,923 | 7,436 | -73% | 1 | 1 | 0% | 3,739 | 6,583 | +76% | 0 | 0 | — |
case-23 | fail→pass | 19,944 | 15,727 | -21% | 1 | 1 | 0% | 3,091 | 8,627 | +179% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 23 cases were attempted. The headline lift of +70 percentage points is the difference between those two pass rates over the 23 comparable cases. 1 case got worse with the skill loaded, and it is included in that figure.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
| Model | Method | Date | Lift |
|---|---|---|---|
| gemini-3.6-flash | verified | 7/27/2026 | +64% |
Other measured skills in the registry, with their headline benchmark lift.