fix(mutate): scope optimisticData and populateCache per matched key - #4286
Open
spokodev wants to merge 1 commit into
Open
fix(mutate): scope optimisticData and populateCache per matched key#4286spokodev wants to merge 1 commit into
spokodev wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When global mutate is called with a key filter function, mutateByKey runs once
for every matched key through matchedKeys.map(mutateByKey). Two variables that
get reassigned during a mutation, optimisticData and populateCache, were declared
once in the outer internalMutate scope and shared across all those calls.
On the first matched key, a functional optimisticData is called and the shared
variable is overwritten with the resulting value. Every later matched key then
sees a non-function value and reuses the first key's optimistic data instead of
computing its own. A functional populateCache has the same problem for the
committed write. The result is that multiple cache entries show the wrong
optimistic value during a filtered mutation.
This moves both variables inside mutateByKey so each matched key gets its own
copy. Single-key mutations are unaffected. The mutator data transformer already
worked per key because it uses a fresh local variable; this brings optimisticData
and populateCache in line with that.
Added a test that seeds two keys with distinct committed values and fires one
filtered mutation with a functional optimisticData. Before the change the second
key rendered the first key's optimistic value; after it renders its own.