Skip to content

Commit 450dfc9

Browse files
fix
1 parent b04c703 commit 450dfc9

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

‎packages/start-server-core/src/transformAssetUrls.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,13 @@ export async function transformManifestAssets(
413413
if (route.assets) {
414414
for (const asset of route.assets) {
415415
if (asset.tag === 'link' && asset.attrs?.href) {
416+
const rel = asset.attrs.rel
417+
const relTokens = typeof rel === 'string' ? rel.split(/\s+/) : []
418+
419+
if (!relTokens.includes('stylesheet')) {
420+
continue
421+
}
422+
416423
const result = normalizeTransformAssetResult(
417424
await transformFn({
418425
url: asset.attrs.href,

‎packages/start-server-core/tests/transformAssets.test.ts‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,70 @@ describe('transformAssets', () => {
137137
})
138138
})
139139

140+
it('only treats stylesheet links in route.assets as stylesheet transforms', async () => {
141+
const transformFn = vi.fn(({ url }) => ({
142+
href: `https://cdn.example.com${url}`,
143+
}))
144+
145+
const manifest = await transformManifestAssets(
146+
{
147+
manifest: {
148+
routes: {
149+
__root__: {
150+
preloads: [],
151+
assets: [
152+
{
153+
tag: 'link',
154+
attrs: { rel: 'stylesheet preload', href: '/assets/app.css' },
155+
},
156+
{
157+
tag: 'link',
158+
attrs: { rel: 'icon', href: '/favicon.ico' },
159+
},
160+
],
161+
},
162+
},
163+
},
164+
clientEntry: '/assets/entry.js',
165+
},
166+
transformFn,
167+
{ clone: true },
168+
)
169+
170+
expect(transformFn).toHaveBeenCalledWith({
171+
kind: 'stylesheet',
172+
url: '/assets/app.css',
173+
})
174+
expect(transformFn).not.toHaveBeenCalledWith({
175+
kind: 'stylesheet',
176+
url: '/favicon.ico',
177+
})
178+
expect(manifest.routes.__root__?.assets).toEqual([
179+
{
180+
tag: 'link',
181+
attrs: {
182+
rel: 'stylesheet preload',
183+
href: 'https://cdn.example.com/assets/app.css',
184+
},
185+
},
186+
{
187+
tag: 'link',
188+
attrs: {
189+
rel: 'icon',
190+
href: '/favicon.ico',
191+
},
192+
},
193+
{
194+
tag: 'script',
195+
attrs: {
196+
type: 'module',
197+
async: true,
198+
},
199+
children: 'import("https://cdn.example.com/assets/entry.js")',
200+
},
201+
])
202+
})
203+
140204
describe('object shorthand', () => {
141205
it('supports { prefix } — same as string shorthand', () => {
142206
const config = resolveTransformAssetsConfig({

0 commit comments

Comments
 (0)