-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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 needs interop #7568
Conversation
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
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.
Awesome ⚡
Adding this one to the 3.0 milestone, as it would be good to test it a bit during the beta window. I will add docs in the meantime and we would need to discuss the addition of the new |
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.
The merged changes lgtm. Maybe we should add docs for optimizeDeps.needsInterop
here too?
After the latest changes in the repo, this PR makes this error happens more often: https://github.com/vitejs/vite/runs/6407272224?check_suite_focus=true#step:11:130, I think it may be a race condition that we are uncovering. I'm very confused by this test though, I tried to fix the package json of the dep it is importing but then the error is consistent: @bluwy this dep is written in ESM + a .vue file, and it doesn't have |
@bluwy would you help me here? I think this test is not right and should be removed. It was added by: The idea was to test an issue with the external detection heuristics, but added a Package with an uncompiled .vue file (that IIUC, it isn't what the Vue ecosystem does). We have been adding |
Pushed a commit to update I also found out that playgrounds with custom Hopefully the tests passes now. |
Oh, awesome @bluwy! I still think this may not be the best test to have, but even better if we dont need to remove it because of this PR. Would you send these changes in a separate PR so we can merge them without waiting approval for this PR? |
Oh are there more stuff to work on for this PR? Thought it was in a ready state except for the tests. If so yeah I can create a separate PR. |
We didnt discuss it in a meeting, and there is a new option 👀 |
Description
Continuation of the work started by
We allowed requests to flow through the pipeline in #6758 while pre-bundling, but we needed to block them when:
Ideally, we only would like to block on 1. Awaiting in 2 blocks requests for any user source code that imports a dep. So in a Vue app, we will be blocking most requests because they all import
'vue'
.Proposal
This PR proposes a way out potentially speeding up cold start even further, with the tradeoff that some legacy packages that advertise themselves as ESM but include mixed CJS may now need to be manually added in the user config. I believe that we could push this "breaking change" in Vite 3.0, and keep pushing for the ecosystem to fix packages as we already do in many other cases in Vite.
Edit: with the latest commits, there is no longer a breaking change. Mixed ESM and CJS would still work, and the only diff would be that cold start would be a bit slower because of an extra page reload if they aren't added to
optimizeDeps.needsInterop
.Details
The old
needsInterop
checks:a.
KNOWN_INTEROP_IDS
->true
(only'moment'
is included right now, that was the lib that originated the complex mixed ESM and CJS checks)b. there aren't exports or imports -> true (assumes it is CJS or UMD)
c. mixed ESM and CJS by checking exports mismatch after esbuild bundled the dep
Because of c., this needs to be computed after pre-bundling
The new
needsInterop
after this PR checks only a. and b., and a new list inoptimizedDeps.needsInterop
. So we can compute it before pre-bundling.We still check c. after pre-bundling, but now to be able to warn the user of the package issue and hint that this can be solved by adding the dep id to
optimizedDeps.needsInterop
If we would like to proceed with this change, we would need to check how many dependencies have mixed ESM and CJS. And how problematic it is for users to manually add them to the config. I like the idea of having some friction so some of these packages get PRs to fix them.
As an alternative, we could avoid the
optimizedDeps.needsInterop
list and instead add aoptimizedDeps.acceptMixedSyntax
(better name?) that defaults to false. If the user sets it to true, then we revert to the current approach. I think thatoptimizedDeps.needsInterop
is better because users don't need to revert to the slower scheme just because of one faulty package, and because the implementation (the one in this PR) is simpler than what we would need to supportacceptMixedSyntax
.What is the purpose of this pull request?