enhance(react): useFetch() returns UsablePromise thenable for React.use()#3755
Merged
enhance(react): useFetch() returns UsablePromise thenable for React.use()#3755
Conversation
|
You have run out of free Bugbot PR reviews for this billing cycle. This will reset on April 19. To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial. |
🦋 Changeset detectedLatest commit: 74d348d The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
|
Size Change: 0 B Total Size: 80.6 kB ℹ️ View Unchanged
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3755 +/- ##
=======================================
Coverage 98.04% 98.05%
=======================================
Files 151 151
Lines 2818 2821 +3
Branches 552 553 +1
=======================================
+ Hits 2763 2766 +3
Misses 11 11
Partials 44 44 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
e28ca69 to
e000d86
Compare
…se() useFetch() now returns a thenable with status/value/reason that works directly with React.use() — use(useFetch(endpoint, args)) behaves identically to useSuspense(endpoint, args): suspends when loading, returns denormalized data when cached, throws on errors, and re-suspends on invalidation. - Replace trackPromise/RESOLVED with createFulfilled/createRejected - Add GC tracking via countRef - Support parallel fetches (all useFetch() calls run before use() suspends) - Add comprehensive test suite (React 19+ only via describeIf19) - Update useFetch.md docs with use() patterns and parallel fetch examples Made-with: Cursor
e000d86 to
99eea3c
Compare
ab21e82 to
74d348d
Compare
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.
Motivation
Building on #3752,
useFetch()now returns a proper thenable that works directly withReact.use(). This makesuse(useFetch(endpoint, args))a drop-in equivalent touseSuspense(endpoint, args)— same suspend, resolve, error, and invalidation behavior — while also enabling parallel data fetching that avoids sequential waterfalls.Solution
trackPromise.ts: ReplaceFetchPromise/RESOLVED/trackPromise()withUsablePromise/createFulfilled()/createRejected()— thenables withstatus/value/reasonfields thatReact.use()reads synchronously.useFetch.ts/useFetch.native.ts: Return fulfilled thenables with denormalized data when cached, rejected thenables on errors, and pending promises when fetching. Add GC tracking viacountRef.useFetch-use.web.tsx): Comprehensive test suite cloned fromuseSuspense.web.tsxandintegration-endpoint.web.tsx, validating behavioral equivalence. Gated behinddescribeIf19to skip on React 18.useFetch.md): Updated withuse()usage, parallel fetch pattern, behavior table foruse(), andAsyncBoundaryexample.status,value,then) and denormalized data on fulfilled thenables.Made with Cursor