Skip to content

fix(typegen): handle duplicate type names#8950

Merged
sgulseth merged 3 commits intomainfrom
fix/typegen/lookup-inline-map
Apr 8, 2025
Merged

fix(typegen): handle duplicate type names#8950
sgulseth merged 3 commits intomainfrom
fix/typegen/lookup-inline-map

Conversation

@sgulseth
Copy link
Copy Markdown
Member

@sgulseth sgulseth commented Mar 15, 2025

Description

We require each query to be unique, but we normalize the schema type names. Ie foo.bar becomes FooBar, if you then also have another type fooBar that would also become FooBar. This change ensures that we properly increment the suffix

What to review

Did I miss anything?

Testing

Added

Notes for release

TypeGen: Fixes a rare bug where generated type names could collide and wasn't handled correctly.

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 15, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
page-building-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 7, 2025 0:40am
performance-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 7, 2025 0:40am
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 7, 2025 0:40am
3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
e2e-studio ⬜️ Ignored (Inspect) Apr 7, 2025 0:40am
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Apr 7, 2025 0:40am
test-next-studio ⬜️ Ignored (Inspect) Apr 7, 2025 0:40am

@github-actions
Copy link
Copy Markdown
Contributor

No changes to documentation

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 15, 2025

⚡️ Editor Performance Report

Updated Mon, 07 Apr 2025 12:45:45 GMT

Benchmark reference
latency of sanity@latest
experiment
latency of this branch
Δ (%)
latency difference
article (title) 27.8 efps (36ms) 23.3 efps (43ms) +7ms (+19.4%)
article (body) 72.2 efps (14ms) 72.5 efps (14ms) -0ms (-/-%)
article (string inside object) 28.6 efps (35ms) 25.6 efps (39ms) +4ms (+11.4%)
article (string inside array) 25.3 efps (40ms) 22.2 efps (45ms) +6ms (+13.9%)
recipe (name) 50.0 efps (20ms) 47.6 efps (21ms) +1ms (+5.0%)
recipe (description) 52.6 efps (19ms) 55.6 efps (18ms) -1ms (-5.3%)
recipe (instructions) 99.9+ efps (5ms) 99.9+ efps (5ms) +0ms (-/-%)
synthetic (title) 18.2 efps (55ms) 18.5 efps (54ms) -1ms (-1.8%)
synthetic (string inside object) 17.7 efps (57ms) 17.2 efps (58ms) +2ms (+2.7%)

efps — editor "frames per second". The number of updates assumed to be possible within a second.

Derived from input latency. efps = 1000 / input_latency

Detailed information

🏠 Reference result

The performance result of sanity@latest

Benchmark latency p75 p90 p99 blocking time test duration
article (title) 36ms 42ms 46ms 171ms 306ms 9.6s
article (body) 14ms 16ms 18ms 73ms 45ms 4.9s
article (string inside object) 35ms 37ms 41ms 304ms 123ms 6.8s
article (string inside array) 40ms 42ms 45ms 131ms 13ms 6.7s
recipe (name) 20ms 22ms 25ms 46ms 0ms 7.2s
recipe (description) 19ms 20ms 22ms 48ms 0ms 4.8s
recipe (instructions) 5ms 8ms 13ms 37ms 0ms 3.1s
synthetic (title) 55ms 60ms 66ms 199ms 907ms 14.8s
synthetic (string inside object) 57ms 58ms 62ms 84ms 1019ms 8.6s

🧪 Experiment result

The performance result of this branch

Benchmark latency p75 p90 p99 blocking time test duration
article (title) 43ms 46ms 53ms 170ms 268ms 11.7s
article (body) 14ms 15ms 17ms 197ms 182ms 5.2s
article (string inside object) 39ms 40ms 42ms 50ms 11ms 6.9s
article (string inside array) 45ms 49ms 56ms 295ms 432ms 7.7s
recipe (name) 21ms 22ms 23ms 39ms 0ms 6.9s
recipe (description) 18ms 19ms 20ms 23ms 0ms 4.6s
recipe (instructions) 5ms 7ms 8ms 16ms 0ms 3.1s
synthetic (title) 54ms 57ms 59ms 62ms 690ms 15.5s
synthetic (string inside object) 58ms 59ms 72ms 124ms 931ms 8.2s

