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

Update single fetch logic when clientLoaders are present #9073

Merged
merged 7 commits into from
Mar 19, 2024

Conversation

brophdawg11
Copy link
Contributor

@brophdawg11 brophdawg11 commented Mar 18, 2024

Change the logic for serverLoader calls from clientLoader's in single fetch mode so we're not over-fetching on the server if a clientLoader never calls serverLoader.

Todo:

  • Update prefetching logic to align

Copy link

changeset-bot bot commented Mar 18, 2024

🦋 Changeset detected

Latest commit: be61761

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

This PR includes changesets to release 16 packages
Name Type
@remix-run/react Patch
@remix-run/testing Patch
@remix-run/dev Patch
create-remix Patch
remix Patch
@remix-run/architect Patch
@remix-run/cloudflare Patch
@remix-run/cloudflare-pages Patch
@remix-run/cloudflare-workers Patch
@remix-run/css-bundle Patch
@remix-run/deno Patch
@remix-run/eslint-config Patch
@remix-run/express Patch
@remix-run/node Patch
@remix-run/serve Patch
@remix-run/server-runtime 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

@brophdawg11 brophdawg11 marked this pull request as ready for review March 18, 2024 21:04
Comment on lines 140 to 145
// When a route has a client loader, we make it's own call for just
// it's server loader data
let url = stripIndexParam(singleFetchUrl(request.url));
url.searchParams.set("_routes", routeId);
let { data } = await fetchAndDecode(url);
results = data as SingleFetchResults;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

clientLoader calls through to serverLoader make a call for their individual route

Comment on lines 148 to 160
if (!singleFetchPromise) {
let url = addRevalidationParam(
manifest,
routeModules,
matches.map((m) => m.route),
matches.filter((m) => m.shouldLoad).map((m) => m.route),
stripIndexParam(singleFetchUrl(request.url))
);
singleFetchPromise = fetchAndDecode(url).then(
({ data }) => data as SingleFetchResults
);
}
results = await singleFetchPromise;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Everyone else (non-clientLoader routes) latches onto the same promise

manifest.routes[r.id]?.hasClientLoader
);
if (!needsParam) {
return url;
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 don't bother adding a param if there are no shouldRevalidate's and no clientLoader's

Comment on lines +244 to +248
let loadIds = genRouteIds(
loadRoutes
.filter((r) => !manifest.routes[r.id]?.hasClientLoader)
.map((r) => r.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.

Load the routes requested that don't have client loaders

@sergiodxa
Copy link
Member

If I understand correctly, by adding a clientLoader you're essentially opting out of Single Fetch? So now every serverLoader call will be a separate request as currently

@brophdawg11
Copy link
Contributor Author

brophdawg11 commented Mar 19, 2024

Yeah only for that route branch. Otherwise we nullify a primary benefit of clientLoader which is to avoid hitting the server loader since the single fetch call would hit it anyway even if you pulled data from the client side cache. serverLoader is essentially the same as the old ?_data fetch via the single fetch call/encoding.

You still get a multi-route single fetch call for any routes that do not have a client loader, so if you route to a/b/c/d and only d has a clientLoader, you'd get:

GET /a/b/c/d.data?_routes=a,b,c (always)

GET /a/b/c/d.data?_routes=d     (only if d called serverLoader())

@brophdawg11 brophdawg11 merged commit 00928fd into dev Mar 19, 2024
5 checks passed
@brophdawg11 brophdawg11 deleted the brophdawg11/single-fetch-client-loader branch March 19, 2024 18:31
@github-actions github-actions bot added the awaiting release This issue has been fixed and will be released soon label Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting release This issue has been fixed and will be released soon CLA Signed feat:routing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants