Skip to content

Commit

Permalink
fix: fix inline css hmr
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Dec 3, 2024
1 parent ea2a629 commit 1df4042
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/vite/src/node/server/environments/rolldown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
} from '../..'
import { CLIENT_ENTRY, VITE_PACKAGE_DIR } from '../../constants'
import { injectEnvironmentToHooks } from '../../build'
import { cleanUrl } from '../../../shared/utils'

const require = createRequire(import.meta.url)

Expand Down Expand Up @@ -141,6 +142,7 @@ class RolldownEnvironment extends DevEnvironment {
outputOptions!: rolldown.OutputOptions
lastModules: Record<string, string | null> = {}
newModules: Record<string, string | null> = {}
fileModuleIds = new Set<string>()
buildPromise?: Promise<void>

static createFactory(
Expand Down Expand Up @@ -266,6 +268,7 @@ class RolldownEnvironment extends DevEnvironment {
modules[id] = current
}
this.lastModules = modules
this.fileModuleIds = new Set(chunk.moduleIds.map((id) => cleanUrl(id)))

this.buildTimestamp = Date.now()
console.timeEnd(`[rolldown:${this.name}:build]`)
Expand Down Expand Up @@ -300,8 +303,7 @@ ${innerCode}
if (!this.result) {
return
}
const output = this.result.output[0]
if (!output.moduleIds.includes(ctx.file)) {
if (!this.fileModuleIds.has(ctx.file)) {
return
}
if (
Expand Down
6 changes: 4 additions & 2 deletions playground/rolldown-dev-react/__tests__/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ test.runIf(!isBuild)('hmr css', async () => {
.toBe('rgb(0, 0, 255)')
await page.getByRole('button', { name: 'Count: 1' }).click()

editFile('./src/test-style.css', (s) => s.replace('blue', 'green'))
editFile('./src/test-style-inline.css', (s) => s.replace('orange', 'green'))
await expect
.poll(() =>
page.locator('.test-style').evaluate((el) => getComputedStyle(el).color),
page
.locator('.test-style-inline')
.evaluate((el) => getComputedStyle(el).color),
)
.toBe('rgb(0, 128, 0)')
await page.getByRole('button', { name: 'Count: 2' }).click()
Expand Down

0 comments on commit 1df4042

Please sign in to comment.