Skip to content

feat: allow configuration of how route modules are loaded in the browser #12638

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

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

jacob-ebey
Copy link
Member

@jacob-ebey jacob-ebey commented Dec 25, 2024

Adds a new API for bundler plugin usage to take control over the loading of client modules:

// entry.client.tsx
import { startTransition, StrictMode } from "react";
import { hydrateRoot } from "react-dom/client";
import type { unstable_LoadRouteModuleFunction } from "react-router";
import { HydratedRouter } from "react-router/dom";

const loadRouteModule: unstable_LoadRouteModuleFunction = async (
  route,
  routeModulesCache
) => {
  if (route.id in routeModulesCache) {
    return routeModulesCache[route.id];
  }

  console.log("Running custom import logic for route module:", route.module);

  // Note: a proper implementation should handle an error here
  // We trigger a hard reload in RR's default implementation
  let routeModule = await import(route.module);

  routeModulesCache[route.id] = routeModule;
  return routeModule;
};

startTransition(() => {
  hydrateRoot(
    document,
    <StrictMode>
      <HydratedRouter unstable_loadRouteModule={loadRouteModule} />
    </StrictMode>
  );
});

Copy link

changeset-bot bot commented Dec 25, 2024

⚠️ No Changeset found

Latest commit: 235eba2

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

@brophdawg11 brophdawg11 added the review flag for team review label Apr 2, 2025
@brophdawg11
Copy link
Contributor

Note - this new API would need to be added to the new import() calls for split route modules

@brophdawg11 brophdawg11 self-assigned this Apr 3, 2025
@brophdawg11 brophdawg11 added pkg:react-router and removed review flag for team review labels Apr 3, 2025
@brophdawg11 brophdawg11 added the alpha-release Used by maintainers to trigger a Stage 2 (alpha) release on a PR label Jul 1, 2025
Copy link
Contributor

github-actions bot commented Jul 1, 2025

Alpha release created: 0.0.0-experimental-1d8f3ee

⚠️ Note: This release was created from the HEAD of this branch so it may contain commits that have landed in dev but have not been released yet depending on when this branch was created. You can run the following command to see the commits that may not have been released yet:

git log --pretty=oneline [email protected]

@github-actions github-actions bot removed the alpha-release Used by maintainers to trigger a Stage 2 (alpha) release on a PR label Jul 1, 2025
@@ -582,6 +582,9 @@ export function RSCHydratedRouter({
},
routeDiscovery: { mode: "lazy", manifestPath: "/__manifest" },
routeModules: {},
loadRouteModule: () => {
throw new Error("Not required in RSC Mode");
Copy link
Contributor

Choose a reason for hiding this comment

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

@jacob-ebey Can you confirm this is correct?

@brophdawg11 brophdawg11 added the alpha-release Used by maintainers to trigger a Stage 2 (alpha) release on a PR label Jul 1, 2025
Copy link
Contributor

github-actions bot commented Jul 1, 2025

Alpha release created: 0.0.0-experimental-235eba2

⚠️ Note: This release was created from the HEAD of this branch so it may contain commits that have landed in dev but have not been released yet depending on when this branch was created. You can run the following command to see the commits that may not have been released yet:

git log --pretty=oneline [email protected]

@github-actions github-actions bot removed the alpha-release Used by maintainers to trigger a Stage 2 (alpha) release on a PR label Jul 1, 2025
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.

2 participants