Skip to content
Draft
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
5 changes: 5 additions & 0 deletions .changeset/calm-route-styles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: resolve server-routed CSS against its route module
3 changes: 2 additions & 1 deletion packages/kit/src/runtime/server/page/server_routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,6 @@ function create_css_import(route, url, client) {

if (!css) return '';

return `${create_client_import(client.start, paths)}.then(x => x.load_css([${css}]));\n`;
// CSS paths are relative to this module, not the document we are navigating from.
return `${create_client_import(client.start, paths)}.then(x => x.load_css([${css}].map(p => new URL(p, import.meta.url).href)));\n`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@
}
});

test('Scroll position is correct after going back from a shallow route', async ({

Check warning on line 700 in packages/kit/test/apps/basics/test/playwright/cross-platform/client.test.js

View workflow job for this annotation

GitHub Actions / e2e (test:server-side-route-resolution:dev, js, 1/2)

flaky test: Scroll position is correct after going back from a shallow route

retries: 2
page,
scroll_to
}) => {
Expand All @@ -718,6 +718,45 @@
});

test.describe('CSS', () => {
for (const preload of [false, true]) {
test(`loads styles from a deeper page${preload ? ' after preloading code' : ''}`, async ({
page,
app
}) => {
await page.goto('/routing/rest/xyz/abc/qwe/deep');

if (preload) await app.preloadCode('/css/encöded');
await app.goto('/css/encöded');

await expect(page.locator('h1')).toHaveCSS('color', 'rgb(128, 0, 128)');
});
}

test('reuses server-rendered styles after preloading from a deeper page', async ({
page,
app
}) => {
test.skip(!!process.env.DEV);

await page.goto('/css/encöded');
const assets = await page
.locator('link[rel="stylesheet"]')
.evaluateAll((links) =>
links.map((link) => /** @type {HTMLLinkElement} */ (link).href.split('/').at(-1))
);
expect(assets.length).toBeGreaterThan(0);

await app.goto('/routing/rest/xyz/abc/qwe/deep');
await app.preloadData('/css/encöded');
await app.goto('/css/encöded');

await expect(page.locator('h1')).toHaveCSS('color', 'rgb(128, 0, 128)');
for (const asset of assets) {
// Compare filenames to also catch duplicate links with incorrectly resolved URLs.
await expect(page.locator(`link[rel="stylesheet"][href$="/${asset}"]`)).toHaveCount(1);
}
});

test('applies generated component styles (hides announcer)', async ({
page,
clicknav,
Expand Down
Loading