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

[Bug]: Instantiating a component with new is no longer valid in Svelte 5. #24886

Closed
allozaur opened this issue Nov 17, 2023 · 3 comments · Fixed by #24889
Closed

[Bug]: Instantiating a component with new is no longer valid in Svelte 5. #24886

allozaur opened this issue Nov 17, 2023 · 3 comments · Fixed by #24889

Comments

@allozaur
Copy link

allozaur commented Nov 17, 2023

Describe the bug

Just created an empty SvelteKit Library project with Beta version of Svelte 5 enabled and installed Storybook.

This is what i get when viewing demo component stories:

Zrzut ekranu 2023-11-17 o 11 48 09

To Reproduce

pnpm create svelte

Choose Svelte 5 beta.

pnpm dlx storybook@latest init

System

No response

Additional context

I managed to find that this particular code causes the error:

https://github.com/storybookjs/storybook/blob/main/code/renderers/svelte/src/render.ts#L69

According to docs, this:

let createdComponent = new PreviewRender({ target: canvasElement, props: { storyFn, storyContext, name, kind, showError } });

should be changed to this:

import { mount } from 'svelte';

function renderToCanvas({ storyFn, kind, name, showMain, showError, storyContext, forceRemount }, canvasElement) {

  // Rest of the code

  let createdComponent = mount(PreviewRender, { target: canvasElement, props: { storyFn, storyContext, name, kind, showError } });

  // Rest of the code
}
@JReinhold
Copy link
Contributor

JReinhold commented Nov 17, 2023

@benmccann is there a recommended approach to migrating this while still being compatible with Svelte 4?

I'd expect as soon as we try to do import { mount } from 'svelte' or import { createClassComponent } from 'svelte/legacy'; it will fail for all Svelte 4 users, unless you're planning on backporting svelte/legacy to Svelte 4?

I think we can make this work by doing version detection via svelte/package.json, but maybe you had a cleaner idea.

@JReinhold
Copy link
Contributor

Actually we're strongly proposing we make this a breaking change for Storybook 8.0 so we don't have to juggle multiple Svelte versions. The migration from Storybook 7 to 8 should be easy for users.

Do you have any input or objections @benmccann?

@allozaur
Copy link
Author

allozaur commented Nov 20, 2023

@JReinhold it seems that i have some early-working code for the Storybook Svelte 5 renderer with these changes.

Just tested the svelte-kit/skeleton-js sandbox and it worked just fine locally for me :)

Tomorrow i will try to test Svelte 5 code to see how stories look.

JReinhold added a commit to allozaur/storybook that referenced this issue Nov 22, 2023
JReinhold added a commit to allozaur/storybook that referenced this issue Dec 1, 2023
JReinhold added a commit that referenced this issue Dec 4, 2023
JReinhold added a commit that referenced this issue Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants