-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Vite: User-define route export referencing server-only code not working #7864
Comments
Experimenting with the reproduction repo, it looks like this is something to do with re-exporting Replacing server-only import from "named" import to "star // in routes/onborading.tsx
//
// before
//
import { getBaseUrl } from "~/utils/getBaseUrl.server";
export function getUrl(request: Request) {
return `${getBaseUrl(request)}/onboarding`;
}
//
// after
//
import * as serverLib from "~/utils/getBaseUrl.server";
export function getUrl(request: Request) {
return `${serverLib.getBaseUrl(request)}/onboarding`;
} Another note is that I think vite remix is less forgiving about import/export between two route files (cf. https://remix.run/docs/en/main/discussion/hot-module-replacement#supported-exports), so refactoring it out such structure might be recommended. |
@hi-ogawa, thank you for taking the time to review my repro repository. You're absolutely right, using named imports indeed functions as expected. While I can understand the reasons behind the supported exports, I'm unsure if it should be restricted in this case, where a full page reload would be acceptable (e.g. when modifying the In fact, I really like this pattern of treating the route component as the single source of truth. I'm wondering if this opens up a completely new possibility. Perhaps having a "reflect" function within a route component would be interesting. Here's an example that came to mind: export function reflect() {
return {
url(request: Request) {
return `${getBaseUrl()}/onboarding`
}
} as const;
} |
|
With Vite, Remix gets stricter about which exports are allowed from your route modules. For more see #8171 |
What version of Remix are you using?
2.2.0
Are all your remix dependencies & dev-dependencies using the same version?
Steps to Reproduce
http://localhost:5173
In one route,
/onboarding
, there is a function responsible for constructing its own URL (getUrl
). This function gets imported in theindex
route and used within aredirect
. This redirect fails occasionally.Expected Behavior
The redirect should work always.
Actual Behavior
The redirect works occasionally.
The text was updated successfully, but these errors were encountered: