-
-
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
walkParentInfos
handles circular imports too naively
#7857
Comments
Thanks for opening an issue, @ottomated! Is this something you're planning to tackle in #7733 ? |
@natemoo-re I think it should be done on that branch, but I don't think I'm the best person for the job – I assume there's an existing algorithm for resolving circular imports that someone else would know. |
Cool, thanks for the context! @bluwy hopefully might know something of the technique Vite uses to handle this... |
I took a look at the issue in the past few days. I think I got a good grasp of it now, and what proposed here would indeed improve the optimization. But looking into all the edge case surrounding hoisted scripts, it's a lot complex than expected.
I think it will be most robust if scripts (and styles?) are added during render time, instead of build time. Build-time analysis can only go very far and usually relies on side-effects, which is what we're emulating before for scripts (and styles). For now, I'll revert #7707 to unblock the issue. This would "dumb down" the hoisted script heuristic, which isn't great, but I think it's better to be predictable for now and find a better solution in the future. |
I completely agree that render-time is better than build-time for this (although two issues that instantly strike me are the need to bundle scripts, i.e. a build step after the render step, and what to do for SSR pages). However, I would ask that we consider fixing these edge cases before reverting, or at least raising an issue with the same priority as #7744.
Otherwise, I would ask for this behavior to be behind an experimental flag for now so it doesn't entirely block my project. |
There could be a lot of patterns people are using:
My point is the consistency where one page would sometime works and sometimes doesn't, e.g.
I'm open to that too. (I'm signing off for the day and call handle this tomorrow, otherwise feel free to send a PR too) |
What version of
astro
are you using?2.9.5
Are you using an SSR adapter? If so, which one?
N/A
What package manager are you using?
npm
What operating system are you using?
Linux
What browser are you using?
Chrome
Describe the Bug
When analyzing hoisted script imports, the following situation can happen:
This causes an issue when
bad.astro
hasimport { Component } from '../components';
. This is because the path fromComponent.astro
->index.ts
->bad.astro
is never traversed, meaning Astro can't analyze the import.What's the expected result?
The expected traversal is:
Since walkParentInfo's implementation prevents circular imports by ensuring each module is only visited once, we can't to visit
index.ts
twice like we need to.Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-xidexe?file=dist%2Fbad%2Findex.html
Participation
The text was updated successfully, but these errors were encountered: