-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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: preserve base in HMR for CSS referenced in link tags #4407
Conversation
Looks good, is it difficult to include a test for this in the backend-integration playground? |
@patak-js Adding an HMR test case is not difficult, but it wouldn't fail if the base is removed—Vite will serve files anyway. Not sure if there's a way to spy on the incoming requests to verify the prefix, couldn't find a similar test. |
Added a spec where we check the replaced |
packages/vite/src/client/client.ts
Outdated
base + | ||
`${path.slice(1)}${path.includes('?') ? '&' : '?'}t=${timestamp}` |
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.
base + | |
`${path.slice(1)}${path.includes('?') ? '&' : '?'}t=${timestamp}` | |
`${base}${path.slice(1)}${path.includes('?') ? '&' : '?'}t=${timestamp}` |
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.
Could you also please run the formatter after this change? Could change the suggestion
Description 📖
This pull request ensures the
base
is also used for HMR updates when a CSS file was included using alink
tag.Additional context
base
is already being used to prefix the URLs when ajs-update
occurs.Since the
base
is removed from theurl
when registering a CSS file in the module graph, thepath
sent in thecss-update
message is not prefixed withbase
.As a result, the updated
href
targets the origin root (/
), which is not consistent with how JS updates are fetched, and requires special handling if proxying requests to the Vite dev server.What is the purpose of this pull request?