Skip to content
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

Merged
merged 56 commits into from Mar 11, 2024
Merged

Data Strategy Configuration #11098

merged 56 commits into from Mar 11, 2024

Conversation

jacob-ebey
Copy link
Member

@jacob-ebey jacob-ebey commented Dec 6, 2023

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:

  • Docs (coming in subsequent PR)
  • Update decision doc with latest
  • Tests for unstable_skipActionErrroRevalidation

Copy link

changeset-bot bot commented Dec 6, 2023

🦋 Changeset detected

Latest commit: 2a8dc42

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@remix-run/router Minor
react-router Patch
react-router-dom Patch
react-router-dom-v5-compat Patch
react-router-native Patch

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

@jacob-ebey jacob-ebey changed the base branch from main to dev December 6, 2023 20:09
Comment on lines 3813 to 3817
let shouldSkipRevalidation =
skipActionErrorRevalidation &&
pendingActionResult &&
typeof pendingActionResult[1].statusCode === "number" &&
pendingActionResult[1].statusCode >= 400;
Copy link
Contributor

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

};

let handlerPromise = handlerOverride
? handlerOverride(async (ctx: unknown) => runHandlerForReal(ctx))
Copy link
Contributor

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)) {
Copy link
Contributor

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

Comment on lines 1616 to 1622
/**
* 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 {
Copy link
Contributor

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.

Copy link
Contributor

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

@brophdawg11 brophdawg11 marked this pull request as ready for review February 16, 2024 21:34
Co-authored-by: Jason Pickens <jasonpickensnz@gmail.com>
@brophdawg11 brophdawg11 merged commit c7dd3d3 into dev Mar 11, 2024
3 checks passed
@brophdawg11 brophdawg11 deleted the data_strategy branch March 11, 2024 19:01
Copy link
Contributor

🤖 Hello there,

We just published version 6.23.0-pre.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

Copy link
Contributor

🤖 Hello there,

We just published version 6.23.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants