Skip to content
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
64 changes: 59 additions & 5 deletions packages/plugin-rsc/e2e/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,11 +632,15 @@

async function expectNoDuplicateServerCss(page: Page) {
// check only manually inserted stylesheet link exists
// (toHaveAttribute passes only when locator matches single element)
await expect(page.locator('link[rel="stylesheet"]')).toHaveAttribute(
'href',
'/test-style-server-manual.css',
)
await expect(page.locator('link[rel="stylesheet"]')).toHaveCount(3)
for (const locator of await page
.locator('link[rel="stylesheet"]')
.all()) {
await expect(locator).toHaveAttribute(
'data-precedence',
'test-style-manual-link',
)
}
}

test('no duplicate server css', async ({ page }) => {
Expand Down Expand Up @@ -719,7 +723,7 @@
'rgb(0, 0, 0)',
)
editor.reset()
await expect(page.locator('.test-style-server')).toHaveCSS(

Check failure on line 726 in packages/plugin-rsc/e2e/basic.test.ts

View workflow job for this annotation

GitHub Actions / test-rsc (macos-latest / webkit)

[webkit] › e2e/basic.test.ts:704:5 › dev-default › css hmr server

1) [webkit] › e2e/basic.test.ts:704:5 › dev-default › css hmr server ───────────────────────────── Error: Timed out 5000ms waiting for expect(locator).toHaveCSS(expected) Locator: locator('.test-style-server') Expected string: "rgb(255, 165, 0)" Received string: "rgb(0, 0, 0)" Call log: - Expect "toHaveCSS" with timeout 5000ms - waiting for locator('.test-style-server') 9 × locator resolved to <div class="test-style-server">test-style-server</div> - unexpected value "rgb(0, 0, 0)" 724 | ) 725 | editor.reset() > 726 | await expect(page.locator('.test-style-server')).toHaveCSS( | ^ 727 | 'color', 728 | 'rgb(255, 165, 0)', 729 | ) at /Users/runner/work/vite-plugin-react/vite-plugin-react/packages/plugin-rsc/e2e/basic.test.ts:726:56

Check failure on line 726 in packages/plugin-rsc/e2e/basic.test.ts

View workflow job for this annotation

GitHub Actions / test-rsc (macos-latest / chromium)

[chromium] › e2e/basic.test.ts:704:5 › dev-default › css hmr server

1) [chromium] › e2e/basic.test.ts:704:5 › dev-default › css hmr server ─────────────────────────── Error: Timed out 5000ms waiting for expect(locator).toHaveCSS(expected) Locator: locator('.test-style-server') Expected string: "rgb(255, 165, 0)" Received string: "rgb(0, 0, 0)" Call log: - Expect "toHaveCSS" with timeout 5000ms - waiting for locator('.test-style-server') 9 × locator resolved to <div class="test-style-server">test-style-server</div> - unexpected value "rgb(0, 0, 0)" 724 | ) 725 | editor.reset() > 726 | await expect(page.locator('.test-style-server')).toHaveCSS( | ^ 727 | 'color', 728 | 'rgb(255, 165, 0)', 729 | ) at /Users/runner/work/vite-plugin-react/vite-plugin-react/packages/plugin-rsc/e2e/basic.test.ts:726:56
'color',
'rgb(255, 165, 0)',
)
Expand Down Expand Up @@ -854,6 +858,56 @@
)
})

test('css url client @js', async ({ page }) => {
await page.goto(f.url())
await waitForHydration(page)
await expect(page.locator('.test-style-url-client')).toHaveCSS(
'color',
'rgb(255, 165, 0)',
)

if (f.mode !== 'dev') return

// test client css url HMR
await using _ = await expectNoReload(page)
const editor = f.createEditor('src/routes/style-client/client-url.css')
editor.edit((s) => s.replaceAll('rgb(255, 165, 0)', 'rgb(0, 165, 255)'))
await expect(page.locator('.test-style-url-client')).toHaveCSS(
'color',
'rgb(0, 165, 255)',
)
editor.reset()
await expect(page.locator('.test-style-url-client')).toHaveCSS(
'color',
'rgb(255, 165, 0)',
)
})

