Unverified Commit d9b82a95 authored by Shu Ding's avatar Shu Ding Committed by GitHub

Fix HMR support for server layer imported SASS and SCSS (#49534)

Closes #43396.

https://github.com/vercel/next.js/issues/43396#issuecomment-1538638785
fix NEXT-684
parent 881d2029
...@@ -958,7 +958,7 @@ export default class HotReloader { ...@@ -958,7 +958,7 @@ export default class HotReloader {
// components are tracked. // components are tracked.
if ( if (
key.startsWith('app/') && key.startsWith('app/') &&
mod.resource?.endsWith('.css') /\.(css|scss|sass)$/.test(mod.resource || '')
) { ) {
const resourceKey = mod.layer + ':' + mod.resource const resourceKey = mod.layer + ':' + mod.resource
const prevHash = const prevHash =
......
...@@ -649,6 +649,59 @@ createNextDescribe( ...@@ -649,6 +649,59 @@ createNextDescribe(
await next.patchFile(filePath, origContent) await next.patchFile(filePath, origContent)
} }
}) })
it('should support HMR with sass/scss', async () => {
const filePath1 = 'app/css/sass/global.scss'
const origContent1 = await next.readFile(filePath1)
const filePath2 = 'app/css/sass/global.sass'
const origContent2 = await next.readFile(filePath2)
const browser = await next.browser('/css/sass/inner')
// .scss
expect(
await browser.eval(
`window.getComputedStyle(document.querySelector('#scss-server-layout')).color`
)
).toBe('rgb(222, 184, 135)')
// .sass
expect(
await browser.eval(
`window.getComputedStyle(document.querySelector('#sass-server-layout')).color`
)
).toBe('rgb(165, 42, 42)')
try {
await next.patchFile(
filePath1,
origContent1.replace('color: burlywood;', 'color: red;')
)
await check(
() =>
browser.eval(
`window.getComputedStyle(document.querySelector('#scss-server-layout')).color`
),
'rgb(255, 0, 0)'
)
} finally {
await next.patchFile(filePath1, origContent1)
}
try {
await next.patchFile(
filePath2,
origContent2.replace('color: brown', 'color: red')
)
await check(
() =>
browser.eval(
`window.getComputedStyle(document.querySelector('#sass-server-layout')).color`
),
'rgb(255, 0, 0)'
)
} finally {
await next.patchFile(filePath2, origContent2)
}
})
} }
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment