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: reuse the old preprocessor after changing the lang attr #4224

Merged
merged 3 commits into from Jul 20, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/plugin-vue/src/handleHotUpdate.ts
Expand Up @@ -88,7 +88,11 @@ export async function handleHotUpdate({
const next = nextStyles[i]
if (!prev || !isEqualBlock(prev, next)) {
didUpdateStyle = true
const mod = modules.find((m) => m.url.includes(`type=style&index=${i}`))
const mod = modules.find(
(m) =>
m.url.includes(`type=style&index=${i}`) &&
m.url.endsWith(`.${next.lang || 'css'}`)
Comment on lines +93 to +94
Copy link
Member

Choose a reason for hiding this comment

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

question:

"[...] changing the lang attribute of the style tag will not cause the preprocessor to be updated. [...]"

Why should this work? You just shrink the condition from includes to includes + endsWith 🤔
Could you explain what is happening here?

Copy link
Contributor Author

@y1d7ng y1d7ng Jul 12, 2021

Choose a reason for hiding this comment

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

When the lang is changed, the corresponding module will be found through the following line of code, but the url of the module still contains the previous lang. The css plugin will parse the url of this module to select the preprocessor.

const mod = modules.find((m) => m.url.includes(`type=style&index=${i}`))

After adding endsWith, a new module will be generated with the new lang in the url.

)
if (mod) {
affectedModules.add(mod)
} else {
Expand Down