Skip to content

Commit

Permalink
[fix] Silence unknown prop warnings coming from SvelteKit (#6071)
Browse files Browse the repository at this point in the history
This is a hack, but it's a working quick solution. Fixes #5980
  • Loading branch information
dummdidumm authored Aug 19, 2022
1 parent eecbbfc commit ad673a7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/tiny-pears-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Silence unknown prop warnings coming from SvelteKit
46 changes: 40 additions & 6 deletions packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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) };
Expand Down

0 comments on commit ad673a7

Please sign in to comment.