fix(dev): align dev server typegen defaults with sanity typegen generate#1426
Open
bjoerge wants to merge 2 commits into
Open
fix(dev): align dev server typegen defaults with sanity typegen generate#1426bjoerge wants to merge 2 commits into
sanity typegen generate#1426bjoerge wants to merge 2 commits into
Conversation
Contributor
📦 Bundle Stats —
|
| Metric | Value | vs main (bb18d26) |
|---|---|---|
| Internal (raw) | 2.7 KB | - |
| Internal (gzip) | 1.0 KB | - |
| Bundled (raw) | 11.16 MB | - |
| Bundled (gzip) | 2.10 MB | - |
| Import time | 686ms | +3ms, +0.4% |
bin:sanity
| Metric | Value | vs main (bb18d26) |
|---|---|---|
| Internal (raw) | 782 B | - |
| Internal (gzip) | 423 B | - |
| Bundled (raw) | 9.87 MB | - |
| Bundled (gzip) | 1.78 MB | - |
| Import time | 1.78s | +3ms, +0.2% |
🗺️ View treemap · Artifacts
Details
- Import time regressions over 10% are flagged with
⚠️ - Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.
📦 Bundle Stats — @sanity/cli-core
Compared against main (bb18d264)
| Metric | Value | vs main (bb18d26) |
|---|---|---|
| Internal (raw) | 106.7 KB | - |
| Internal (gzip) | 26.7 KB | - |
| Bundled (raw) | 21.72 MB | - |
| Bundled (gzip) | 3.46 MB | - |
| Import time | 608ms | +15ms, +2.6% |
🗺️ View treemap · Artifacts
Details
- Import time regressions over 10% are flagged with
⚠️ - Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.
📦 Bundle Stats — create-sanity
Compared against main (bb18d264)
| Metric | Value | vs main (bb18d26) |
|---|---|---|
| Internal (raw) | 908 B | - |
| Internal (gzip) | 483 B | - |
| Bundled (raw) | 931 B | - |
| Bundled (gzip) | 491 B | - |
| Import time | ❌ ChildProcess denied: node | - |
Details
- Import time regressions over 10% are flagged with
⚠️ - Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.
Contributor
Coverage Delta
Comparing 1 changed file against main @ Overall Coverage
|
runeb
approved these changes
Jul 2, 2026
runeb
left a comment
Member
There was a problem hiding this comment.
Assuming this doesn't break users types, only reduces diffs and adds more core types
Member
Author
I don't have a clear picture of the downstream impact of these changes, so not in a position to give a confident answer to that. Would love for someone from @sanity-io/typegen to weigh in/review. |
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.
Description
The typegen vite plugin used by
sanity dev/sanity buildhand-rolled its config defaults, defaultingformatGeneratedCodeandoverloadClientMethodstofalse(and using a narrower set of default query patterns). Meanwhile,sanity typegen generateapplies defaults throughconfigDefinition.parse()from@sanity/codegen, where both default totrue. As a result, the samesanity.cli.tsconfig produced different output depending on whether types were generated by the dev server or by the manual command: the dev server emitted unformatted code (large git diffs) without the@sanity/clientquery typemap.This PR replaces the hand-rolled defaults with
configDefinition.parse(inputConfig)— the exact same zod schema thetypegen generatecommand uses — so the two code paths share one source of truth and can't drift again. The schema strips the extraenabledkey from the CLI config, and the plugin's now-redundant local default query patterns were removed.Fixes #1425
What to review
packages/@sanity/cli/src/server/vite/plugin-typegen.ts: config resolution now goes throughconfigDefinition.parse(). Note this intentionally changes the dev-server defaults:formatGeneratedCode: true,overloadClientMethods: true,generates: './sanity.types.ts', and the broader default query patterns from@sanity/codegen(including.astro/.vue/.svelteand./sanity/**).Testing
configDefinition.parse({})verbatim, so it stays in lockstep with@sanity/codegen.fixtures/basic-studiowith the issue reporter's config shape (enabled: true, format/overload unset):sanity typegen generateoutput vs. dev-server-generated output is now byte-identical (prettier-formatted, with thedeclare module "@sanity/client"typemap).formatGeneratedCode: false, overloadClientMethods: false) still produces unformatted output without the typemap.Note
Medium Risk
Default generated
sanity.types.tsoutput changes for projects that relied on implicit dev-server defaults (formatting and client typemap), though explicit config opt-outs still apply.Overview
The Vite typegen plugin used by
sanity dev/sanity buildno longer applies its own default config. It now resolves options withconfigDefinition.parse()from@sanity/codegen, the same path assanity typegen generate, so watch/build and manual runs share one source of truth.Behavior change when fields are left unset: dev-server generation now defaults
formatGeneratedCodeandoverloadClientMethodstotrue, uses@sanity/codegen’s output path and query globs (broader than the removed local patterns), and strips CLI-only keys likeenabledvia the schema. Explicitsanity.cli.tsvalues are unchanged.The plugin unit test now expects
runTypegenGenerateto receiveconfigDefinition.parse({})instead of the old hand-rolled defaults.Reviewed by Cursor Bugbot for commit 70333a0. Bugbot is set up for automated code reviews on this repo. Configure here.