-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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(hmr): html registered as a PostCSS dependency, fix #3716 #4127
Conversation
Checking the naming of these helpers export const isCSSRequest = (request: string): boolean =>
cssLangRE.test(request) && !directRequestRE.test(request)
export const isDirectCSSRequest = (request: string): boolean =>
cssLangRE.test(request) && directRequestRE.test(request) That are used in some places like if (
isJSRequest(url) ||
isImportRequest(url) ||
isCSSRequest(url) ||
isHTMLProxy(url)
) {
// for CSS, we need to differentiate between normal CSS requests and imports
if (isCSSRequest(url) && req.headers.accept?.includes('text/css')) {
url = injectQuery(url, 'direct')
} I wonder if there are other bugs like this because people were using it without knowing that it explicitly tests for not being a direct request. I think we should have export const isCSSRequest = (request: string): boolean =>
cssLangRE.test(request)
// Only use this helper in plugins when the URL has already being marked
export const isIndirectCSSRequest = (request: string): boolean =>
isCSSRequest(request) && !directRequestRE.test(request)
export const isDirectCSSRequest = (request: string): boolean =>
cssLangRE.test(request) && directRequestRE.test(request) In the check above we could use an isCSSRequest check + an explicit !directRequestRE if that is really needed at that point. After that, URLs are already marked in plugins But this refactor shouldn't be part of this PR, so it is better to me that we go forward with this fix |
@patak-js Thank you for your comment. |
Thank you for all the work in Vite lately!
Would you like to give this refactor a try? Or should we open it to others? |
@patak-js I'm glad to give this refactor a try. Thanks~ |
Awesome, thanks! Just a fair warning that I think it is a good idea but we will need to review it later with the rest of the team once it is on the table |
Description
fix #3716
Additional context
PostCSS plugin Tailwind JIT register any file as a dependency to a CSS file. When using
<link rel="stylesheet">
,index.html
module's importers includes style.css module, the browser does not automatically refresh as index.html is changed.The current solution does not include the processing of direct import css:
vite/packages/vite/src/node/server/hmr.ts
Line 252 in e30ce56
vite/packages/vite/src/node/plugins/css.ts
Lines 101 to 102 in e30ce56
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).