-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Fix route export props #12043
Conversation
|
@@ -1033,6 +1033,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = (_config) => { | |||
plugin !== null && | |||
"name" in plugin && | |||
plugin.name !== "react-router" && | |||
plugin.name !== "react-router-route-exports" && |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
removeExports(ast, SERVER_ONLY_ROUTE_EXPORTS); | ||
if (!options?.ssr) { | ||
removeExports(ast, SERVER_ONLY_ROUTE_EXPORTS); | ||
} |
There was a problem hiding this comment.
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.
Previously, the props HOCs were only applied when
ssr: false
, so it would work when HMR'ing an existing route to start using props likeloaderData
. That was causing errors as the initial SSR render did not have the HOCs applied, so all the props wereundefined
. Now the props HOCs always get applied.