Skip to content

Commit a1f1e99

Browse files
hi-ogawaclaude
andauthored
test(rsc): use default CSS auto-injection in basic e2e fixture (#1058)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e8271c1 commit a1f1e99

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { test } from '@playwright/test'
2+
import { setupInlineFixture, useFixture } from './fixture'
3+
import { defineStarterTest } from './starter'
4+
5+
// Test `rscCssTransform: false` option which disables automatic CSS injection
6+
// and requires manual use of `import.meta.viteRsc.loadCss()`.
7+
8+
test.describe('manual-css', () => {
9+
const root = 'examples/e2e/temp/manual-css'
10+
11+
test.beforeAll(async () => {
12+
await setupInlineFixture({
13+
src: 'examples/starter',
14+
dest: root,
15+
files: {
16+
// Disable auto CSS injection
17+
'vite.config.ts': {
18+
edit: (s) => s.replace('rsc({', `rsc({ rscCssTransform: false,`),
19+
},
20+
// Add manual loadCss() call since auto-injection is disabled
21+
'src/root.tsx': {
22+
edit: (s) =>
23+
s.replace('</head>', `{import.meta.viteRsc.loadCss()}</head>`),
24+
},
25+
},
26+
})
27+
})
28+
29+
test.describe('dev', () => {
30+
const f = useFixture({ root, mode: 'dev' })
31+
defineStarterTest(f)
32+
})
33+
34+
test.describe('build', () => {
35+
const f = useFixture({ root, mode: 'build' })
36+
defineStarterTest(f)
37+
})
38+
})

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
import type React from 'react'
1010
import type { ReactFormState } from 'react-dom/client'
1111
import { parseRenderRequest } from './request.tsx'
12-
import '../styles.css'
1312

1413
// The schema of payload which is serialized into RSC stream on rsc environment
1514
// and deserialized on ssr/client environments.
@@ -125,8 +124,6 @@ async function handler(request: Request): Promise<Response> {
125124
const nonceMeta = nonce && <meta property="csp-nonce" nonce={nonce} />
126125
const root = (
127126
<>
128-
{/* this `loadCss` only collects `styles.css` but not css inside dynamic import `root.tsx` */}
129-
{import.meta.viteRsc.loadCss()}
130127
{nonceMeta}
131128
<Root url={url} />
132129
</>

packages/plugin-rsc/examples/basic/src/routes/root.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import '../styles.css'
12
import TestDepCssInServer from '@vitejs/test-dep-css-in-server/server'
23
import React from 'react'
34
import {
@@ -56,7 +57,6 @@ export function Root(props: { url: URL }) {
5657
<head>
5758
<meta charSet="utf-8" />
5859
<title>vite-rsc</title>
59-
{import.meta.viteRsc.loadCss('/src/routes/root.tsx')}
6060
</head>
6161
<body className="flex flex-col gap-2 items-start p-2">
6262
<div>

packages/plugin-rsc/examples/basic/vite.config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ export default defineConfig({
2828
ssr: './src/framework/entry.ssr.tsx',
2929
rsc: './src/framework/entry.rsc.tsx',
3030
},
31-
// disable auto css injection to manually test `loadCss` feature.
32-
rscCssTransform: false,
3331
copyServerAssetsToClient: (fileName) =>
3432
fileName !== '__server_secret.txt',
3533
clientChunks(meta) {

0 commit comments

Comments
 (0)