Skip to content

Conversation

@judofyr
Copy link
Contributor

@judofyr judofyr commented Sep 16, 2025

Description

The following introduces a "source" concept that can be used to query different types of resources. The long-term vision here goes much broader:

  • SanityInstance should no longer be an inherited tree structure. This will rather be a single object which contains global information (e.g. token). There will be no re-use of any state across SanityInstance.
  • All hooks/functions which works on documents will also accept a source parameter. This is a single parameter (instead of the projectId/dataset tuple) that can easily be passed around. If you're making higher-order helpers you just need to accept a single source object.
  • There are top-level functions which constructs these source objects. In the future these objects will also contain type information. These should also be owned by @sanity/client. In this PR we're mapping it to the existing experimental resource API, but the intention is for @sanity/client to provide a proper source-based API which we're re-exporting/using here in SDK.
  • We'll introduce a new "default source" context as well. This is outside of the SanityInstance so that you can change it.
  • There will be no special support for placing multiple sources in the context. The user can always define their own context if they want to have access to multiple source objects. This gives them more flexibility in how to structure their applications.
  • If you have fully static data sources you can always hard-code them in single file: export const PRODUCTS = datasetSource(projectId, "datasets").

(This is based on #619)

What to review

Testing

Fun gif

The source

The following introduces a "source" concept that can be used to query
different types of resources. The long-term vision here is:

- `SanityInstance` should no longer be an inherited tree structure.
  This will rather be a single object which contains global information
  (e.g. token). There will be no re-use of any state across `SanityInstance`.
- All hooks/functions which works on documents will also accept a
  `source` parameter. This is a single parameter (instead of the
  `projectId`/`dataset`) tuple that can easily be passed around.
  If you're making higher-order helpers you just need to accept a
  single source object.
- There are top-level functions which constructs these `source` objects.
  In the future these objects will also contain type information.
  These should also be owned by `@sanity/client`. In this PR we're
  mapping it to the existing experimental resource API, but the
  intention is for `@sanity/client` to provide a proper source-based API
  which we're re-exporting/using here in SDK.
- We'll introduce a new "default source" context as well. This is
  _outside_ of the `SanityInstance` so that you can change it.
- There will be no special support for placing multiple sources in the
  context. The user can always define their own context if they want to
  have access to multiple `source` objects. This gives them more
  flexibility in how to structure their applications.
- If you have fully static data sources you can always hard-code them in
  single file: `export const PRODUCTS = datasetSource(projectId, "datasets")`.
@judofyr judofyr self-assigned this Sep 16, 2025
@judofyr judofyr requested a review from a team as a code owner September 16, 2025 11:28
@judofyr judofyr requested a review from colepeters September 16, 2025 11:28
@vercel
Copy link

vercel bot commented Sep 16, 2025

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

Project Deployment Preview Updated (UTC)
sdk-kitchensink-react Ready Ready Preview Sep 16, 2025 11:28am

@judofyr judofyr changed the title Introduce "source" concept feat: Introduce "source" concept Sep 16, 2025
@ryanbonial ryanbonial self-requested a review September 16, 2025 15:38
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