-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Filter out Svelte's unknown class prop console warnings #7291
Conversation
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.
🦋 Changeset detectedLatest commit: 6b59b4f The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
I know the console messages are irritating but I don't love console filtering as a general approach... if this is spreading to multiple renderer integrations, maybe we need to rethink how the Svelte renderer works? |
Yeah I'm not crazy about console filtering either, but if you decide it's worth it I've updated the PR with an |
FYI, you can export a let className;
export { className as class }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm personally fine with the patching to avoid the confusion in the logs, but will hold off merging before discussing with @natemoo-re first.
Sorry for the delay! I'm fine with merging this since it should help avoid confusion, appreciate the PR! |
Changes
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 sinceclass
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.It would probably be better to generalize the console filtering process 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 hackery in SvelteKit.
Note that you may need to clear your Vite cache to get this change to stick:
Testing
Create an Astro + Svelte project:
Run the project and observe the browser console's warning output:
Console output:
Apply the patch
Clear the vite cache:
Run the project and observe the browser console's (lack of) warning output:
Console output:
Docs
This is a non-breaking change that offers a minor quality of life improvement, not sure documentation beyond what's included in the source comments is necessary.