📚 Glossary

column definitions

  • benchmark — the name of the test, e.g. "article", followed by the label of the field being measured, e.g. "(title)".
  • latency — the time between when a key was pressed and when it was rendered. derived from a set of samples. the median (p50) is shown to show the most common latency.
  • p75 — the 75th percentile of the input latency in the test run. 75% of the sampled inputs in this benchmark were processed faster than this value. this provides insight into the upper range of typical performance.
  • p90 — the 90th percentile of the input latency in the test run. 90% of the sampled inputs were faster than this. this metric helps identify slower interactions that occurred less frequently during the benchmark.
  • p99 — the 99th percentile of the input latency in the test run. only 1% of sampled inputs were slower than this. this represents the worst-case scenarios encountered during the benchmark, useful for identifying potential performance outliers.
  • blocking time — the total time during which the main thread was blocked, preventing user input and UI updates. this metric helps identify performance bottlenecks that may cause the interface to feel unresponsive.
  • test duration — how long the test run took to complete.

@sgulseth sgulseth force-pushed the fix/typegen/lookup-inline-map branch from a70e591 to 9dec78e Compare March 15, 2025 15:07
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 15, 2025

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 43.26% 56428 / 130422
🔵 Statements 43.26% 56428 / 130422
🔵 Functions 47.38% 2795 / 5899
🔵 Branches 79.63% 10499 / 13184
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/@sanity/codegen/src/typescript/typeGenerator.ts 94.57% 87.69% 100% 94.57% 62-63, 134-135, 205-206, 211-212, 242, 299-300, 342, 348-349
Generated in workflow #33418 for commit 77c7346 by the Vitest Coverage Report Action

@sgulseth sgulseth force-pushed the fix/typegen/lookup-inline-map branch from 9dec78e to 14f29b4 Compare March 15, 2025 21:59
@sgulseth sgulseth force-pushed the fix/typegen/lookup-inline-map branch from 14f29b4 to 57c7bb7 Compare March 15, 2025 22:25
@sgulseth sgulseth force-pushed the fix/typegen/lookup-inline-map branch 2 times, most recently from 748c20d to c346b1c Compare March 15, 2025 22:38
@sgulseth sgulseth changed the title fix(typegen): Use typeMap to resolve all inline types Fix handling of duplicate type names Apr 4, 2025
@sgulseth sgulseth marked this pull request as ready for review April 4, 2025 18:45
@sgulseth sgulseth requested a review from a team as a code owner April 4, 2025 18:45
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 7, 2025

📊 Playwright Test Report

Download Full E2E Report

This report contains test results, including videos of failing tests.

@sgulseth sgulseth requested a review from stipsan April 8, 2025 07:45
@sgulseth
Copy link
Copy Markdown
Member Author

sgulseth commented Apr 8, 2025

Had to rebase so also had to re-request review @stipsan sorry about that

