fix(use-swrv): compare serialized keys during revalidation#428
fix(use-swrv): compare serialized keys during revalidation#428officialasishkumar wants to merge 2 commits into
Conversation
Compare cache keys through the cache serializer when applying mutations so computed array keys and other structurally equivalent keys update their refs. Also avoid clearing validation/loading state when an older in-flight request resolves after a hook has moved to a different key. Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
👷 Deploy request for docs-swrv pending review.Visit the deploys page to approve it
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 604d7ac3c4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (!isSameSerializedKey(stateRef.key, keyVal, config.cache)) { | ||
| return | ||
| } |
There was a problem hiding this comment.
Clear loading when stale request resolves after key is unset
When a request is in flight and the watched key changes to a falsy value (e.g. null), the watcher skips revalidate() and only updates isValidating, so isLoading can remain true. This new early return skips the only remaining isLoading = false path for that in-flight request, leaving consumers stuck in a perpetual loading state once the old promise resolves. This regression is triggered specifically by key transitions from truthy to falsy during an active fetch.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 8660a69 by clearing isLoading when the watched key becomes falsy, with a regression test for the in-flight request case.
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
71c5d9e to
8660a69
Compare
Summary
Fixes #390.
Fixes #345.
Validation