feat: introduce reading resources in app template#255
feat: introduce reading resources in app template#255cngonzalez wants to merge 13 commits intomainfrom
Conversation
|
Claude finished @ryanbonial's task in 1m 48s —— View job Review
The regex import {
SanityApp,
useSomething,
} from '@sanity/sdk-react'Fix: add the
When
If |
Coverage Delta
Comparing 13 changed files against main @ Overall Coverage
|
|
@cngonzalez what's the status of this? Could this be converted to draft if not ready? |
The CLI now uses renderSanityApp from @sanity/sdk-react in the auto-generated app.js entry module, instead of relying on the user's App.tsx to contain a SanityApp context provider. Named resources (project/dataset pairs) are read from sanity.cli.ts and passed to renderSanityApp at build/dev time. Renames the CLI config property sources → resources (and AppSource → AppResource) to align with SDK v3 terminology. Also exports findAppConfigPath from @sanity/cli-core for use in the build pipeline. Made-with: Cursor
Adds static analysis to detect when a user's App.tsx still uses the legacy <SanityApp> component pattern from @sanity/sdk-react v2. If detected, the CLI emits a deprecation warning with migration instructions during build and dev. The output object is threaded through the build and dev server call chains (buildApp, buildStudio, buildStaticFiles, devServer, startAppDevServer, startStudioDevServer) so the warning uses the CLI's standard output.warn() mechanism rather than console.warn. Made-with: Cursor
App templates no longer wrap their root component with <SanityApp>. The CLI's generated entry module now handles this via renderSanityApp, so user code stays clean and framework-agnostic. Made-with: Cursor
7b4cda9 to
f304343
Compare
- Upgrade @sanity/sdk-react to ^3.0.0-rc.0 - Rename sources → resources in sanity.cli.ts - Remove stale SanityApp import from App.tsx - Set organizationId to match dev.test.ts expectation - Ignore test fixture files from knip Made-with: Cursor
f304343 to
d423392
Compare
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
| // change these to 'latest' as in studioDependencies.ts once SDK v3 is released | ||
| '@sanity/sdk': '^2', | ||
| '@sanity/sdk-react': '^2', | ||
| // TODO: change these to 'latest' once SDK v3 is published |
There was a problem hiding this comment.
Don't merge this PR until SDK v3 is officially out and we change all of the 3.0.0-rc.0 references in this PR
cngonzalez
left a comment
There was a problem hiding this comment.
Mostly looks good! I had a couple of comments / architectural questions I'd like to hash out.
| * A named canvas resource that the app will access. | ||
| * @public | ||
| */ | ||
| export interface AppCanvasResource { |
There was a problem hiding this comment.
I'm on the fence about whether we should accept these as resources at the start, when we roll out this feature. We got a request in the v3 doc KJ shared with us to infer these from the org, and there's a PR for it here: sanity-io/sdk#779
I also think that it should be opt-in behavior, which is a larger architectural issue to discuss later in this review since I'm not sure how this param would be passed down.
| reactStrictMode: %REACT_STRICT_MODE% | ||
| } | ||
|
|
||
| renderSanityApp( |
There was a problem hiding this comment.
This is a larger issue than this repo, but I'm realizing that we haven't provided a way for users to add any other configuration parameters.
Right now that's just auth (for example, setting a different API host) and possibly the new orgId inference parameter (we could pass it here, but I'd like it to be opt-in to prevent surprises) so I do feel there might be some merit to another layer /context provider that separates resource configuration and other configuration.
I'm not sure what the best path is, but I'm concerned we may be limiting ourselves down the line.
| app: { | ||
| organizationId: '%organizationId%', | ||
| entry: '%entry%', | ||
| resources: { |
There was a problem hiding this comment.
We now have a couple of implementations of this, and I worry that this will cause a race condition / merge conflict when we release v3. I suggest we create a stack with just the new CLI config type changes and config template as the base, and merge our PRs into it when the time comes).
📦 Bundle Stats —
|
| Metric | Value | vs main (7b98e0b) |
|---|---|---|
| Internal (raw) | 2.1 KB | - |
| Internal (gzip) | 799 B | - |
| Bundled (raw) | 10.95 MB | +8.9 KB, +0.1% |
| Bundled (gzip) | 2.05 MB | +1.6 KB, +0.1% |
| Import time | 843ms | +4ms, +0.5% |
bin:sanity
| Metric | Value | vs main (7b98e0b) |
|---|---|---|
| Internal (raw) | 975 B | - |
| Internal (gzip) | 460 B | - |
| Bundled (raw) | 9.84 MB | - |
| Bundled (gzip) | 1.77 MB | - |
| Import time | 1.96s | -3ms, -0.1% |
🗺️ 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 (7b98e0be)
| Metric | Value | vs main (7b98e0b) |
|---|---|---|
| Internal (raw) | 92.7 KB | +399 B, +0.4% |
| Internal (gzip) | 21.7 KB | +62 B, +0.3% |
| Bundled (raw) | 21.60 MB | +353 B, +0.0% |
| Bundled (gzip) | 3.43 MB | +18 B, +0.0% |
| Import time | 785ms | -2ms, -0.3% |
🗺️ 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 (7b98e0be)
| Metric | Value | vs main (7b98e0b) |
|---|---|---|
| Internal (raw) | 976 B | - |
| Internal (gzip) | 507 B | - |
| Bundled (raw) | 50.7 KB | - |
| Bundled (gzip) | 12.6 KB | - |
| 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.
Coverage Delta
Comparing 13 changed files against main @ Overall Coverage
|
Description
This PR adds support for configuring data sources in Sanity apps. It introduces a new
sourcesproperty in the CLI config that allows apps to specify project IDs and datasets they need to access. The runtime now automatically passes these sources to the app, eliminating the need for manual configuration in the App component.What to review
sourcesschema in the CLI configrenderSanityAppTesting
The changes have been tested with the basic-app example, which now uses a real organization ID and project/dataset configuration. The example app has been updated to use the latest SDK packages from PR #704.