kit icon indicating copy to clipboard operation
kit copied to clipboard

`$page.url.pathname` is inconsistent when using `paths.base`

Open UnlimitedBytes opened this issue 2 years ago • 1 comments

Describe the bug

While writing the reproduction for #10124 I discovered another bug in SvelteKit. When you set the paths.base inside svelte.config.js the app/stores's $page.url becomes inconsistent. When initially calling the base like http://example.com/base it will redirect your browser to http://example.com/base/ and $page.url will be set to that too. Anyway as soon as hydration kicks in the $page.url will be set to http://example.com/base even if the browser url bar still shows http://example.com/base/. As far as I can tell this behavior is only present at the root of the base. Sub Routes like http://example.com/base/about are always redirected to the none slash version and therefore don't seem to have this bug.

Reproduction

Repository showcasing the bug in code: https://github.com/UnlimitedBytes/sveltekit-paths-base-bug Because of the speed at which the hydration process happens it's very hard to see the change in $page.url by just looking at the current value. So I recommend you open up the source code viewer for the page and search for URL of the current site:. This will take you directly to the $page.url which is outputted. You can then see that the URL in the HTML source code ends with a slash while the URL displayed on the page (after hydration) doesn't contain an ending slash.

Logs

Not needed.

System Info

Not needed.

Severity

annoyance

Additional Information

Not needed.

UnlimitedBytes avatar Jun 08 '23 22:06 UnlimitedBytes

Possible duplicate/related to #9595

ghostdevv avatar Jun 09 '23 15:06 ghostdevv