Skip to content

feat: use single sanity instance#828

Draft
cngonzalez wants to merge 2 commits intorefactor/sdk-1335/turn-project-dataset-pairs-into-resourcesfrom
feat/sdk-1330/use-single-sanity-instance
Draft

feat: use single sanity instance#828
cngonzalez wants to merge 2 commits intorefactor/sdk-1335/turn-project-dataset-pairs-into-resourcesfrom
feat/sdk-1330/use-single-sanity-instance

Conversation

@cngonzalez
Copy link
Copy Markdown
Member

@cngonzalez cngonzalez commented Apr 30, 2026

Description

Another v3 banger brought over to v2. For a while now, there's been no need to find instances by configuration. Every utility that requires a projectId and dataset can be bound to any instance, not just the instance that has a a specific configuration. This PR flattens this and shares a single instance across a SanityApp.

This could subtly be considered a breaking change in one way that I can think of. If a user wanted to get the configuration of where they're currently "at" in the component tree, they could do the following:

  1. call const instance = useSanityInstance()
  2. derive instance.config.projectId and instance.config.dataset

And then get the currently active projectId and dataset. Now that's not so reliable so we should ship a useResource to cover the gap.

What to review

Any other possibly breaking behavior?

Testing

Mostly tests were removed.

Fun gif

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sdk-docs Ready Ready Preview, Comment May 4, 2026 8:06pm
sdk-kitchensink-react Ready Ready Preview, Comment May 4, 2026 8:06pm

Request Review

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 30, 2026

📦 Bundle Stats — @sanity/sdk

Compared against refactor/sdk-1335/turn-project-dataset-pairs-into-resources (343c2282) · v2.10.0 (npm)

@sanity/sdk

Metric Value vs refactor/sdk-1335/turn-project-dataset-pairs-into-resources (343c228) vs v2.10.0
Internal (raw) 195.5 KB - -2.0 KB, -1.0%
Internal (gzip) 43.5 KB - -312 B, -0.7%
Bundled (raw) 1.12 MB - -9.5 KB, -0.8%
Bundled (gzip) 259.6 KB - -1.9 KB, -0.7%
Import time 208ms +1ms, +0.4% +10ms, +5.3%

@sanity/sdk/_internal

Metric Value vs refactor/sdk-1335/turn-project-dataset-pairs-into-resources (343c228) vs v2.10.0
Internal (raw) 70.5 KB -389 B, -0.5% -913 B, -1.2%
Internal (gzip) 16.5 KB -77 B, -0.5% -239 B, -1.4%
Bundled (raw) 504.9 KB -389 B, -0.1% +267 B, +0.1%
Bundled (gzip) 121.3 KB -85 B, -0.1% +91 B, +0.1%
Import time 131ms +2ms, +1.5% +9ms, +7.0%

🗺️ . · ./_internal · 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/sdk-react

Compared against refactor/sdk-1335/turn-project-dataset-pairs-into-resources (343c2282) · v2.10.0 (npm)

Metric Value vs refactor/sdk-1335/turn-project-dataset-pairs-into-resources (343c228) vs v2.10.0
Internal (raw) 80.4 KB -464 B, -0.6% +2.5 KB, +3.3%
Internal (gzip) 19.0 KB -133 B, -0.7% +576 B, +3.0%
Bundled (raw) 1.24 MB -865 B, -0.1% -7.3 KB, -0.6%
Bundled (gzip) 289.8 KB -228 B, -0.1% -1.5 KB, -0.5%
Import time 241ms -0ms, -0.1% +13ms, +5.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.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 30, 2026

Coverage Report

Status Category Percentage Covered / Total
🟢 Lines 94.72% (🎯 94%) 3595 / 3795
🟢 Statements 93.38% (🎯 93%) 3895 / 4171
🟢 Functions 94.03% (🎯 94%) 1009 / 1073
🟢 Branches 86.57% (🎯 86%) 2166 / 2502
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/core/src/config/sanityConfig.ts 50% 100% 50% 50% 237-253
packages/core/src/store/createSanityInstance.ts 97.22% 100% 90.9% 97.05% 131
packages/core/src/telemetry/initTelemetry.ts 86.36% 80% 78.57% 88.23% 74, 82-85, 99, 145-146, 168, 172-174
packages/react/src/components/SDKProvider.tsx 80% 46.15% 85.71% 77.77% 61-64, 82-86
packages/react/src/context/ResourceProvider.tsx 100% 92.85% 100% 100%
packages/react/src/hooks/context/useSanityInstance.ts 100% 100% 100% 100%
Generated in workflow #3624 for commit d0c1650 by the Vitest Coverage Report Action

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.

1 participant