Skip to content

Commit 8a9e3f8

Browse files
committed
test: add e2e
1 parent 98e3c9c commit 8a9e3f8

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

packages/plugin-rsc/e2e/basic.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,24 @@ function defineTest(f: Fixture) {
637637
'rgb(255, 0, 0)',
638638
)
639639
})
640+
641+
test('tailwind no redundant server hmr', async ({ page }) => {
642+
await page.goto(f.url())
643+
await waitForHydration(page)
644+
const logs: string[] = []
645+
page.on('console', (msg) => {
646+
if (msg.type() === 'log') {
647+
logs.push(msg.text())
648+
}
649+
})
650+
f.createEditor('src/routes/tailwind/unused.tsx').resave()
651+
await page.waitForTimeout(200)
652+
f.createEditor('src/routes/tailwind/server.tsx').resave()
653+
await page.waitForTimeout(200)
654+
expect(logs).toEqual([
655+
expect.stringMatching(/\[vite-rsc:update\].*\/tailwind\/server.tsx/),
656+
])
657+
})
640658
})
641659

642660
test('temporary references @js', async ({ page }) => {

packages/plugin-rsc/e2e/fixture.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ export function useFixture(options: {
142142
reset(): void {
143143
fs.writeFileSync(filepath, originalFiles[filepath]!)
144144
},
145+
resave(): void {
146+
fs.writeFileSync(filepath, current)
147+
},
145148
}
146149
}
147150

packages/plugin-rsc/examples/basic/src/framework/entry.browser.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ async function main() {
7070

7171
// implement server HMR by trigering re-fetch/render of RSC upon server code change
7272
if (import.meta.hot) {
73-
import.meta.hot.on('rsc:update', () => {
73+
import.meta.hot.on('rsc:update', (e) => {
74+
console.log('[vite-rsc:update]', e.file)
7475
fetchRscPayload()
7576
})
7677
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
console.log('unused file text-[#f12345]')
1+
console.log(<div className="unused">unused</div>)

packages/plugin-rsc/src/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ export default function vitePluginRsc(
406406
importers.length > 0 &&
407407
importers.every((m) => m.id && isCSSRequest(m.id))
408408
) {
409-
return
409+
return []
410410
}
411411
}
412412

0 commit comments

Comments
 (0)