From 218617473bbf9ad6e1f4f91fc3125d658d1af8ea Mon Sep 17 00:00:00 2001 From: Nikhil Kothari Date: Sat, 23 Dec 2023 20:58:48 -0800 Subject: [PATCH 1/4] Filter out Svelte's unknown data prop warnings Fixes https://github.com/withastro/astro/issues/9508 The existing console filter looked for class attributes. This change adds a check for warnings related to data attributes as well. --- packages/integrations/svelte/client.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/integrations/svelte/client.js b/packages/integrations/svelte/client.js index 9e3df401915c..4bb7644d933a 100644 --- a/packages/integrations/svelte/client.js +++ b/packages/integrations/svelte/client.js @@ -104,9 +104,11 @@ function finishUsingConsoleFilter() { */ function filteredConsoleWarning(msg, ...rest) { if (consoleFilterRefs > 0 && typeof msg === 'string') { - // Astro passes a `class` prop to the Svelte component, which + // Astro passes `class` and `data-astro-cid` props to the Svelte component, which // outputs the following warning, which we can safely filter out. - const isKnownSvelteError = msg.endsWith("was created with unknown prop 'class'"); + const isKnownSvelteError = + msg.endsWith("was created with unknown prop 'class'") || + msg.indexOf("was created with unknown prop 'data-astro-cid") > 0; if (isKnownSvelteError) return; } originalConsoleWarning(msg, ...rest); From dbb687e31fdf4446b3005710c67d17f518a065cb Mon Sep 17 00:00:00 2001 From: Nikhil Kothari Date: Sat, 23 Dec 2023 21:46:06 -0800 Subject: [PATCH 2/4] Create changeset for fix to #9508 --- .changeset/forty-actors-wash.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/forty-actors-wash.md diff --git a/.changeset/forty-actors-wash.md b/.changeset/forty-actors-wash.md new file mode 100644 index 000000000000..4a5d79d0a625 --- /dev/null +++ b/.changeset/forty-actors-wash.md @@ -0,0 +1,5 @@ +--- +'@astrojs/svelte': patch +--- + +Filter out Svelte's unknown data prop warnings From 184ffb49eb23ec6cd00119df92bac149ee66df8d Mon Sep 17 00:00:00 2001 From: Nikhil Kothari Date: Sat, 23 Dec 2023 21:51:33 -0800 Subject: [PATCH 3/4] Add additional comment detail --- packages/integrations/svelte/client.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/integrations/svelte/client.js b/packages/integrations/svelte/client.js index 4bb7644d933a..4916f8105a46 100644 --- a/packages/integrations/svelte/client.js +++ b/packages/integrations/svelte/client.js @@ -106,6 +106,10 @@ function filteredConsoleWarning(msg, ...rest) { if (consoleFilterRefs > 0 && typeof msg === 'string') { // Astro passes `class` and `data-astro-cid` props to the Svelte component, which // outputs the following warning, which we can safely filter out. + + // NOTE: In practice data-astro-cid props have a hash suffix. Hence the use of a + // quoted prop name string without a closing quote. + const isKnownSvelteError = msg.endsWith("was created with unknown prop 'class'") || msg.indexOf("was created with unknown prop 'data-astro-cid") > 0; From ace47d4c3045c3523be628b37165a290796926ab Mon Sep 17 00:00:00 2001 From: Nikhil Kothari Date: Tue, 26 Dec 2023 16:12:06 -0800 Subject: [PATCH 4/4] Update client.js Switch from string.indexOf to string.includes. --- packages/integrations/svelte/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/integrations/svelte/client.js b/packages/integrations/svelte/client.js index 4916f8105a46..51d60ac8fcb2 100644 --- a/packages/integrations/svelte/client.js +++ b/packages/integrations/svelte/client.js @@ -112,7 +112,7 @@ function filteredConsoleWarning(msg, ...rest) { const isKnownSvelteError = msg.endsWith("was created with unknown prop 'class'") || - msg.indexOf("was created with unknown prop 'data-astro-cid") > 0; + msg.includes("was created with unknown prop 'data-astro-cid"); if (isKnownSvelteError) return; } originalConsoleWarning(msg, ...rest);