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 usage of deprecated <svelte:component> #29405

Open
wants to merge 7 commits into
base: next
Choose a base branch
from

Conversation

xeho91
Copy link

@xeho91 xeho91 commented Oct 19, 2024

I can't transfer the issue to this repository.

Closes storybookjs/addon-svelte-csf#212

Warning

Needs manual verification if this doesn't break Svelte v4

What I did

I removed usage of deprecated <svelte:component> - source of documented deprecation

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>

name before after diff z %
createSize 0 B 0 B 0 B - -
generateSize 77.6 MB 77.6 MB 0 B -0.5 0%
initSize 146 MB 146 MB 0 B -0.49 0%
diffSize 68.5 MB 68.5 MB 0 B 0.54 0%
buildSize 6.82 MB 6.82 MB 0 B -0.61 0%
buildSbAddonsSize 1.5 MB 1.5 MB 0 B -0.65 0%
buildSbCommonSize 195 kB 195 kB 0 B - 0%
buildSbManagerSize 1.85 MB 1.85 MB 0 B 0.5 0%
buildSbPreviewSize 271 kB 271 kB 0 B 0.49 0%
buildStaticSize 0 B 0 B 0 B - -
buildPrebuildSize 3.82 MB 3.82 MB 0 B -0.61 0%
buildPreviewSize 3 MB 3 MB 0 B 0.28 0%
testBuildSize 0 B 0 B 0 B - -
testBuildSbAddonsSize 0 B 0 B 0 B - -
testBuildSbCommonSize 0 B 0 B 0 B - -
testBuildSbManagerSize 0 B 0 B 0 B - -
testBuildSbPreviewSize 0 B 0 B 0 B - -
testBuildStaticSize 0 B 0 B 0 B - -
testBuildPrebuildSize 0 B 0 B 0 B - -
testBuildPreviewSize 0 B 0 B 0 B - -
name before after diff z %
createTime 7.5s 7.2s -360ms -0.66 -5%
generateTime 22.8s 20.8s -2s -57ms -1 -9.9%
initTime 16s 14.5s -1s -410ms -0.43 -9.7%
buildTime 8.8s 10.2s 1.3s 0.56 12.9%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 6.3s 6.6s 318ms -0.38 4.8%
devManagerResponsive 4.1s 4.1s -77ms -0.84 -1.9%
devManagerHeaderVisible 659ms 575ms -84ms -0.44 -14.6%
devManagerIndexVisible 745ms 643ms -102ms -0.32 -15.9%
devStoryVisibleUncached 1s 968ms -57ms -0.55 -5.9%
devStoryVisible 742ms 605ms -137ms -0.47 -22.6%
devAutodocsVisible 541ms 481ms -60ms -0.84 -12.5%
devMDXVisible 613ms 493ms -120ms -0.74 -24.3%
buildManagerHeaderVisible 585ms 524ms -61ms -0.94 -11.6%
buildManagerIndexVisible 595ms 534ms -61ms -1.03 -11.4%
buildStoryVisible 587ms 525ms -62ms -1.14 -11.8%
buildAutodocsVisible 489ms 499ms 10ms -0.38 2%
buildMDXVisible 487ms 486ms -1ms -0.4 -0.2%

Greptile Summary

This PR removes deprecated <svelte:component> usage in the SlotDecorator.svelte file, addressing compatibility with Svelte 5 while maintaining support for earlier versions.

  • Replaced <svelte:component> with direct component usage in code/renderers/svelte/src/components/SlotDecorator.svelte
  • Added version-specific logic for handling event listeners in Svelte versions below 5
  • Potential impact on Svelte v4 compatibility requires careful verification
  • Changes align with Svelte 5 best practices while attempting to maintain backward compatibility
  • Related to issue No CLI documentation that's helpful D: #212 in the addon-svelte-csf repository, improving Svelte renderer compatibility

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

@JReinhold JReinhold added the ci:daily Run the CI jobs that normally run in the daily job. label Oct 19, 2024
@JReinhold JReinhold self-assigned this Oct 19, 2024
@JReinhold JReinhold added maintenance User-facing maintenance tasks svelte labels Oct 19, 2024
Copy link

nx-cloud bot commented Oct 19, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit f028acb. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@JReinhold JReinhold changed the title fix(renderer/svelte): Resolve usage of deprecated <svelte:component> Svelte: Fix usage of deprecated <svelte:component> Oct 24, 2024
<div
style="margin: 3em;"
>
<decorator.component>
Copy link
Contributor

Choose a reason for hiding this comment

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

This exposes a bug in Testing Library Svelte and/or Svelte 4.

When you use <something.theComponent />, it will snapshot as that directly instead of what the component actually is, as we see in the diff here. I confirmed that it is unrelated to Storybook/Portable Stories and that it's only a problem in Svelte 4. I wrote this simple test setup:

// Wrapper.svelte
<div style="margin: 3em;">
  <slot />
</div>
// Inner.svelte
<script>
  export let stuff;
</script>

<stuff.Component> hello </stuff.Component>
// the.test.js
import { it, expect } from 'vitest';
import { render } from '@testing-library/svelte';
import Inner from './Inner.svelte';
import Wrapper from './Wrapper.svelte';

it('barebone', () => {
  render(Inner, { stuff: { Component: Wrapper }});
  expect(document.body).toMatchInlineSnapshot();
});

Using <stuff.Component> hello </stuff.Component> it had this weird flaw in the snapshot, using <svelte:component this={stuff.Component}>hello</svelte:component> it didn't.

I think this is okay honestly, not much we can do about it other than not fixing the warning here. Thoughts @yannbf @kasperpeulen?

Copy link
Member

Choose a reason for hiding this comment

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

It was discussed with @JReinhold that he will try to apply version-dependent logic so that the decorator.Component is only used in Svelte 5

@JReinhold
Copy link
Contributor

@xeho91 I'm actually struggling to reproduce the original issue here. I have a project with:

And I can't get the warning to appear, even when adding decorators to stories.
That doesn't mean that this change isn't valid, but I was trying to create a workaround for #29405 (comment) and couldn't test if it worked, because I couldn't get the warning to show even in the base state.

Am I doing something wrong, or was this perhaps only an issue in the addon?

@xeho91
Copy link
Author

xeho91 commented Oct 29, 2024

@xeho91 I'm actually struggling to reproduce the original issue here. I have a project with:

And I can't get the warning to appear, even when adding decorators to stories. That doesn't mean that this change isn't valid, but I was trying to create a workaround for #29405 (comment) and couldn't test if it worked, because I couldn't get the warning to show even in the base state.

Am I doing something wrong, or was this perhaps only an issue in the addon?

No, I don't think you're wrong. I'm also not being able to reproduce this warning now.
I remember seeing them in Storybook dev mode, where it complained about SlotDecorator component.
I keep reverting to previous versions of Svelte, but I can't still trigger it. I tried <svelte:options runes={true} /> as well.

I confirmed that svelte_component_warning still exists, but it's not being triggered anymore.

@JReinhold
Copy link
Contributor

Alright, then let's keep this unmerged for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:daily Run the CI jobs that normally run in the daily job. maintenance User-facing maintenance tasks svelte
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Deprecation warnings for <svelte:component> with latest pre-release of svelte 5
3 participants