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
24 changes: 24 additions & 0 deletions packages/plugin-rsc/e2e/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1179,4 +1179,28 @@ function defineTest(f: Fixture) {
await expect(page.locator(selector)).toHaveCSS('color', color)
}
})

test('assets', async ({ page }) => {
await page.goto(f.url())
await waitForHydration(page)
await expect(
page.getByTestId('test-assets-server-import'),
).not.toHaveJSProperty('naturalWidth', 0)
await expect(
page.getByTestId('test-assets-client-import'),
).not.toHaveJSProperty('naturalWidth', 0)

async function testBackgroundImage(selector: string) {
const url = await page
.locator(selector)
.evaluate((el) => getComputedStyle(el).backgroundImage)
expect(url).toMatch(/^url\(.*\)$/)
const response = await page.request.get(url.slice(5, -2))
expect(response.ok()).toBeTruthy()
expect(response.headers()['content-type']).toBe('image/svg+xml')
}

await testBackgroundImage('.test-assets-server-css')
await testBackgroundImage('.test-assets-client-css')
})
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.test-assets-client-css {
background: url(./client-css.svg) no-repeat;
background-size: contain;
width: 20px;
height: 20px;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions packages/plugin-rsc/examples/basic/src/routes/assets/client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use client'

import './client.css'
import svg from './client.svg?no-inline'

export function TestAssetsClient() {
return (
<div style={{ display: 'flex', gap: '0.5rem', alignItems: 'center' }}>
<span>test-assets-client</span>
<img
src={svg}
data-testid="test-assets-client-import"
width="20"
height="20"
/>
<span className="test-assets-client-css" />
</div>
)
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.test-assets-server-css {
background: url(./server-css.svg) no-repeat;
background-size: contain;
width: 20px;
height: 20px;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions packages/plugin-rsc/examples/basic/src/routes/assets/server.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { TestAssetsClient } from './client'
import './server.css'
import svg from './server.svg?no-inline'

export function TestAssetsServer() {
return (
<>
<div style={{ display: 'flex', gap: '0.5rem', alignItems: 'center' }}>
<span>test-assets-server</span>
<img
src={svg}
data-testid="test-assets-server-import"
width="20"
height="20"
/>
<span className="test-assets-server-css" />
</div>
<TestAssetsClient />
</>
)
}
2 changes: 2 additions & 0 deletions packages/plugin-rsc/examples/basic/src/routes/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { TestHmrSharedClient } from './hmr-shared/client'
import { TestHmrSharedAtomic } from './hmr-shared/atomic/server'
import { TestCssQueries } from './css-queries/server'
import { TestImportMetaGlob } from './import-meta-glob/server'
import { TestAssetsServer } from './assets/server'

export function Root(props: { url: URL }) {
return (
Expand Down Expand Up @@ -87,6 +88,7 @@ export function Root(props: { url: URL }) {
<TestReactCache url={props.url} />
<TestCssQueries />
<TestImportMetaGlob />
<TestAssetsServer />
</body>
</html>
)
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-rsc/examples/basic/src/server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default async function handler(request: Request): Promise<Response> {
// `unsafe-eval` is required during dev since React uses eval for findSourceMapURL feature
`script-src 'self' 'nonce-${nonce}' ${import.meta.env.DEV ? `'unsafe-eval'` : ``};`,
`style-src 'self' 'unsafe-inline';`,
`img-src 'self' data:;`,
// allow blob: worker for Vite server ping shared worker
import.meta.hot && `worker-src 'self' blob:;`,
]
Expand Down
Loading