Open kwchang0831 opened 2 years ago
Name your folder 初め
instead of %E5%88%9D%E3%82%81
and I expect it will work
If dev
and preview
are behaving differently from one another, this does sound like a bug of some sort to me.
I understand that a normal user probably wouldn't even use encoded URI as route name. That's counter-intuitive.
I found out this issue because I had problem when the folder is naming 初め
. That will only work in dev
but NOT preview
which describes in #7074. I was trying to see if there is another way to bypass the issue that prerender fails when routes contains unicode characters.
It renders correctly on the server, but something then happens on the client that makes it fail.
Yes, the first request is /%E5%88%9D%E3%82%81
, it renders correctly. Then, it immediately request /src/routes/%E5%88%9D%E3%82%81/+page.svelte
which fails with Not Found as end result.
The culprit is somewhere at https://github.com/sveltejs/kit/blob/5161241d523d47376525d73d1bb04a2d0b250972/packages/kit/src/exports/vite/dev/index.js#L257-L270 or https://github.com/sveltejs/kit/blob/5161241d523d47376525d73d1bb04a2d0b250972/packages/kit/src/exports/vite/dev/index.js#L294-L305 I believe - although it still doesn't work when I remove the decode there (which is probably there for good reason and shouldn't be removed anyway)
I wonder if https://github.com/sveltejs/kit/issues/7570 relates to this. I'm intrigued that a test with a route containing %40
(i.e. @
) works fine in dev mode - Vite is able to load the source for /routes/%40/+page.svelte
- but that a test with a route containing %5F
(i.e. _
) does not work in dev mode - the source code isn't returned, and instead SvelteKit attempts to do a route fallthrough and serve +page.svelte
in some other way. (You can see this in my failing test).
Is the difference all about how encodeUriComponent
and decodeUriComponent
work?
decodeURIComponent('%40'); // gives '@'
decodeURIComponent('%5F'); // gives '_'
encodeURIComponent('@'); // gives '%40'
encodeURIComponent('_'); // gives '_' <<<<<<<<<<<
Describe the bug
Routing result is Not Found if the route is encoded URI during dev server. eg: With route
src/routes/%E5%88%9D%E3%82%81/+page.svelte
when navigating tohttp://localhost:5173/%E5%88%9D%E3%82%81
However, preview works as expected. After
pnpm build && pnpm preview
, the routehttp://localhost:4173/%E5%88%9D%E3%82%81
is accessible.For the reference:
Reproduction
https://github.com/kwchang0831/issue-sveltekit-already-encoded-route
To Reproduce:
src/routes/%E5%88%9D%E3%82%81/+page.svelte
.export const prerender = true;
in+layout.ts
.pnpm dev
.http://localhost:5173/%E5%88%9D%E3%82%81
.Logs
No response
System Info
Severity
serious, but I can work around it
Additional Information
If the route name is
%E5%88
which is not a valid encoded URI, just a arbitrary string, it will result inURIError: URI malformed
when access the route.So, it seems like when handing route name, it assumes that the name is previously encoded or just to make sure the name is not encoded.