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

Fix route export props #12043

Merged
merged 1 commit into from
Sep 28, 2024
Merged

Fix route export props #12043

merged 1 commit into from
Sep 28, 2024

Conversation

pcattori
Copy link
Contributor

Previously, the props HOCs were only applied when ssr: false, so it would work when HMR'ing an existing route to start using props like loaderData. That was causing errors as the initial SSR render did not have the HOCs applied, so all the props were undefined. Now the props HOCs always get applied.

Copy link

changeset-bot bot commented Sep 28, 2024

⚠️ No Changeset found

Latest commit: 56d40f0

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

@@ -1033,6 +1033,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = (_config) => {
plugin !== null &&
"name" in plugin &&
plugin.name !== "react-router" &&
plugin.name !== "react-router-route-exports" &&
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@markdalgleish as I was working on this, I realized that the child compiler really exists to transform the routes with all plugins prior to the Remix/RR plugins. It just so happens that all of our transforms only target client code (ssr: false) so (1) the early returns in each transform (if (options?.ssr) return) combined with (2) setting ssr: true when using the child compiler to determine route exports, just happened to work.

But now that we have a transform that needs to run for both (the props HOC transform), that stopped working. I added react-router-route-exports to this list, but what if we just add all the plugins defined here to this list? we could even define the plugins separately. That way we'll still get all external plugins set in the child compiler.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that makes sense. Would it be too aggressive to simply filter out react-router and anything starting with react-router-? Alternatively, we could annotate all of our plugins with an extra property that we detect (e.g. we check for plugin.__reactRouterPlugin or something similar). That way we don't have to maintain a list.

Comment on lines -1465 to +1466
removeExports(ast, SERVER_ONLY_ROUTE_EXPORTS);
if (!options?.ssr) {
removeExports(ast, SERVER_ONLY_ROUTE_EXPORTS);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the important part: the WithProps.transform (below) always needs to be applied so that SSR render also has data from props HOCs, which means we need to conditionally remove exports for ssr: false more precisely.

@pcattori pcattori merged commit 12c37f0 into dev Sep 28, 2024
8 checks passed
@pcattori pcattori deleted the pedro/fix-route-export-args-and-props branch September 28, 2024 01:19
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