-
-
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
fix: call createFileOnlyEntry() only for CSS deps, fix #4150 #4267
Conversation
Thanks for digging into this issue @paraboul, reading your comments has been very helpful to understand the problem. I think the PR is close to where we need it, but it is fragile to call Check out the comment
// some deps, like a css file referenced via @import, don't have its own
// url because they are inlined into the main css import. But they still
// need to be represented in the module graph so that they can trigger
// hmr in the importing css file. This should only be called for these CSS deps, and not for the others. I think we should apply the same pattern that is already present here vite/packages/vite/src/node/server/hmr.ts Line 230 in 09c6c94
and only call createFileOnlyEntry here vite/packages/vite/src/node/plugins/css.ts Line 195 in 09c6c94
ensureEntryFromUrl as usual.
What do you think? @OneNail your input here would also be appreciated :) |
@patak-js Thanks for the feedback! :) I'm not sure to understand when It's called from this place (and only there) since it has been added by this commit : The problem here is that This PR really just tries to make sure the same module is being unified in one entry if Or am I missing something? |
Not with something that is not a file, but it should only be called for file-only entries as in a CSS imported from a CSS by a preprocessor that will end up inlined (and it isn't then a real independent module)
Yes, I understand what you were trying to achieve. The issue is that these deps added by postCSS are not file-only entries and with the current change set they will end up in the module graph without a proper entry in What I mean in my last comment is that we should have something like vite/packages/vite/src/node/plugins/css.ts Line 195 in 09c6c94
Warning: pseudocode, not tested // record deps in the module graph so edits to @import css can trigger
// main import to hot update. PostCSS can add other deps to a CSS, so
// we need to check if this is file-only entry and fallback to a regular
// module entry for other modules
const depModules = new Set(
[...deps].map((file) =>
cssLangRE.test(file) ?
moduleGraph.createFileOnlyEntry(file) :
moduleGraph.ensureEntryFromUrl(file)
) I haven't checked the details here, maybe the file needs to be converted to an URL before passing it to |
@patak-js Ok I get it. Thanks! |
It's very distressing to not be able to reproduce the bug #4150 before. Thank @paraboul for reproducing and solving this bug. It turns out that |
@patak-js |
@OneNail For reference, it's not specific to vue-router. The problem happens as soon as a CSS plugin registers non CSS files as dependencies of the transformed CSS (which is what Tailwind JIT does). The issue exhibits as soon as a purgeable file doesn't import any other dependency. |
Yes, the root cause is what you pointed out, |
@anncwb would you test this PR with your use case #4150 (comment)? |
@knightly-bot build this |
🌒 Knightly build enabled, release every night at 00:00 UTC (skip if no change) |
@jods4 @yassinebridi, @luukdv, @cossssmin, @nmabhinandan the Knightly bot built a version of this PR (link in the previous comment). Would you help us test this using it in your projects? Thanks! |
@paraboul @patak-js I tried to isolate the problem to add a test but cannot reproduce/recreate it within |
@paraboul I think I isolated this - are you working on a test or should I? Edit: Nevermind - I had it, then tried to simplify further, and lost it. Whac-A-Mole |
I can check early next week. Unless you already have something ready ? :)
We can merge this PR and land a test in a separate one?
|
@patak-js Can you check if that knightly build exists, it doesn't seem to be? |
Ya, looks like Knightly bot is not working correctlty, back to yarn link to test then |
@patak-js Just added a new playground project to test various tailwind updates. The test fails without this PR's fix. |
@paraboul Good playground - accurately represents the typical usage of Tailwind. |
I added index.css in the index.html file instead. I wasn't able to
reproduce the issue in the test run by importing the css in JS. Probably
related to some difference in the dependency tree specific to testing?
Anyway, i was able to reproduce the issue that way.
…On Mon, Jul 19, 2021, 13:38 patak ***@***.***> wrote:
***@***.**** requested changes on this pull request.
------------------------------
In packages/playground/tailwind/src/main.js
<#4267 (comment)>:
> @@ -0,0 +1,6 @@
+import { createApp } from 'vue'
+import App from './App.vue'
+import router from './router'
+// import '../index.css';
Why is this import commented? Shouldn't this be part of the tailwind setup
https://tailwindcss.com/docs/guides/vue-3-vite#include-tailwind-in-your-css
?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4267 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAATTVPAM5AQFWAFDPRF4WTTYQFCXANCNFSM5AN4ZODQ>
.
|
Co-authored-by: patak <[email protected]>
Co-authored-by: patak <[email protected]>
Co-authored-by: patak <[email protected]>
The change in vitejs#4267 caused all CSS dependencies of files that are not CSS (Tailwind CSS JIT deps) to be tracked with the `base` prefix in the module graph. URLs in the module graph are normalized and are never prefixed with base and as a result changes to those files were not causing the CSS module to be invalidated. See tailwindlabs/tailwindcss#4978 (comment)
Description
Tailwind (JIT) registers all purgeable files as dependencies of the generated css.
This lead to every SFC/html being added to moduleGraph with
createFileOnlyEntry()
.If some cases,
createFileOnlyEntry()
is called beforeensureEntryFromUrl()
for the same file but with a different URL (becausecreateFileOnlyEntry()
only add modules entries with absolute path usingFS_PREFIX
), ultimately leading to the same module having a duplicate entry but with different importers (preventing HMR from properly propagating updates).This PR tries to address this problem by making sure we're calling
ensureEntryFromUrl()
rather thancreateFileOnlyEntry()
for non CSS filesThis fix #4150
Additional context
Discussion on the issue #4150
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).