-
Notifications
You must be signed in to change notification settings - Fork 373
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
[Bug?]: undefined error on exported variable in page route #1591
Comments
I have the same issue and I think it was caused by updating to the latest vinxi version. |
It's caused by the fix we did from the HMR page reload. Before we weren't properly reloading HMR on pages which was causing hydration errors on new routes. The problem now is that when the routes reload it appears that we get circular deps issues in HMR when things are exported from the page files and used downstream. All I can recommend at this point is don't export from page routes. The way code splitting and bundling work it is too easy for things to get in a weird state. Maybe we should just find a way to error/warn you in this case. But the types of loops it can cause especially if the export is used by components used in nested page sections messes with code splitting. Strongly recommend having a separate file that has things that are imported into both locations. |
Yeah, I realised it was a circular dependency and fixed it, but it wasn't from a page route. I just wish the error would actually be helpful and inform of the circular dependency instead of the current incorrect error. I will look into vinxi to see if I can pinpoint it and open a PR. |
In general this is an interesting type of issue I'm seeing people hit more often than I thought. Because of the way code splitting works I could never recommend this pattern and never even thought of it. But people tend to want to do this and I'm not sure we can safe guard against it unless we somehow error when processing the routes. While not all situations end up in breaking code splitting it is incredibly common and basically defeats the point of file system routing. Unfortunately I hit very similar issues when building SolidStart internals and had the same undefined problem. This silently fails at layer lower than us so I don't really have any recourse here. I'm open to suggestions, but not recommending exporting things other than default/route from page routes is all I can really put out there. |
Erroring out during the creation of routes sounds like the best (and maybe only) option. This behaviour also happens if you import a component from a different directory than routes and then export it as default from a route, so that's another thing we could catch. I think I saw the code that creates the routes and it already checks for default AND named exports, so we could just throw there. |
Duplicates
Latest version
Current behavior 😯
In a page route when trying to access an exported variable
X is not defined
error is thrown during SSR.Interestingly the error does not occur when the var is not exported and seems to only occur in route file.
Expected behavior 🤔
Variable access should work.
Steps to reproduce 🕹
Steps:
Stackblitz started from
start.solid.new
Error:
Context 🔦
Exporting config objects.
Your environment 🌎
The text was updated successfully, but these errors were encountered: