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

@github-actions
Copy link
Copy Markdown
Contributor

👋 We've moved away from Changesets to our own internal changes process]. Please manually add a change file to this branch, or you can merge in the latest dev branch and run pnpm run changes:add to add a change file.

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