-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
feat: experimental preTransformDynamicRequests #14777
Conversation
Run & review this pull request in StackBlitz Codeflow. |
Another function-based option 😄 I'm trying to imagine the usecase but I'm not quite sure how it'll happen. For example, if it depends on the route the user is visiting, shouldn't the route would've statically import that url in the first place? Dynamic imports would always imply something optional. Also would this be able to workaround by calling |
So, for Nuxt, they will hit a dynamic import right away at the start of every route as that is how their router work. I'm still unsure if this API would be good though, @danielroe could check later if there is enough information to know if a dynamic import should be crawled. But it seems that isn't the case, I just looked at it with @antfu and all dynamic imports are going to be hit for each route so you don't know if you should process it or not.
Yes, Nuxt was already doing this but more similar to what We also discussed with Anthony another use case for this PR, that could still be interesting. He is using dynamic imports to conditionally load some features that are not always needed like: if (__FEATURE_FLAG__)
import(...).then(...) For these feature imports, the function will still be useful. But it may be too much of an edge case. For sli.dev for example where there are several of these, he doesn't care that all of them are loaded during dev so he will probably just adopt |
Thanks. Perhaps in the case of routing where each route is a dynamic import, it would also be tricky to use this API since the information of which page being requested doesn't exist in this hook/option. Nuxt might already have the mapping of route urls to the route files, that might be easier to call Maybe also, we could add a |
@patak-dev should we close this over #14787, or there's still a possibility for this API? |
Let's close this one until we have a real use case. Working with ecosystem partners to adopt |
Description
@danielroe has been working to adopt the new
warmup
functionality from Vite 5 and review their warmup implementation.This PR implements an idea we discussed. The current
warmup
,--open
, andpreTransformRequests
will only crawl static imports. There are some dynamic imports in routes that frameworks know should be crawled but if all of them are added towarmup
, there could be a lot of unneeded modules processed depending on the route the user is visiting. Interested in hearing your opinion on this one @bluwy.preTransformDynamicRequests
will let frameworks decide if a request that would be started by a dynamic import should be crawled or not.I named the function
preTransformDynamicRequests
instead ofpreTransformDynamicImports
because we are giving a URL to it, we can change the name.What is the purpose of this pull request?