Skip to content
Closed
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/fix-trailing-slash-error-boundary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: preserve trailing slash when error boundary truncates branch
2 changes: 1 addition & 1 deletion packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ async function initialize(result, target, hydrate) {
*/
function get_navigation_result_from_branch({ url, params, branch, status, error, route, form }) {
/** @type {import('types').TrailingSlash} */
let slash = 'never';
let slash = error ? 'ignore' : 'never';

// if `paths.base === '/a/b/c`, then the root route is always `/a/b/c/`, regardless of
// the `trailingSlash` route option, so that relative paths to JS and CSS work
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
import { page } from '$app/state';
</script>

<h1>Error: {page.error?.message}</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { error } from '@sveltejs/kit';

export const trailingSlash = 'always';

export function load() {
error(500, 'trailing slash error test');
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
test.describe.configure({ mode: 'parallel' });

test.describe('a11y', () => {
test('resets focus', async ({ page, clicknav, browserName }) => {

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

View workflow job for this annotation

GitHub Actions / test-kit-cross-browser (18, windows-latest, chromium, dev)

flaky test: resets focus

retries: 2
const tab = browserName === 'webkit' ? 'Alt+Tab' : 'Tab';

await page.goto('/accessibility/a');
Expand All @@ -32,7 +32,7 @@
expect(await page.evaluate(() => document.documentElement.getAttribute('tabindex'))).toBe(null);
});

test('applies autofocus after a navigation', async ({ page, clicknav }) => {

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

View workflow job for this annotation

GitHub Actions / test-kit-cross-browser (18, windows-latest, chromium, dev)

flaky test: applies autofocus after a navigation

retries: 2
await page.goto('/accessibility/autofocus/a');

await clicknav('[href="/accessibility/autofocus/b"]', {
Expand Down Expand Up @@ -95,7 +95,7 @@
).toBe(0);
});

test('keepfocus works', async ({ page }) => {

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

View workflow job for this annotation

GitHub Actions / test-kit-svelte-async (build)

flaky test: keepfocus works

retries: 2
await page.goto('/keepfocus');

await Promise.all([
Expand Down Expand Up @@ -1069,7 +1069,7 @@
expect(requests.filter((r) => !r.includes('__route.js'))).toEqual([]);
});

test('responds to <form target="_blank"> submission with new tab', async ({ page }) => {

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

View workflow job for this annotation

GitHub Actions / test-kit-cross-browser (18, macOS-latest, webkit, dev)

flaky test: responds to <form target="_blank"> submission with new tab

retries: 2
await page.goto('/routing/form-target-blank');

let tabs = page.context().pages();
Expand All @@ -1083,7 +1083,7 @@
expect(tabs.length > 1);
});

test('responds to <button formtarget="_blank" submission with new tab', async ({ page }) => {

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

View workflow job for this annotation

GitHub Actions / test-kit-cross-browser (18, ubuntu-latest, firefox, build)

flaky test: responds to <button formtarget="_blank" submission with new tab

retries: 2
await page.goto('/routing/form-target-blank');

let tabs = page.context().pages();
Expand Down Expand Up @@ -1132,6 +1132,15 @@
expect(new URL(page.url()).pathname).toBe('/routing/trailing-slash/never');
await expect(page.locator('p')).toHaveText('/routing/trailing-slash/never');
});

test('trailing slash is preserved when error boundary truncates branch', async ({
page,
app
}) => {
await page.goto('/routing/trailing-slash');
await app.goto('/routing/trailing-slash/error/always-error/');
expect(new URL(page.url()).pathname).toBe('/routing/trailing-slash/error/always-error/');
});
});

test.describe('Shadow DOM', () => {
Expand Down
Loading