Skip to content
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: CSS dependencies are tracked incorrectly when base is set #4592

Merged
merged 3 commits into from Aug 17, 2021

Conversation

ElMassimo
Copy link
Contributor

@ElMassimo ElMassimo commented Aug 12, 2021

Description

CSS file dependencies are being tracked incorrectly when the base configuration option is set—URLs are being prefixed with base in some scenarios.

URLs in the module graph are normalized and are never prefixed with base, and as a result changes to those files are not causing the CSS module to be invalidated.

This pull request ensures the base is removed before passing it to ensureEntryFromUrl which is not base-aware.

Additional context

The bug was introduced in #4267, released in 2.4.3.

Among other potential bugs, this causes Tailwind CSS in JIT mode to stop working as expected when base is specified, because changes to HTML or JS files do not match the module graph file names, and as a result CSS is not invalidated when a change occurs.

See tailwindlabs/tailwindcss#4978 (comment) for more context.

What is the purpose of this pull request?

  • Bug fix

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)
@Shinigami92 Shinigami92 added feat: css p3-minor-bug An edge case that only affects very specific usage (priority) labels Aug 12, 2021
Copy link
Member

@Shinigami92 Shinigami92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a weird solution, but if it works, it works

@ElMassimo
Copy link
Contributor Author

ElMassimo commented Aug 12, 2021

Yeah, I'm not convinced that using fileToUrl as added in #4267 is the way to go, but there's no other "normalize" function that is public and can handle all the edge cases.

Perhaps it could be wrapped into fileToModuleGraphUrl and remove the base there instead, but for now it's the only place where it's used like this.

Copy link
Member

@patak-dev patak-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the refactoring mentioned by @ElMassimo should be done, but we could get this fix in the meantime.

@patak-dev patak-dev requested a review from antfu August 12, 2021 20:04
@patak-dev patak-dev merged commit 633c03a into vitejs:main Aug 17, 2021
@ElMassimo ElMassimo deleted the fix/css-dependencies branch August 17, 2021 18:42
@sebastiaanluca
Copy link

Is it possible this has broken again somehow? Using vite 2.6.3 and Tailwind (v2 or 3) breaks its JIT mode. Downgrading to Vite 2.4.2 (as suggested in tailwindlabs/tailwindcss#4978 (comment)) resolves the issue.

@patak-dev
Copy link
Member

@sebastiaanluca would you create an issue with a reproduction to track this?

@sebastiaanluca
Copy link

Need to do the same for the other ticket, so I'll try and set that up one of these days 👍

aleclarson pushed a commit to aleclarson/vite that referenced this pull request Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: css p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants