Skip to content

POC: clientLoader.unstable_batch - batch clientLoader with single fetch server call#14884

Draft
brophdawg11 wants to merge 2 commits intodevfrom
brophdawg11/client-loader-batched
Draft

POC: clientLoader.unstable_batch - batch clientLoader with single fetch server call#14884
brophdawg11 wants to merge 2 commits intodevfrom
brophdawg11/client-loader-batched

Conversation

@brophdawg11
Copy link
Copy Markdown
Contributor

@brophdawg11 brophdawg11 commented Mar 17, 2026

POC for a new unstable_batch flag on clientLoader that allows a route's client loader to participate in the normal single fetch server request, rather than forcing a separate out-of-band server call.

export async function clientLoader({ serverLoader }: Route.ClientLoaderArgs) {
  const data = await serverLoader({ batch: true });
  // ... client-side augmentation ...
  return { ...data, extra: "client-only stuff" };
}

clientLoader.unstable_batch = true

With unstable_batch = true:

  • The server loader call is initiated eagerly before clientLoader runs, as part of the normal single fetch request alongside all other loaders
  • When the clientLoader calls serverLoader(), it awaits the already-in-flight batched response rather than issuing a new request

Known limitation: <Link prefetch>

<Link prefetch> still excludes routes with hasClientLoader from the prefetch .data URL on the first prefetch, even when unstable_batch = true because we don't have the route module to know if unstable_batch is set.

plan:

  • we already do an AST parse at route module extraction for splitting loader/action/etc.
  • move that up to manifest creation time and cache
  • short circuit on quick regex for unstable_batch
  • add clientLoaderBatch boolean to manifest

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 17, 2026

⚠️ No Changeset found

Latest commit: 03764fb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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.

1 participant