Skip to content
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

chore: shrink error messages shipped to client #11551

Merged
merged 6 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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/green-shrimps-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sveltejs/kit": patch
---

chore: shrink error messages shipped to client
6 changes: 3 additions & 3 deletions packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ function _before_navigate({ url, type, intent, delta }) {
...nav.navigation,
cancel: () => {
should_block = true;
nav.reject(new Error('navigation was cancelled'));
nav.reject(new Error('navigation cancelled'));
}
};

Expand Down Expand Up @@ -1206,7 +1206,7 @@ async function navigate({

// abort if user navigated during update
if (token !== nav_token) {
nav.reject(new Error('navigation was aborted'));
nav.reject(new Error('navigation aborted'));
return false;
}

Expand Down Expand Up @@ -1899,7 +1899,7 @@ function _start_router() {
...nav.navigation,
cancel: () => {
should_block = true;
nav.reject(new Error('navigation was cancelled'));
nav.reject(new Error('navigation cancelled'));
}
};

Expand Down
6 changes: 5 additions & 1 deletion packages/kit/src/utils/routing.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { BROWSER, DEV } from 'esm-env';

const param_pattern = /^(\[)?(\.\.\.)?(\w+)(?:=(\w+))?(\])?$/;

/**
Expand Down Expand Up @@ -65,7 +67,9 @@ export function parse_route_id(id) {
const match = param_pattern.exec(content);
if (!match) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could remove this whole block on the client side I think, the manifest generation would fail on this so it never gets here on the client.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you removed it altogether,
I don't remember the specifics but iirc the error during manifest generation comes from the same place, so it can only be removed in the client bundle.

const { pattern, params } = parse_route_id(id);

throw new Error(
`Invalid param: ${content}. Params and matcher names can only have underscores and alphanumeric characters.`
DEV || !BROWSER
? `Invalid param: ${content}. Params and matcher names can only have underscores and alphanumeric characters.`
: 'Invalid param'
);
}

Expand Down
8 changes: 5 additions & 3 deletions packages/kit/src/utils/url.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BROWSER } from 'esm-env';
import { BROWSER, DEV } from 'esm-env';

/**
* Matches a URI scheme. See https://www.rfc-editor.org/rfc/rfc3986#section-3.1
Expand Down Expand Up @@ -146,7 +146,9 @@ export function make_trackable(url, callback, search_params_callback) {
};
}

disable_hash(tracked);
if (DEV || !BROWSER) {
disable_hash(tracked);
}

return tracked;
}
Expand All @@ -155,7 +157,7 @@ export function make_trackable(url, callback, search_params_callback) {
* Disallow access to `url.hash` on the server and in `load`
* @param {URL} url
*/
export function disable_hash(url) {
function disable_hash(url) {
allow_nodejs_console_log(url);

Object.defineProperty(url, 'hash', {
Expand Down
Loading