-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor dataStrategy for easier RSC abstraction #13344
base: dev
Are you sure you want to change the base?
Conversation
|
122598c
to
12857fd
Compare
8f33065
to
573f1a1
Compare
a5c98a5
to
5047f3f
Compare
}; | ||
export type SingleFetchResults = | ||
| { [key: string]: SingleFetchResult } | ||
| { [SingleFetchRedirectSymbol]: SingleFetchRedirectResult }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now correctly represented as a union - we only ever return data or a redirect from the server - not both
// Shared/serializable type used by both turbo-stream and RSC implementations | ||
type DecodedSingleFetchResults = | ||
| { routes: { [key: string]: SingleFetchResult } } | ||
| { redirect: SingleFetchRedirectResult }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fetchAndDecode
will now return this shape which can be the common payload for turbo-stream and RSC. unwrapSingleFetchResult
now operates on this so that implementation can be shared.
// treat those as "no data" instead of throwing an exception. | ||
// 304 is not included here because the browser should fill those responses | ||
// with the cached body content. | ||
export const NO_BODY_STATUS_CODES = new Set([100, 101, 204, 205]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lifted from below so we can export for consumption in server-runtime code
// Track which routes need a server load - in case we need to tack on a | ||
// `_routes` param | ||
// Track which routes need a server load for use in a `_routes` param | ||
let routesParams = new Set<string>(); | ||
|
||
// We only add `_routes` when one or more routes opts out of a load via | ||
// `shouldRevalidate` or `clientLoader` | ||
// Only add `_routes` when at least 1 route opts out via `shouldRevalidate`/`clientLoader` | ||
let foundOptOutRoute = false; | ||
|
||
// Deferreds for each route so we can be sure they've all loaded via | ||
// `match.resolve()`, and a singular promise that can tell us all routes | ||
// have been resolved | ||
// Deferreds per-route so we can be sure they've all loaded via `match.resolve()` | ||
let routeDfds = matches.map(() => createDeferred<void>()); | ||
let routesLoadedPromise = Promise.all(routeDfds.map((d) => d.promise)); | ||
|
||
// Deferred that we'll use for the call to the server that each match can | ||
// await and parse out it's specific result | ||
let singleFetchDfd = createDeferred<SingleFetchResults>(); | ||
// Deferred we'll use for the singleular call to the server | ||
let singleFetchDfd = createDeferred<DecodedSingleFetchResults>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went back to the single deferred approach since we can now avoid dual fetchAndDecode
/unwrap
DI needs by decoding to a shared shape in fetchAndDecode
- so mostly just comment updates leftover
No description provided.