-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Svelte island does not expect class prop by default, causing warning #5665
Comments
Just spent a time on this myself, without discovering an external workaround, but indeed tis is something apparently internal to Svelte...not to be fixed, as it's supposed to be a dev 'warning'' to 'help'. Someone ought to speak to them about the psychology of this, but the good thing is that it and others do go away for production. You can prove it to yourself by doing a build and then preview with your Astro project. Still agree well with @Princesseuh 's categorization... reference: sveltejs/svelte#4652 (comment) |
Just came here from a Google search, after a similar incident while using Astro + Svelte:
Not crazy bad or anything, but annoying, as I cannot even Is there a reason Astro must pass in a |
A dirty workaround could be the It looks like SvelteKit is already using a similar approach for filtering out the if (DEV) {
// Nasty hack to silence harmless warnings the user can do nothing about
const console_warn = console.warn;
console.warn = function warn(...args) {
if (
args.length === 1 &&
/<(Layout|Page|Error)(_[\w$]+)?> was created (with unknown|without expected) prop '(data|form)'/.test(
args[0]
)
) {
return;
}
console_warn(...args);
};
} |
Astro's hydration code passes a `class` prop to Svelte components, inducing Svelte to log a warning about an unknown prop. Preempting this by exporting a `class` prop from the Svelte component isn't a viable workaround since `class` is a reserved identifier in JS. This PR implements the console-filtering workaround suggested by @HiDeoo in withastro#5665, borrowing the `useConsoleFilter` approach from the [preact integration](https://github.com/withastro/astro/blob/a1c0cbe604c9f91cdc421b5606aab574999eba01/packages/integrations/preact/src/server.ts#L72-L94). It would probably be better to generalize console filtering so it could be shared across multiple integrations. Ideally there would be a way to handle this in Svelte, but as was pointed out in the issue thread even they resort to [similar cringe-inducing hackery](https://github.com/sveltejs/kit/blob/master/packages/kit/src/runtime/client/client.js#L1974-L1996) in sveltekit.
* Filter out Svelte's unexpected class prop console warnings Astro's hydration code passes a `class` prop to Svelte components, inducing Svelte to log a warning about an unknown prop. Preempting this by exporting a `class` prop from the Svelte component isn't a viable workaround since `class` is a reserved identifier in JS. This PR implements the console-filtering workaround suggested by @HiDeoo in #5665, borrowing the `useConsoleFilter` approach from the [preact integration](https://github.com/withastro/astro/blob/a1c0cbe604c9f91cdc421b5606aab574999eba01/packages/integrations/preact/src/server.ts#L72-L94). It would probably be better to generalize console filtering so it could be shared across multiple integrations. Ideally there would be a way to handle this in Svelte, but as was pointed out in the issue thread even they resort to [similar cringe-inducing hackery](https://github.com/sveltejs/kit/blob/master/packages/kit/src/runtime/client/client.js#L1974-L1996) in sveltekit. * Only filter Svelte console warnings in dev builds * Add changeset * Fix lint error. --------- Co-authored-by: bluwy <[email protected]> Co-authored-by: Nate Moore <[email protected]>
What version of
astro
are you using?1.7.2
Are you using an SSR adapter? If so, which one?
None
What package manager are you using?
npm
What operating system are you using?
Mac
Describe the Bug
A lot of work has already gone into passing Astro classes to Svelte islands (#5397, #5112), currently it seems the default behaviour is to pass the scoped classname as a prop (class="astro-VFKJLXQS"). However, Svelte components by default don't expect this prop unless explicitly used in the Svelte component. This causes a console warning:
<Example> was created with unknown prop 'class'
.I'm hesitant to bring it up because it seems like more of a Svelte issue than an Astro one, but it does cause unexpected warnings which can be considered bad DX.
Thanks guys!
Link to Minimal Reproducible Example
https://codesandbox.io/p/sandbox/sweet-james-kxt2e3
Participation
The text was updated successfully, but these errors were encountered: