Skip to content

Conversation

judofyr
Copy link
Contributor

@judofyr judofyr commented Sep 22, 2025

Description

applyDocumentActions was the only function in the core package which interpreted the SanityInstance as a tree, automatically traversing the tree to find a matching instance. This is inconsistent with the other stores (e.g. query store) which assumes that it's being called with the right instance.

In addition, this changes applyDocumentActions to only accept actions as an array (so we don't have to check if it's an array or not) and also it places the actions as part of option. This is consistent with e.g. getQueryState which has a required query field in its options. This now means that all functions which are wrapped in bindActionByDataset are now consistently getting passed an object as their first argument. This is going to be key so that we later can modify this function to consider the options (instead of the instance).

There should be no breaking changes in the React package.

What to review

Testing

Fun gif

Copy link

vercel bot commented Sep 22, 2025

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

Project Deployment Preview Comments Updated (UTC)
sdk-docs Ready Ready Preview Comment Sep 25, 2025 10:38am
sdk-kitchensink-react Ready Ready Preview Comment Sep 25, 2025 10:38am

{state}: StoreContext<DocumentStoreState>,
{actions, transactionId = crypto.randomUUID(), disableBatching}: ApplyDocumentActionsOptions,
): Promise<ActionsResult> {
const actions = Array.isArray(actionOrActions) ? actionOrActions : [actionOrActions]
Copy link
Member

@ryanbonial ryanbonial Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like moving these checks to the React package, useApplyDocumentActions, would allow developers using the core package directly to pass invalid actions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don’t actually validate the actions in core, though? If you’re using core methods you must pass data which matches the TypeScript definition or bad things happen.

I’ve just dropped support for having either an array or an object in core, but I don’t think there’s much difference from that.

`applyDocumentActions` was the only function in the `core` package which
interpreted the `SanityInstance` as a tree, automatically traversing the
tree to find a matching instance. This is inconsistent with the other
stores (e.g. query store) which assumes that it's being called with the
right instance.

In addition, this changes `applyDocumentActions` to only accept actions
as an array (so we don't have to check if it's an array or not) and also
it places the `actions` as part of option. This is consistent with e.g.
`getQueryState` which has a required `query` field in its options.
This now means that all functions which are wrapped in
`bindActionByDataset` are now consistently getting passed an object as
their first argument. This is going to be key so that we later can
modify this function to consider the options (instead of the instance).

There should be no breaking changes in the React package.
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