Skip to content

Commit 9b777cc

Browse files
committed
[fix] Silence unknown prop warnings coming from SvelteKit
This is a hack, but it's a working quick solution. Fixes #5980
1 parent eecbbfc commit 9b777cc

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

.changeset/tiny-pears-check.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
Silence unknown prop warnings coming from SvelteKit

packages/kit/src/runtime/client/client.js

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,22 @@ export function create_client({ target, base, trailing_slash }) {
268268
navigation_result.props.page.url = url;
269269
}
270270

271-
root.$set(navigation_result.props);
271+
if (import.meta.env.DEV) {
272+
// Nasty hack to silence harmless warnings the user can do nothing about
273+
const warn = console.warn;
274+
console.warn = (...args) => {
275+
if (
276+
args.length !== 1 ||
277+
!/<(Layout|Page)> was created with unknown prop '(data|errors)'/.test(args[0])
278+
) {
279+
warn(...args);
280+
}
281+
};
282+
root.$set(navigation_result.props);
283+
tick().then(() => (console.warn = warn));
284+
} else {
285+
root.$set(navigation_result.props);
286+
}
272287
} else {
273288
initialize(navigation_result);
274289
}
@@ -347,11 +362,30 @@ export function create_client({ target, base, trailing_slash }) {
347362

348363
page = result.props.page;
349364

350-
root = new Root({
351-
target,
352-
props: { ...result.props, stores },
353-
hydrate: true
354-
});
365+
if (import.meta.env.DEV) {
366+
// Nasty hack to silence harmless warnings the user can do nothing about
367+
const warn = console.warn;
368+
console.warn = (...args) => {
369+
if (
370+
args.length !== 1 ||
371+
!/<(Layout|Page)> was created with unknown prop '(data|errors)'/.test(args[0])
372+
) {
373+
warn(...args);
374+
}
375+
};
376+
root = new Root({
377+
target,
378+
props: { ...result.props, stores },
379+
hydrate: true
380+
});
381+
console.warn = warn;
382+
} else {
383+
root = new Root({
384+
target,
385+
props: { ...result.props, stores },
386+
hydrate: true
387+
});
388+
}
355389

356390
if (router_enabled) {
357391
const navigation = { from: null, to: new URL(location.href) };

0 commit comments

Comments
 (0)