Repository navigation
feat: select, structural sharing, throwOnError and useIsFetching - #151
Merged
Merged
Conversation
- cache.set merges new data with the previous entry using replaceEqualDeep, so deeply equal responses keep their data reference and unchanged branches are reused - new structuralSharing request option (default true) with a setStructuralSharing setter and sdk configuration - dispatcher emits onRunningRequestsChange(ByKey) whenever requests start or stop running Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hing - select option for useFetch, useCache, useSubmit and useListener - the hook rerenders only when the selected value changes, while the cache stays shared - selected data is structurally shared and equal state values keep their previous references - throwOnError option for useFetch passes settled errors to the closest Error Boundary - useIsFetching and useIsSubmitting hooks count the running requests with optional filters - useListener and useEmitter apply the documented dependencyTracking default (true) Closes #150 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…etching Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
🎉 This PR is included in version 9.3.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
Closes #150
What
selectoption foruseFetch,useCache,useSubmitanduseListener. It runs at the observer level: the hook re-renders only when the selected value changes, while the request and its cache stay shared between hooks.id), it is re-applied to the current data in the same render.dataandsetDatatake the selected type, which is inferred. Callbacks,submit()and the cache keep the full response.selectcannot be set in the Provider config (a distributive Omit keeps the bounce union intact).Structural sharing (TanStack-style)
cache.setmerges incoming data into the previous entry withreplaceEqualDeep. A deeply equal response keeps the samedatareference across every hook, and unchanged branches are reused. It is on by default and can be turned off per request with thestructuralSharingoption,setStructuralSharing()or the sdk config.deepCompareskipped the render but still swapped in the new object, so the next unrelated render handed out a fresh reference.throwOnErroronuseFetch(boolean | (error) => boolean) throws settled errors to the Error Boundary. It doesn't throw for errors on attempts that will be retried, canceled requests, or offline re-queued ones. Suspense mode is supported too.useIsFetching(client, filters?)/useIsSubmitting(client, filters?)count running requests, filtered byqueryKey(string or RegExp) or apredicate. They are backed by the new dispatcher eventsonRunningRequestsChange/onRunningRequestsChangeByKey. All running-request mutations now go through a single setter.Behaviour changes to note
useListener/useEmitternow apply the documented defaultdependencyTracking: true. Before, the default was never applied, so they re-rendered on everytimestamp/extrachange, which would have defeatedselect.deepCompare: false, values that are identical byObject.isno longer trigger a re-render.select,useListenerstill updatesdataon every message, because messages are events.Tests
replaceEqualDeepunits, cache sharing (identical / partial / update / opt-out), request setter round-trip, dispatcher running events (add/finish/cancel/clear/no-op)use-fetch.refresh.spec(fixed sleeps →waitFor), seen failing once under full-suite load🤖 Generated with Claude Code