Skip to content

Commit a2f23ca

Browse files
whataboutpereirabenmccannRich Harris
authored
fix: ensure styles are loaded in dev mode for routes containing special characters (#9894)
* Fix loading styles for routes containing special characters in dev mode. SvelteKit doesn't decode special characters in pathnames when loading CSS modules in dev mode, resulting in an error: Internal server error: Failed to load url /src/routes/(special)/hinnap%C3%A4ring/+page.svelte?svelte=&type=style&lang.css=&inline= (resolved id: /src/routes/(special)/hinnap%C3%A4ring/+page.svelte?svelte&type=style&lang.css). Does the file exist? Actual path: /src/routes/(special)/hinnapäring/ Fix by using decodeURI on the url.pathname when loading CSS modules. * Create stale-houses-yell.md * decodeURL inside if * add test --------- Co-authored-by: Ben McCann <[email protected]> Co-authored-by: Rich Harris <[email protected]>
1 parent 43b6786 commit a2f23ca

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

.changeset/stale-houses-yell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@sveltejs/kit": patch
3+
---
4+
5+
fix: ensure styles are loaded in dev mode for routes containing special characters

packages/kit/src/exports/vite/dev/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ export async function dev(vite, vite_config, svelte_config) {
186186
) {
187187
try {
188188
query.set('inline', '');
189-
const mod = await vite.ssrLoadModule(`${url.pathname}${url.search}${url.hash}`);
189+
const mod = await vite.ssrLoadModule(
190+
`${decodeURI(url.pathname)}${url.search}${url.hash}`
191+
);
190192
styles[dep.url] = mod.default;
191193
} catch {
192194
// this can happen with dynamically imported modules, I think
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<h1>this should be purple</h1>
2+
3+
<style>
4+
h1 {
5+
color: purple;
6+
}
7+
</style>

packages/kit/test/apps/basics/test/cross-platform/test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ test.describe('CSS', () => {
2929
expect(await get_computed_style('.not', 'color')).toBe('rgb(0, 0, 0)');
3030
});
3131
});
32+
33+
test('loads styles on routes with encoded characters', async ({ page, get_computed_style }) => {
34+
await page.goto('/css/encöded');
35+
expect(await get_computed_style('h1', 'color')).toBe('rgb(128, 0, 128)');
36+
});
3237
});
3338

3439
test.describe('Shadowed pages', () => {

0 commit comments

Comments
 (0)