Skip to content
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: Fix decorators with slots #19987

Merged
merged 6 commits into from
Nov 30, 2022
Merged

Conversation

JReinhold
Copy link
Contributor

@JReinhold JReinhold commented Nov 28, 2022

#19671

This PR fixes a regression introduced in #19580 that broke decorators in Svelte. This is the second time we've had that regression, so I've added a comment explaining that the import is weird on purpose.
It also refactors the structure around Svelte decorators and preparing them a bit. The restructuring only contains minor fixes to the logic (fixing #19671), and is mostly about readability.

I've added a few stories that tests decorators in CI (see Chromatic), and I've tested that this restructuring still works with @storybook/addon-svelte-csf@next.

* Check if an object is a svelte component.
* @param obj Object
*/
function isSvelteComponent(obj: any) {
Copy link
Contributor Author

@JReinhold JReinhold Nov 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work in dev mode with Vite (and maybe with Webpack) because the component is an instance of an empty ProxyComponent instead.
I asked on the Svelte Discord for alternatives, but we haven't come up with any yet.
https://discord.com/channels/457912077277855764/1046174450749558895/1046174450749558895

} = storyFn();

// reactive, re-render on storyFn change
$: ({ Component, props = {}, on, Wrapper, WrapperData = {} } = storyFn());
Copy link
Contributor Author

@JReinhold JReinhold Nov 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe these Wrapper and WrapperData were causing the issue at #19671 , because they're never set, in decorators.ts they were called decorator and decoratorProps

@JReinhold JReinhold marked this pull request as ready for review November 29, 2022 12:19
@JReinhold JReinhold requested review from j3rem1e and a team November 29, 2022 12:19
Copy link
Contributor

@valentinpalkovic valentinpalkovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (not a vue expert at all, code-wise I haven't found any issues)

@JReinhold
Copy link
Contributor Author

LGTM (not a vue expert at all, code-wise I haven't found any issues)

Then it's good this is Svelte and not Vue 😂

@JReinhold JReinhold merged commit 2cb1e88 into next Nov 30, 2022
@JReinhold JReinhold deleted the jeppe/fix-svelte-decorators-slots branch November 30, 2022 11:34
@valentinpalkovic
Copy link
Contributor

For sure. xD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants