-
-
Notifications
You must be signed in to change notification settings - Fork 6.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
feat: non-blocking scanning of dependencies #7379
Conversation
✅ all green vite-ecosystem-ci run against this PR
We could make the new |
This might break https://github.com/antfu/vite-plugin-optimize-persist since it's relying on some internals. But what is great is that we might be able to completely deprecate it in favor of these improvements! 🚀 |
Oh, interesting. IMO it may not be needed anymore as you said. FWIW, I checked the code of vite-plugin-optimize-persist, and looks like it will not fail with a hard error, it will just not update since |
Not at all. I mean the good side, it's much better not needing it :) No need to change anything |
This PR is now ready to be merged. All green vite-ecosystem-ci run here: Also tested it in Laddle and Vaddin Start. I ended up removing |
Thank you for the improvement! |
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.
Left some comments/questions below, but the rest looks great! It looks a lot cleaner than before.
I'm not enough deep into this as I could make a real review, but from a code review I can accept this ^^ |
Done at: e55d8a9 This is how icones looks in 2.8.6. There were 2 page reloads needed on cold start It is interesting that for icones, the server start isn't faster than in 2.8.6, I wonder if the used plugins may affect this. With only the Vue or React plugin I'm seeing 200ms start times. @antfu 💚 |
Looks like some tests are failing because of timeouts, maybe 30sec isn't enough. I will try to raise it in another PR. CI was working better though lately compared to the fails we are getting in this PR, so we may still need to squash a bug here. I think we should merge it though and get people to test it to have more time during the beta |
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.
LGTM 🚀
I wonder if it would make sense to add a delay before logging the optimized deps so we avoid the multiple lines in case there are missing deps
Done at: e55d8a9
I think it's nice to have for DX as long as in debug mode, we can see the separation of deps pre-bundled, as it may help with debugging some issues/support in the future.
Indeed, when debugging with |
Example of new logs running Laddle and opening a few stories (each story will discover a new set of dependencies). I still think that we should only show the last message, but maybe it is too much of a change for 2.9 and we can discuss it for 3.0. I don't think that it is useful to a regular user to know when their dependencies were optimized, it is an implementation detail for Vite. Merging this now so we can do a new beta patch and get some more testing. |
Thx for your great work and I could close my issues #6677 |
LGTM, 2.9.0 test succeed in my ssr framework without full reload when find new dependencies |
Description
For context, first read:
#6758 moved the pre-bundling of dependencies after the server start. But the initial scan phase was still blocked. The scanning is fast thanks to esbuild, but the time it takes will grow with the user code. Depending on what dependencies the project uses, the scanning phase could take longer than the pre-bundling itself.
This PR completes the work started by #6758 by moving scanning after the server start, and letting the requests flow and be processed in parallel.
A refactoring was needed to implement this feature. I think how the different pieces interact are more clear after this PR, and even if the scanning will be blocking, I would advocate merging the refactoring.
Main changes:
server._optimizeDepMetadata
andserver._registerMissingImport
toserver._optimizedDeps
which is an object where we can have themetadata
and related functions. I think we could move some of the free functions that takes themetadata
to this object (like we do withmoduleGraph
), but I wanted to keep the changes focused on the feat in this PR. We can do other refactorings in future PRs._registerMissingImport
as a flag to know if we were scanning (if it was null, then we were resolving for the scan phase). We can no longer use this scheme as we are processing requests in parallel and we will have some resolve calls from the scan process intermixed with the regular requests. So, there is a newscan
option passed toresolveId
(as we do withssr
) and we have aserver._optimizedDeps.scanProcessing
promise which lets us await until scanning is over when resolving bare imports.Note: Since we are processing requests in parallel to the scan phase we could allow their resolution to progress (or some of them) and register them as missing imports. Then we can aggregate the scan phase dependencies with the discovered deps potentially saving a page reload. I found this problematic though, as we can't safely cache in the browser the resulting deps. See related explanation at #7378. Maybe this could be further explored.
Tested with Vaadin Start and with Ladle.
More testing is still required, but we may want to merge this one during the 2.9 beta so we only test the changes to pre-bundling in this minor and we don't need to repeat these again for 3.0.
What is the purpose of this pull request?