Skip to content

Conversation

brophdawg11
Copy link
Contributor

No description provided.

Copy link

changeset-bot bot commented Aug 30, 2024

🦋 Changeset detected

Latest commit: 47d9a97

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 Patch
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

Comment on lines 18 to 30
function keyedResults(
matches: DataStrategyMatch[],
results: HandlerResult[]
) {
return results.reduce(
(acc, r, i) =>
Object.assign(
acc,
matches[i].shouldLoad ? { [matches[i].route.id]: r } : {}
),
{}
);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the primary user-facing (breaking) change to unstable_dataStrategy in that instead of returning a HandlerResult[] (as a parallel array to matchesToLoad), you now return a Record<string, HandlerResult> which allows you to deviate from the internal matchesToLoad and provide (or not provide) fresh data for any active routes. This is how Remix will choose to revalidate existing ancestor routes by default.

null
);
result = results[0];
result = results[actionMatch.route.id];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Results are keyed by routeId now, not indexed

Comment on lines -2782 to -2812
return await Promise.all(
results.map((result, i) => {
if (isRedirectHandlerResult(result)) {
let response = result.result as Response;
return {
type: ResultType.redirect,
response: normalizeRelativeRoutingRedirectResponse(
response,
request,
matchesToLoad[i].route.id,
matches,
basename,
future.v7_relativeSplatPath
),
};
}

return convertHandlerResultToDataResult(result);
})
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just moved down below to scope the try/catch to callDataStrategyImpl

Comment on lines 2839 to 2844
// Kick off loaders and fetchers in parallel
let loaderResultsPromise = matchesToLoad.length
? callDataStrategy("loader", state, request, matchesToLoad, matches, null)
: Promise.resolve({} as Record<string, DataResult>);

let fetcherResultsPromise = Promise.all(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These still run in parallel but separating them from the singular Promise.all made it a bit easier to work with the new keyed object return value

Comment on lines +2864 to +2870
return Promise.resolve({
[f.key]: {
type: ResultType.error,
error: getInternalRouterError(404, {
pathname: f.path,
}),
} as ErrorResult,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fetchers are keyed by the fetcherKey from here outward, not the routeId, since you could have multiple fetchers hitting the same route

);

await Promise.all([
resolveDeferredResults(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was also split to 2 separate implementations since they did't share the majorty of the code anymore

): Promise<Record<string, HandlerResult>> {
let loadRouteDefinitionsPromises = matches.map((m) =>
m.route.lazy
? loadLazyRouteModule(m.route, mapRouteProperties, manifest)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We kick these off up front now, to remove the need for folks to call resolve() for all matches

type,
request,
match,
loadRoutePromise,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we pass the route.lazy promise into callLoaderOrAction so it can be awaited internally

export interface DataStrategyFunctionArgs<Context = any>
extends DataFunctionArgs<Context> {
matches: DataStrategyMatch[];
fetcherKey: string | null;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are passing the fetcherKey into dataStrategy now for fetcher cals which allows Remix to make one-off calls and not run any parent handlers in the single fetch request

@brophdawg11 brophdawg11 marked this pull request as ready for review September 3, 2024 16:57
@brophdawg11 brophdawg11 force-pushed the brophdawg11/single-fetch-data-strategy-updates branch from 8e3cb89 to b74306e Compare September 3, 2024 17:41
@brophdawg11 brophdawg11 merged commit 05612a3 into v6 Sep 4, 2024
3 checks passed
@brophdawg11 brophdawg11 deleted the brophdawg11/single-fetch-data-strategy-updates branch September 4, 2024 14:21
Copy link
Contributor

github-actions bot commented Sep 4, 2024

🤖 Hello there,

We just published version 6.26.2-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

github-actions bot commented Sep 9, 2024

🤖 Hello there,

We just published version 6.26.2 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.28.2-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!

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

1 participant