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 HMR support for server layer imported SASS and SCSS #49534

Merged
merged 2 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/next/src/server/dev/hot-reloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ export default class HotReloader {
// components are tracked.
if (
key.startsWith('app/') &&
mod.resource?.endsWith('.css')
/\.(css|scss|sass)$/.test(mod.resource || '')
) {
const resourceKey = mod.layer + ':' + mod.resource
const prevHash =
Expand Down
53 changes: 53 additions & 0 deletions test/e2e/app-dir/app-css/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,59 @@ createNextDescribe(
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)
}
})
}
})

Expand Down