-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Data Strategy Configuration #11098
Data Strategy Configuration #11098
Conversation
🦋 Changeset detectedLatest commit: 2a8dc42 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 |
chore: remove example for now for smaller PR rename to
packages/router/router.ts
Outdated
let shouldSkipRevalidation = | ||
skipActionErrorRevalidation && | ||
pendingActionResult && | ||
typeof pendingActionResult[1].statusCode === "number" && | ||
pendingActionResult[1].statusCode >= 400; |
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.
Don't revalidate if unstable_skipActionErrorrRevalidation
is enabled and the action result is a 4xx/5xx response
packages/router/router.ts
Outdated
}; | ||
|
||
let handlerPromise = handlerOverride | ||
? handlerOverride(async (ctx: unknown) => runHandlerForReal(ctx)) |
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.
If the user gave us a handlerOverride
then we call that with a function letting them proxy a second argument into the loader/action:
async function dataStrategy({ matches }) {
let middlewareCtx = await runMiddlewares(matches);
return Promise.all(matches.map(m => m.resolve(handler => handler(middlewareCtx))));
}
Then in your route loader:
function loader({ request }, middlewareCtx) {
// use your middleware context here
}
} finally { | ||
if (onReject) { | ||
request.signal.removeEventListener("abort", onReject); | ||
} | ||
} | ||
|
||
if (isResponse(result)) { |
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.
Redirect post-processing lives in the callDataStratgy
or startRedirectNavigation
methods now
packages/router/utils.ts
Outdated
/** | ||
* Utility class we use to hold unwrapped Responses while preserving status | ||
* codes and headers. This is most useful for dataStrategy implementations | ||
* where implementors want to use a custom decoding mechanism and return | ||
* pre-decoded data while also preserving response meta information | ||
*/ | ||
export class DecodedResponse { |
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.
New public API - very similar to ErrorResponse
but this is intended for user-land usage in dataStrategy
if they need to pre-decode a response - but this then allows us to carry the statusCode and headers along throughout the rest of the data flows.
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 was removed in favor of a status
on HandlerResult
Co-authored-by: Jason Pickens <jasonpickensnz@gmail.com>
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
Exposing a configuration option to allow consumers to take low-level control over the strategy used to fetch data.
This is a low-level, power-user API - it is not intended to be a primary API for most RR apps. The current/default "fetch in parallel" approach should suffice for the vast majority of apps.
The primary consumer will be Remix's upcoming Single Fetch behavior, but this will be useful for other advanced/opinionated data-loading patterns for React Router apps (such as composing together GQL fragments from routes into a single API request).
Todo:
unstable_skipActionErrroRevalidation