0
Fork 0
mirror of https://github.com/TanStack/query.git synced 2026-11-16 22:50:20 +00:00
query/docs/framework/react
Dominik Dorfmeister 24f1d45cbd
feat: scoped mutations (#7312)
* refactor: add scope to mutationCache internally

* refactor: remove unused defaultOptions on mutation

this private field is a leftover from v4

* feat: make sure to not run mutations if there is already one running in the scope of this mutation

* feat: make sure mutations in the same scope can run in serial

* fix: find a _lot_ better way to determine if a mutation can run

* test: widen test scenario to include scopes

* fix: there is a difference between starting and continuing

when starting, we need to check the networkMode differently than when continuing, because of how offlineFirst works (can start, but can't continue)

* refactor: switch to a scope object with `id`

* feat: dehydrate and hydrate mutation scope

* fix: initiate the mutationCache with a random number

since we use the mutationId to create the default scope, and the mutationId is merely incremented, we risk colliding scopes when hydrating mutations into an existing cache. That's because the mutationId itself is never dehydrated. When a mutation gets hydrated, it gets re-built, thus getting a new id. At this point, its id and the scope can differ. That per se isn't a problem. But if a mutation was dehydrated with scope:1, it would put into the same scope with another mutation from the new cache that might also have the scope:1.

To avoid that, we can initialize the mutationId with Date.now(). It will make sure (or at least very likely) that there is no collision

In the future, we should just be able to use `Crypto.randomUUID()` to generate a unique scope, but our promised compatibility doesn't allow for using this function

* test: hydration

* test: those tests actually fail because resumePausedMutations is still wrongly implemented

* fix: simplify and fix resumePausedMutations

we can fire off all mutations at the same time - only the first one in each scope will actually fire, the others have to stay paused until their time has come. mutation.continue handles this internally.

but, we get back all the retryer promises, so resumePausedMutations will wait until the whole chain is done

* test: more tests

* refactor: scopeFor doesn't use anything of the mutationCache class

* docs: scoped mutations
History 2024-04-22 08:39:11 +02:00
..
community docs: Re-organise for new docs layout (#6763) 2024-01-26 07:57:22 +11:00
guides feat: scoped mutations (#7312) 2024-04-22 08:39:11 +02:00
plugins docs: migrate docs to use path-based navigation instead of route-based (#7211) 2024-04-02 16:46:31 -06:00
reference feat: scoped mutations (#7312) 2024-04-22 08:39:11 +02:00
comparison.md docs: Re-organise for new docs layout (#6763) 2024-01-26 07:57:22 +11:00
devtools.md docs: Update spelling in devtools.md (#7269) 2024-04-15 10:59:05 +02:00
graphql.md docs: Re-organise for new docs layout (#6763) 2024-01-26 07:57:22 +11:00
installation.md docs: migrate docs to use path-based navigation instead of route-based (#7211) 2024-04-02 16:46:31 -06:00
overview.md docs: migrate docs to use path-based navigation instead of route-based (#7211) 2024-04-02 16:46:31 -06:00
quick-start.md docs: fix quickstart 2024-04-02 23:21:55 -06:00
react-native.md docs: Update react-native.md 2024-03-11 20:22:57 +01:00
typescript.md docs: migrate docs to use path-based navigation instead of route-based (#7211) 2024-04-02 16:46:31 -06:00
videos.md docs: Re-organise for new docs layout (#6763) 2024-01-26 07:57:22 +11:00