-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix: preserve trailingSlash config when error boundary is above page node #15358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
danielalanbates
wants to merge
4
commits into
sveltejs:main
Choose a base branch
from
danielalanbates:fix/issue-13516
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+40
−4
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fca32df
fix: preserve trailingSlash config when error boundary is above page …
danielalanbates a0c9cad
Merge branch 'main' into fix/issue-13516
teemingc cb958e4
format
teemingc b30c5bd
Merge branch 'main' into fix/issue-13516
elliott-with-the-longest-name-on-github File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@sveltejs/kit': patch | ||
| --- | ||
|
|
||
| fix: preserve trailingSlash config when error boundary is above page node |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -635,9 +635,9 @@ async function initialize(result, target, hydrate) { | |
| * form?: Record<string, any> | null; | ||
| * }} opts | ||
| */ | ||
| function get_navigation_result_from_branch({ url, params, branch, status, error, route, form }) { | ||
| function get_navigation_result_from_branch({ url, params, branch, status, error, route, form, trailing_slash }) { | ||
| /** @type {import('types').TrailingSlash} */ | ||
| let slash = 'never'; | ||
| let slash = trailing_slash ?? '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 | ||
|
|
@@ -1197,13 +1197,21 @@ async function load_route({ id, invalidating, url, params, route, preload }) { | |
|
|
||
| const error_load = await load_nearest_error_page(i, branch, errors); | ||
| if (error_load) { | ||
| // preserve trailingSlash config from the full branch so that | ||
| // slicing the branch for error handling doesn't lose it (#13516) | ||
| let trailing_slash; | ||
| for (const node of branch) { | ||
| if (node?.slash !== undefined) trailing_slash = node.slash; | ||
| } | ||
|
Comment on lines
+1200
to
+1205
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's probably better to create a util for this so we don't repeat it so many times. It's currently repeated 3 times in the module. Maybe something like: /**
* @param {(import('./types.js').BranchNode | undefined)[]} branch
* @param {URL} url
* @returns {import('types').TrailingSlash}
*/
function get_trailing_slash(branch, url) {
// 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
if (base && (url.pathname === base || url.pathname === base + '/')) {
return 'always';
}
return branch.reduce((value, node) => {
return node?.slash ?? value;
}, /** @type {import('types').TrailingSlash} */ ('never'));
} |
||
|
|
||
| return get_navigation_result_from_branch({ | ||
| url, | ||
| params, | ||
| branch: branch.slice(0, error_load.idx).concat(error_load.node), | ||
| status, | ||
| error, | ||
| route | ||
| route, | ||
| trailing_slash | ||
| }); | ||
| } else { | ||
| return await server_fallback(url, { id: route.id }, error, status); | ||
|
|
@@ -2401,13 +2409,21 @@ export async function set_nearest_error_page(error, status = 500) { | |
|
|
||
| const error_load = await load_nearest_error_page(current.branch.length, branch, route.errors); | ||
| if (error_load) { | ||
| // preserve trailingSlash config from the full branch so that | ||
| // slicing the branch for error handling doesn't lose it (#13516) | ||
| let trailing_slash; | ||
| for (const node of branch) { | ||
| if (node?.slash !== undefined) trailing_slash = node.slash; | ||
| } | ||
|
|
||
| const navigation_result = get_navigation_result_from_branch({ | ||
| url, | ||
| params: current.params, | ||
| branch: branch.slice(0, error_load.idx).concat(error_load.node), | ||
| status, | ||
| error, | ||
| route | ||
| route, | ||
| trailing_slash | ||
| }); | ||
|
|
||
| current = navigation_result.state; | ||
|
|
||
7 changes: 7 additions & 0 deletions
7
packages/kit/test/apps/basics/src/routes/routing/trailing-slash/error-boundary/+page.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, 'deliberate error'); | ||
| } |
1 change: 1 addition & 0 deletions
1
packages/kit/test/apps/basics/src/routes/routing/trailing-slash/error-boundary/+page.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <p>This should not be visible</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSDoc type definition for
get_navigation_result_from_branchis missing thetrailing_slashparameter, causing TypeScript errors