@sgulseth sgulseth merged commit 6abe1f9 into main Apr 8, 2025
61 checks passed
@sgulseth sgulseth deleted the fix/typegen/lookup-inline-map branch April 8, 2025 17:55
kbrabrand added a commit that referenced this pull request Nov 28, 2025
…ing (#10294)

The TypeGenerator class has been refactored. Logic specific to generating TypeScript types from the Sanity schema has been extracted into a new, focused SchemaTypeGenerator class. This serves as read-only unit that encapsulates the collection of schema types and pre-computes identifiers and inline types (preserve the behavior of fix(typegen): handle duplicate type names #8950)

Memoization: To prevent re-running costly operations when inputs haven't changed (a common scenario in watch mode), memoization has been implemented for expensive computations. This uses reselect's createSelector, a custom computeOnce helper, and a weakMapMemo helper for the evaluateQuery method. Note: There is no watch mode yet. This is in preparation.

Improved CLI Reporting: The typegen generate command now includes a percentage of completion. This is facilitated by @sanity/worker-channels.

Co-authored-by: Kristoffer Brabrand <kristoffer@brabrand.no>
kbrabrand added a commit that referenced this pull request Dec 3, 2025
…ing (#10294)

The TypeGenerator class has been refactored. Logic specific to generating TypeScript types from the Sanity schema has been extracted into a new, focused SchemaTypeGenerator class. This serves as read-only unit that encapsulates the collection of schema types and pre-computes identifiers and inline types (preserve the behavior of fix(typegen): handle duplicate type names #8950)

Memoization: To prevent re-running costly operations when inputs haven't changed (a common scenario in watch mode), memoization has been implemented for expensive computations. This uses reselect's createSelector, a custom computeOnce helper, and a weakMapMemo helper for the evaluateQuery method. Note: There is no watch mode yet. This is in preparation.

Improved CLI Reporting: The typegen generate command now includes a percentage of completion. This is facilitated by @sanity/worker-channels.

Co-authored-by: Kristoffer Brabrand <kristoffer@brabrand.no>
kbrabrand added a commit that referenced this pull request Dec 3, 2025
…ing (#10294)

The TypeGenerator class has been refactored. Logic specific to generating TypeScript types from the Sanity schema has been extracted into a new, focused SchemaTypeGenerator class. This serves as read-only unit that encapsulates the collection of schema types and pre-computes identifiers and inline types (preserve the behavior of fix(typegen): handle duplicate type names #8950)

Memoization: To prevent re-running costly operations when inputs haven't changed (a common scenario in watch mode), memoization has been implemented for expensive computations. This uses reselect's createSelector, a custom computeOnce helper, and a weakMapMemo helper for the evaluateQuery method. Note: There is no watch mode yet. This is in preparation.

Improved CLI Reporting: The typegen generate command now includes a percentage of completion. This is facilitated by @sanity/worker-channels.

Co-authored-by: Kristoffer Brabrand <kristoffer@brabrand.no>
kbrabrand added a commit that referenced this pull request Dec 5, 2025
…ing (#10294)

The TypeGenerator class has been refactored. Logic specific to generating TypeScript types from the Sanity schema has been extracted into a new, focused SchemaTypeGenerator class. This serves as read-only unit that encapsulates the collection of schema types and pre-computes identifiers and inline types (preserve the behavior of fix(typegen): handle duplicate type names #8950)

Memoization: To prevent re-running costly operations when inputs haven't changed (a common scenario in watch mode), memoization has been implemented for expensive computations. This uses reselect's createSelector, a custom computeOnce helper, and a weakMapMemo helper for the evaluateQuery method. Note: There is no watch mode yet. This is in preparation.

Improved CLI Reporting: The typegen generate command now includes a percentage of completion. This is facilitated by @sanity/worker-channels.

Co-authored-by: Kristoffer Brabrand <kristoffer@brabrand.no>
bjoerge pushed a commit that referenced this pull request Dec 9, 2025
…ing (#10294)

The TypeGenerator class has been refactored. Logic specific to generating TypeScript types from the Sanity schema has been extracted into a new, focused SchemaTypeGenerator class. This serves as read-only unit that encapsulates the collection of schema types and pre-computes identifiers and inline types (preserve the behavior of fix(typegen): handle duplicate type names #8950)

Memoization: To prevent re-running costly operations when inputs haven't changed (a common scenario in watch mode), memoization has been implemented for expensive computations. This uses reselect's createSelector, a custom computeOnce helper, and a weakMapMemo helper for the evaluateQuery method. Note: There is no watch mode yet. This is in preparation.

Improved CLI Reporting: The typegen generate command now includes a percentage of completion. This is facilitated by @sanity/worker-channels.

Co-authored-by: Kristoffer Brabrand <kristoffer@brabrand.no>
bjoerge pushed a commit that referenced this pull request Dec 10, 2025
…ing (#10294)

The TypeGenerator class has been refactored. Logic specific to generating TypeScript types from the Sanity schema has been extracted into a new, focused SchemaTypeGenerator class. This serves as read-only unit that encapsulates the collection of schema types and pre-computes identifiers and inline types (preserve the behavior of fix(typegen): handle duplicate type names #8950)

Memoization: To prevent re-running costly operations when inputs haven't changed (a common scenario in watch mode), memoization has been implemented for expensive computations. This uses reselect's createSelector, a custom computeOnce helper, and a weakMapMemo helper for the evaluateQuery method. Note: There is no watch mode yet. This is in preparation.

Improved CLI Reporting: The typegen generate command now includes a percentage of completion. This is facilitated by @sanity/worker-channels.

Co-authored-by: Kristoffer Brabrand <kristoffer@brabrand.no>
bjoerge pushed a commit that referenced this pull request Dec 12, 2025
…ing (#10294)

The TypeGenerator class has been refactored. Logic specific to generating TypeScript types from the Sanity schema has been extracted into a new, focused SchemaTypeGenerator class. This serves as read-only unit that encapsulates the collection of schema types and pre-computes identifiers and inline types (preserve the behavior of fix(typegen): handle duplicate type names #8950)

Memoization: To prevent re-running costly operations when inputs haven't changed (a common scenario in watch mode), memoization has been implemented for expensive computations. This uses reselect's createSelector, a custom computeOnce helper, and a weakMapMemo helper for the evaluateQuery method. Note: There is no watch mode yet. This is in preparation.

Improved CLI Reporting: The typegen generate command now includes a percentage of completion. This is facilitated by @sanity/worker-channels.

Co-authored-by: Kristoffer Brabrand <kristoffer@brabrand.no>
bjoerge pushed a commit that referenced this pull request Dec 15, 2025
…ing (#10294)

The TypeGenerator class has been refactored. Logic specific to generating TypeScript types from the Sanity schema has been extracted into a new, focused SchemaTypeGenerator class. This serves as read-only unit that encapsulates the collection of schema types and pre-computes identifiers and inline types (preserve the behavior of fix(typegen): handle duplicate type names #8950)

Memoization: To prevent re-running costly operations when inputs haven't changed (a common scenario in watch mode), memoization has been implemented for expensive computations. This uses reselect's createSelector, a custom computeOnce helper, and a weakMapMemo helper for the evaluateQuery method. Note: There is no watch mode yet. This is in preparation.

Improved CLI Reporting: The typegen generate command now includes a percentage of completion. This is facilitated by @sanity/worker-channels.

Co-authored-by: Kristoffer Brabrand <kristoffer@brabrand.no>
bjoerge pushed a commit that referenced this pull request Dec 15, 2025
…ing (#10294)

The TypeGenerator class has been refactored. Logic specific to generating TypeScript types from the Sanity schema has been extracted into a new, focused SchemaTypeGenerator class. This serves as read-only unit that encapsulates the collection of schema types and pre-computes identifiers and inline types (preserve the behavior of fix(typegen): handle duplicate type names #8950)

Memoization: To prevent re-running costly operations when inputs haven't changed (a common scenario in watch mode), memoization has been implemented for expensive computations. This uses reselect's createSelector, a custom computeOnce helper, and a weakMapMemo helper for the evaluateQuery method. Note: There is no watch mode yet. This is in preparation.

Improved CLI Reporting: The typegen generate command now includes a percentage of completion. This is facilitated by @sanity/worker-channels.

Co-authored-by: Kristoffer Brabrand <kristoffer@brabrand.no>
bjoerge pushed a commit that referenced this pull request Dec 15, 2025
…ing (#10294)

The TypeGenerator class has been refactored. Logic specific to generating TypeScript types from the Sanity schema has been extracted into a new, focused SchemaTypeGenerator class. This serves as read-only unit that encapsulates the collection of schema types and pre-computes identifiers and inline types (preserve the behavior of fix(typegen): handle duplicate type names #8950)

Memoization: To prevent re-running costly operations when inputs haven't changed (a common scenario in watch mode), memoization has been implemented for expensive computations. This uses reselect's createSelector, a custom computeOnce helper, and a weakMapMemo helper for the evaluateQuery method. Note: There is no watch mode yet. This is in preparation.

Improved CLI Reporting: The typegen generate command now includes a percentage of completion. This is facilitated by @sanity/worker-channels.

Co-authored-by: Kristoffer Brabrand <kristoffer@brabrand.no>
kbrabrand added a commit that referenced this pull request Dec 16, 2025
…ing (#10294)

The TypeGenerator class has been refactored. Logic specific to generating TypeScript types from the Sanity schema has been extracted into a new, focused SchemaTypeGenerator class. This serves as read-only unit that encapsulates the collection of schema types and pre-computes identifiers and inline types (preserve the behavior of fix(typegen): handle duplicate type names #8950)

Memoization: To prevent re-running costly operations when inputs haven't changed (a common scenario in watch mode), memoization has been implemented for expensive computations. This uses reselect's createSelector, a custom computeOnce helper, and a weakMapMemo helper for the evaluateQuery method. Note: There is no watch mode yet. This is in preparation.

Improved CLI Reporting: The typegen generate command now includes a percentage of completion. This is facilitated by @sanity/worker-channels.

Co-authored-by: Kristoffer Brabrand <kristoffer@brabrand.no>
kbrabrand added a commit that referenced this pull request Dec 16, 2025
…ing (#10294)

The TypeGenerator class has been refactored. Logic specific to generating TypeScript types from the Sanity schema has been extracted into a new, focused SchemaTypeGenerator class. This serves as read-only unit that encapsulates the collection of schema types and pre-computes identifiers and inline types (preserve the behavior of fix(typegen): handle duplicate type names #8950)

Memoization: To prevent re-running costly operations when inputs haven't changed (a common scenario in watch mode), memoization has been implemented for expensive computations. This uses reselect's createSelector, a custom computeOnce helper, and a weakMapMemo helper for the evaluateQuery method. Note: There is no watch mode yet. This is in preparation.

Improved CLI Reporting: The typegen generate command now includes a percentage of completion. This is facilitated by @sanity/worker-channels.

Co-authored-by: Kristoffer Brabrand <kristoffer@brabrand.no>
kbrabrand added a commit that referenced this pull request Dec 16, 2025
…ing (#10294)

The TypeGenerator class has been refactored. Logic specific to generating TypeScript types from the Sanity schema has been extracted into a new, focused SchemaTypeGenerator class. This serves as read-only unit that encapsulates the collection of schema types and pre-computes identifiers and inline types (preserve the behavior of fix(typegen): handle duplicate type names #8950)

Memoization: To prevent re-running costly operations when inputs haven't changed (a common scenario in watch mode), memoization has been implemented for expensive computations. This uses reselect's createSelector, a custom computeOnce helper, and a weakMapMemo helper for the evaluateQuery method. Note: There is no watch mode yet. This is in preparation.

Improved CLI Reporting: The typegen generate command now includes a percentage of completion. This is facilitated by @sanity/worker-channels.

Co-authored-by: Kristoffer Brabrand <kristoffer@brabrand.no>
bjoerge pushed a commit that referenced this pull request Dec 16, 2025
…ing (#10294)

The TypeGenerator class has been refactored. Logic specific to generating TypeScript types from the Sanity schema has been extracted into a new, focused SchemaTypeGenerator class. This serves as read-only unit that encapsulates the collection of schema types and pre-computes identifiers and inline types (preserve the behavior of fix(typegen): handle duplicate type names #8950)

Memoization: To prevent re-running costly operations when inputs haven't changed (a common scenario in watch mode), memoization has been implemented for expensive computations. This uses reselect's createSelector, a custom computeOnce helper, and a weakMapMemo helper for the evaluateQuery method. Note: There is no watch mode yet. This is in preparation.

Improved CLI Reporting: The typegen generate command now includes a percentage of completion. This is facilitated by @sanity/worker-channels.

Co-authored-by: Kristoffer Brabrand <kristoffer@brabrand.no>
bjoerge pushed a commit that referenced this pull request Dec 16, 2025
…ing (#10294)

The TypeGenerator class has been refactored. Logic specific to generating TypeScript types from the Sanity schema has been extracted into a new, focused SchemaTypeGenerator class. This serves as read-only unit that encapsulates the collection of schema types and pre-computes identifiers and inline types (preserve the behavior of fix(typegen): handle duplicate type names #8950)

Memoization: To prevent re-running costly operations when inputs haven't changed (a common scenario in watch mode), memoization has been implemented for expensive computations. This uses reselect's createSelector, a custom computeOnce helper, and a weakMapMemo helper for the evaluateQuery method. Note: There is no watch mode yet. This is in preparation.

Improved CLI Reporting: The typegen generate command now includes a percentage of completion. This is facilitated by @sanity/worker-channels.

Co-authored-by: Kristoffer Brabrand <kristoffer@brabrand.no>
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