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

defineRoute: runtime #11736

Closed
wants to merge 3 commits into from
Closed

defineRoute: runtime #11736

wants to merge 3 commits into from

Conversation

pcattori
Copy link
Contributor

No description provided.

Copy link

changeset-bot bot commented Jun 26, 2024

⚠️ No Changeset found

Latest commit: 46bb1d9

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

let routePath = path.resolve(ctx.reactRouterConfig.appDirectory, routeFile);
let code = await (readRouteFile?.() ?? fse.readFile(routePath, "utf-8"));

// temporary back compat
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note to self: should probably create a "remove back compat" and add links to that in these comments so its easier to track these down later.

<ComponentNeedingProps
// @ts-expect-error
params={params}
data={data}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
data={data}
loaderData={data}

Comment on lines +73 to +87
let Component = ComponentNeedingProps
? () => {
let params = useParams();
let data = useLoaderData();
let actionData = useActionData();
return (
<ComponentNeedingProps
// @ts-expect-error
params={params}
data={data}
actionData={actionData}
/>
);
}
: undefined;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

right now HMR tests are failing. pretty sure that this part is to blame since were dynamically creating a new component every time we want to render the route's component.

for a quick implementation, I think it'd be easiest to just create a virtual mod for each route (similar to what we already do for production) that re-exports from the route module's default export and wraps the Component.

a more principled solution would be to find out how we pass in data from loaders and actions and stop relying on hooks altogether. that would probably remove the need to wrap the Component from a route.

@pcattori
Copy link
Contributor Author

pcattori commented Jul 1, 2024

The approach of wrapping a component in the React Router runtime (e.g. in lib/dom/ssr/routes.tsx) was a dead end w.r.t. HMR. Instead, we're going to create a virtual module for each route so that Vite can process that vmod. This actually brings dev closer to parity with build since builds already use virtual modules for client routes.

@pcattori pcattori closed this Jul 1, 2024
@pcattori pcattori deleted the pedro/define-route-manifest branch July 1, 2024 22:48
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