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

Prod mode page errors #3151

Merged
merged 2 commits into from Dec 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ten-hairs-perform.md
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Add path/query error getters in prod mode
32 changes: 15 additions & 17 deletions packages/kit/src/runtime/client/renderer.js
Expand Up @@ -445,24 +445,22 @@ export class Renderer {
if (!this.current.url || url.href !== this.current.url.href) {
result.props.page = { url, params };

if (import.meta.env.DEV) {
// TODO remove this for 1.0
/**
* @param {string} property
* @param {string} replacement
*/
const print_error = (property, replacement) => {
Object.defineProperty(result.props.page, property, {
get: () => {
throw new Error(`$page.${property} has been replaced by $page.url.${replacement}`);
}
});
};
// TODO remove this for 1.0
/**
* @param {string} property
* @param {string} replacement
*/
const print_error = (property, replacement) => {
Object.defineProperty(result.props.page, property, {
get: () => {
throw new Error(`$page.${property} has been replaced by $page.url.${replacement}`);
}
});
};

print_error('origin', 'origin');
print_error('path', 'pathname');
print_error('query', 'searchParams');
}
print_error('origin', 'origin');
print_error('path', 'pathname');
print_error('query', 'searchParams');
}

const leaf = filtered[filtered.length - 1];
Expand Down
32 changes: 15 additions & 17 deletions packages/kit/src/runtime/server/index.js
Expand Up @@ -43,24 +43,22 @@ export async function respond(incoming, options, state = {}) {
locals: {}
};

if (options.dev) {
// TODO remove this for 1.0
/**
* @param {string} property
* @param {string} replacement
*/
const print_error = (property, replacement) => {
Object.defineProperty(request, property, {
get: () => {
throw new Error(`request.${property} has been replaced by request.url.${replacement}`);
}
});
};
// TODO remove this for 1.0
/**
* @param {string} property
* @param {string} replacement
*/
const print_error = (property, replacement) => {
Object.defineProperty(request, property, {
get: () => {
throw new Error(`request.${property} has been replaced by request.url.${replacement}`);
}
});
};

print_error('origin', 'origin');
print_error('path', 'pathname');
print_error('query', 'searchParams');
}
print_error('origin', 'origin');
print_error('path', 'pathname');
print_error('query', 'searchParams');

try {
return await options.hooks.handle({
Expand Down
34 changes: 16 additions & 18 deletions packages/kit/src/runtime/server/page/render.js
Expand Up @@ -72,24 +72,22 @@ export async function render_response({
components: branch.map(({ node }) => node.module.default)
};

if (options.dev) {
// TODO remove this for 1.0
/**
* @param {string} property
* @param {string} replacement
*/
const print_error = (property, replacement) => {
Object.defineProperty(props.page, property, {
get: () => {
throw new Error(`$page.${property} has been replaced by $page.url.${replacement}`);
}
});
};

print_error('origin', 'origin');
print_error('path', 'pathname');
print_error('query', 'searchParams');
}
// TODO remove this for 1.0
/**
* @param {string} property
* @param {string} replacement
*/
const print_error = (property, replacement) => {
Object.defineProperty(props.page, property, {
get: () => {
throw new Error(`$page.${property} has been replaced by $page.url.${replacement}`);
}
});
};

print_error('origin', 'origin');
print_error('path', 'pathname');
print_error('query', 'searchParams');

// props_n (instead of props[n]) makes it easy to avoid
// unnecessary updates for layout components
Expand Down