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
45 changes: 43 additions & 2 deletions packages/plugin-rsc/e2e/starter.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, test } from '@playwright/test'
import { useFixture } from './fixture'
import { setupInlineFixture, useFixture, type Fixture } from './fixture'
import { defineStarterTest } from './starter'
import { waitForHydration } from './helper'
import { expectNoPageError, waitForHydration } from './helper'

test.describe('dev-default', () => {
const f = useFixture({ root: 'examples/starter', mode: 'dev' })
Expand Down Expand Up @@ -53,3 +53,44 @@ test.describe('build-development', () => {
expect(output).toContain('jsxDEV')
})
})

test.describe('duplicate loadCss', () => {
const root = 'examples/e2e/temp/duplicate-load-css'
test.beforeAll(async () => {
await setupInlineFixture({
src: 'examples/starter',
dest: root,
files: {
'src/root.tsx': {
edit: (s) =>
s.replace(
'</head>',
() =>
`\
{import.meta.viteRsc.loadCss()}
{import.meta.viteRsc.loadCss()}
</head>`,
),
},
},
})
})

test.describe('dev', () => {
const f = useFixture({ root, mode: 'dev' })
defineTest(f)
})

test.describe('build', () => {
const f = useFixture({ root, mode: 'build' })
defineTest(f)
})

function defineTest(f: Fixture) {
test('basic', async ({ page }) => {
using _ = expectNoPageError(page)
await page.goto(f.url())
await waitForHydration(page)
})
}
})
7 changes: 6 additions & 1 deletion packages/plugin-rsc/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1800,6 +1800,7 @@ export function vitePluginRscCss(

assert(this.environment.name === 'rsc')
const output = new MagicString(code)
let importAdded = false

for (const match of code.matchAll(
/import\.meta\.viteRsc\.loadCss\(([\s\S]*?)\)/dg,
Expand Down Expand Up @@ -1833,7 +1834,11 @@ export function vitePluginRscCss(
})`
} else {
const hash = hashString(importId)
if (!code.includes(`__vite_rsc_importer_resources_${hash}`)) {
if (
!importAdded &&
!code.includes(`__vite_rsc_importer_resources_${hash}`)
) {
importAdded = true
output.prepend(
`import * as __vite_rsc_importer_resources_${hash} from ${JSON.stringify(
importId,
Expand Down
Loading