From dd1528769003eecc1702684f7d79f61634f1c876 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 30 Dec 2021 20:59:03 +0000 Subject: [PATCH 1/2] add error getters in prod mode, at least for now --- packages/kit/src/runtime/client/renderer.js | 32 ++++++++--------- packages/kit/src/runtime/server/index.js | 32 ++++++++--------- .../kit/src/runtime/server/page/render.js | 34 +++++++++---------- 3 files changed, 46 insertions(+), 52 deletions(-) diff --git a/packages/kit/src/runtime/client/renderer.js b/packages/kit/src/runtime/client/renderer.js index dacc5aecde92..0b2ea28337b4 100644 --- a/packages/kit/src/runtime/client/renderer.js +++ b/packages/kit/src/runtime/client/renderer.js @@ -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]; diff --git a/packages/kit/src/runtime/server/index.js b/packages/kit/src/runtime/server/index.js index 2fe7037f9fba..86fa172a3195 100644 --- a/packages/kit/src/runtime/server/index.js +++ b/packages/kit/src/runtime/server/index.js @@ -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({ diff --git a/packages/kit/src/runtime/server/page/render.js b/packages/kit/src/runtime/server/page/render.js index 1a56cca95ccc..624fbcc11dfd 100644 --- a/packages/kit/src/runtime/server/page/render.js +++ b/packages/kit/src/runtime/server/page/render.js @@ -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 From 47ae305e76c6a508055932f369c4b7c497378274 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 30 Dec 2021 20:59:31 +0000 Subject: [PATCH 2/2] changeset --- .changeset/ten-hairs-perform.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/ten-hairs-perform.md diff --git a/.changeset/ten-hairs-perform.md b/.changeset/ten-hairs-perform.md new file mode 100644 index 000000000000..146394e2d7a2 --- /dev/null +++ b/.changeset/ten-hairs-perform.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +Add path/query error getters in prod mode