test('css url server @js', async ({ page }) => {
await page.goto(f.url())
await waitForHydration(page)
await expect(page.locator('.test-style-url-server')).toHaveCSS(
'color',
'rgb(255, 165, 0)',
)

if (f.mode !== 'dev') return

// test server css url HMR
await using _ = await expectNoReload(page)
const editor = f.createEditor('src/routes/style-server/server-url.css')
editor.edit((s) => s.replaceAll('rgb(255, 165, 0)', 'rgb(0, 165, 255)'))
await expect(page.locator('.test-style-url-server')).toHaveCSS(
'color',
'rgb(0, 165, 255)',
)
editor.reset()
await expect(page.locator('.test-style-url-server')).toHaveCSS(
'color',
'rgb(255, 165, 0)',
)
})

test('tailwind @js', async ({ page }) => {
await page.goto(f.url())
await waitForHydration(page)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,15 @@ export function TestCssQueriesClient(props: {
}) {
const [enabled, setEnabled] = React.useState(false)

function urlWithHmr(href: string) {
if (import.meta.hot) {
href += '?t=' + Date.now()
}
return href
}

return (
<div>
<button onClick={() => setEnabled(!enabled)}>test-css-queries</button>
{enabled && (
<>
<link rel="stylesheet" href={urlWithHmr(cssUrl)} />
<link rel="stylesheet" href={cssUrl} />
<style>{cssInline}</style>
<style>{cssRaw}</style>
<link rel="stylesheet" href={urlWithHmr(props.serverUrl)} />
<link rel="stylesheet" href={props.serverUrl} />
<style>{props.serverInline}</style>
<style>{props.serverRaw}</style>
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.test-style-url-client {
color: rgb(255, 165, 0);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import './client.css'
import { TestClientDep } from './client-dep'
import styles from './client.module.css'
import styleUrl from './client-url.css?url'

export function TestStyleClient() {
return (
Expand All @@ -11,6 +12,12 @@ export function TestStyleClient() {
<div data-testid="css-module-client" className={styles.client}>
test-css-module-client
</div>
<link
rel="stylesheet"
href={styleUrl}
precedence="test-style-manual-link"
/>
<div className="test-style-url-client">test-style-url-client</div>
<TestClientDep />
</>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.test-style-url-server {
color: rgb(255, 165, 0);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import './server.css'
import styles from './server.module.css'
import styleUrl from './server-url.css?url'

export function TestStyleServer() {
return (
Expand All @@ -8,10 +9,16 @@ export function TestStyleServer() {
<div data-testid="css-module-server" className={styles.server}>
test-css-module-server
</div>
<link
rel="stylesheet"
href={styleUrl}
precedence="test-style-manual-link"
/>
<div className="test-style-url-server">test-style-url-server</div>
<link
rel="stylesheet"
href="/test-style-server-manual.css"
precedence="test-style-server-manual"
precedence="test-style-manual-link"
/>
<div className="test-style-server-manual">test-style-server-manual</div>
</>
Expand Down
4 changes: 3 additions & 1 deletion packages/plugin-rsc/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,9 @@ export default function vitePluginRsc(
if (this.environment.name === 'client') {
// filter out `.css?direct` (injected by SSR) to avoid browser full reload
// when changing non-self accepting css such as `module.css`.
return ctx.modules.filter((m) => !m.id?.includes('?direct'))
return ctx.modules.filter(
(m) => !(m.id?.includes('?direct') && !m.isSelfAccepting),
)
Comment on lines +484 to +486
Copy link
Contributor Author

@hi-ogawa hi-ogawa Aug 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by targeting non self-accepting case specifically. This likely means HMR doesn't work for xxx.module.css?url, but let's just postpone dealing with that edge case.

}
}

Expand Down
Loading