diff --git a/.changeset/tiny-pears-check.md b/.changeset/tiny-pears-check.md new file mode 100644 index 000000000000..27f82ff1d55d --- /dev/null +++ b/.changeset/tiny-pears-check.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +Silence unknown prop warnings coming from SvelteKit diff --git a/packages/kit/src/runtime/client/client.js b/packages/kit/src/runtime/client/client.js index 08a0e2de083c..55e648dc975f 100644 --- a/packages/kit/src/runtime/client/client.js +++ b/packages/kit/src/runtime/client/client.js @@ -268,7 +268,22 @@ export function create_client({ target, base, trailing_slash }) { navigation_result.props.page.url = url; } - root.$set(navigation_result.props); + if (import.meta.env.DEV) { + // Nasty hack to silence harmless warnings the user can do nothing about + const warn = console.warn; + console.warn = (...args) => { + if ( + args.length !== 1 || + !/<(Layout|Page)> was created with unknown prop '(data|errors)'/.test(args[0]) + ) { + warn(...args); + } + }; + root.$set(navigation_result.props); + tick().then(() => (console.warn = warn)); + } else { + root.$set(navigation_result.props); + } } else { initialize(navigation_result); } @@ -347,11 +362,30 @@ export function create_client({ target, base, trailing_slash }) { page = result.props.page; - root = new Root({ - target, - props: { ...result.props, stores }, - hydrate: true - }); + if (import.meta.env.DEV) { + // Nasty hack to silence harmless warnings the user can do nothing about + const warn = console.warn; + console.warn = (...args) => { + if ( + args.length !== 1 || + !/<(Layout|Page)> was created with unknown prop '(data|errors)'/.test(args[0]) + ) { + warn(...args); + } + }; + root = new Root({ + target, + props: { ...result.props, stores }, + hydrate: true + }); + console.warn = warn; + } else { + root = new Root({ + target, + props: { ...result.props, stores }, + hydrate: true + }); + } if (router_enabled) { const navigation = { from: null, to: new URL(location.href) };