Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test: add e2e
  • Loading branch information
hi-ogawa committed Oct 2, 2025
commit 747a98c4d41fd953c01f32140d123032238c5ed1
23 changes: 23 additions & 0 deletions playground/hmr/__tests__/hmr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1107,4 +1107,27 @@ if (!isBuild) {
await loadPromise
}, [/connected/, 'a.js'])
})

test('deduplicate server rendered link stylesheet', async () => {
await page.goto(viteTestUrl + '/css-link/index.html')
await expect.poll(() => getColor('.test-css-link')).toBe('orange')

// remove color
editFile('css-link/styles.css', (code) =>
code.replace('color: orange;', '/* removed */'),
)
await expect.poll(() => getColor('.test-css-link')).toBe('black')

// add color
editFile('css-link/styles.css', (code) =>
code.replace('/* removed */', 'color: blue;'),
)
await expect.poll(() => getColor('.test-css-link')).toBe('blue')

// // remove css import from js
editFile('css-link/main.js', (code) =>
code.replace(`import './styles.css'`, ``),
)
await expect.poll(() => getColor('.test-css-link')).toBe('black')
})
}
2 changes: 2 additions & 0 deletions playground/hmr/css-link/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<div class="test-css-link">test-css-link</div>
<script type="module" src="./main.js"></script>
5 changes: 5 additions & 0 deletions playground/hmr/css-link/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import './styles.css'

if (import.meta.hot) {
import.meta.hot.accept()
}
26 changes: 26 additions & 0 deletions playground/hmr/css-link/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { normalizePath, type Plugin } from 'vite'

Check failure on line 1 in playground/hmr/css-link/plugin.ts

View workflow job for this annotation

GitHub Actions / Lint: node-22, ubuntu-latest

Member 'Plugin' of the import declaration should be sorted alphabetically
import path from 'node:path'

Check failure on line 2 in playground/hmr/css-link/plugin.ts

View workflow job for this annotation

GitHub Actions / Lint: node-22, ubuntu-latest

`node:path` import should occur before import of `vite`

// use plugin to simulate server rendered css link
export function TestCssLinkPlugin(): Plugin {
return {
name: 'test-css-link',
transformIndexHtml: {
handler(_html, ctx) {
if (!ctx.filename.endsWith('/css-link/index.html')) return
return [
{
tag: 'link',
attrs: {
rel: 'stylesheet',
href: '/css-link/styles.css',
'data-vite-dev-id': normalizePath(
path.resolve(import.meta.dirname, 'styles.css'),
),
},
},
]
},
},
}
}
3 changes: 3 additions & 0 deletions playground/hmr/css-link/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.test-css-link {
color: orange;
}
2 changes: 2 additions & 0 deletions playground/hmr/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'node:fs/promises'
import path from 'node:path'
import { defineConfig } from 'vite'
import type { Plugin } from 'vite'
import { TestCssLinkPlugin } from './css-link/plugin'

export default defineConfig({
experimental: {
Expand Down Expand Up @@ -37,6 +38,7 @@ export default defineConfig({
virtualPlugin(),
transformCountPlugin(),
watchCssDepsPlugin(),
TestCssLinkPlugin(),
],
})

Expand Down
Loading