Skip to content

Commit 7a3c6e6

Browse files
y1d7ngShinigami92
andauthored
fix: reuse the old preprocessor after changing the lang attr (#4224)
* fix(plugin-vue): reuse the old preprocessor after changing the lang attr * feat(playground): add stylus + change lang test in vue * chore: add eol line break Co-authored-by: Shinigami <[email protected]>
1 parent 514e124 commit 7a3c6e6

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

packages/playground/vue/PreProcessors.vue

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ p.pug
66
p.pug-less
77
| This is rendered from &lt;template lang="pug"&gt;
88
| and styled with &lt;style lang="less"&gt;. It should be green.
9+
p.pug-stylus
10+
| This is rendered from &lt;template lang="pug"&gt;
11+
| and styled with &lt;style lang="stylus"&gt;. It should be orange.
912
SlotComponent
1013
template(v-slot:test-slot)
1114
div.pug-slot slot content
@@ -32,3 +35,10 @@ $color: magenta;
3235
color: @color;
3336
}
3437
</style>
38+
39+
<style lang="stylus">
40+
color = orange
41+
42+
.pug-stylus
43+
color: color
44+
</style>

packages/playground/vue/__tests__/vue.spec.ts

+15
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ describe('pre-processors', () => {
5656
)
5757
await untilUpdated(() => getColor(el), 'blue')
5858
})
59+
60+
test('stylus + change lang', async () => {
61+
expect(await getColor('p.pug-stylus')).toBe('orange')
62+
editFile('PreProcessors.vue', (code) =>
63+
code
64+
.replace('<style lang="stylus">', '<style lang="scss">')
65+
.replace('color = orange', '$color: yellow;')
66+
.replace('color: color', '{ color: $color; }')
67+
)
68+
await untilUpdated(() => getColor('p.pug-stylus'), 'yellow')
69+
editFile('PreProcessors.vue', (code) =>
70+
code.replace('$color: yellow;', '$color: orange;')
71+
)
72+
await untilUpdated(() => getColor('p.pug-stylus'), 'orange')
73+
})
5974
})
6075

6176
describe('css modules', () => {

packages/plugin-vue/src/handleHotUpdate.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ export async function handleHotUpdate({
8888
const next = nextStyles[i]
8989
if (!prev || !isEqualBlock(prev, next)) {
9090
didUpdateStyle = true
91-
const mod = modules.find((m) => m.url.includes(`type=style&index=${i}`))
91+
const mod = modules.find(
92+
(m) =>
93+
m.url.includes(`type=style&index=${i}`) &&
94+
m.url.endsWith(`.${next.lang || 'css'}`)
95+
)
9296
if (mod) {
9397
affectedModules.add(mod)
9498
} else {

0 commit comments

Comments
 (0)