RFC: Svelte 5 support #191
JReinhold
announced in
Announcements
Replies: 1 comment 1 reply
-
|
Thanks a ton @JReinhold for all the improvements that have been put into this addon. I have been playing around with a toy project and till now its working pretty well. When I was using this with test-runner, I think its still runs only with |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Addon Svelte CSF v5 RFC
In anticipation of the Svelte 5 release, we’ve re-imagined how the addon could improve by making use of the new features available in Svelte 5.
The purpose of this RFC is to share what we believe the future of the addon is and to collect feedback from the community. Everything described here is implemented in the latest prereleases of the addon, and can be used today. This doesn’t mean it’s set in stone, and we encourage anyone with feedback and ideas to come forward (otherwise why even have an RFC, right?). If there are significant or good suggestions, we’re very open to changing what we already have.
With the exception of the breaking changes listed below, the new version will be backwards compatible with the current API, under a
legacyTemplateflag. The current API will be deprecated in favor of the new API described below and in the README. The new API heavily depends on snippets, so it’s not possible to migrate to the new API before upgrading to Svelte 5.Please also check out the README on the
nextbranch for a complete description of the new API.To try out the new prereleases, upgrade your project to Svelte 5 and install the prereleases of this addon with
npm install --save-dev @storybook/addon-svelte-csf@next.Warning
Adding support for the legacy API isn’t done yet, it’s an ongoing process that will happen over the coming prereleases.
New API
1.
<Meta>component andexport metareplaced withdefineMetaBefore:
Or:
After:
A new
defineMetafunction has been introduced, to define the meta in any stories file:Difference:
Using this format allows for better type-safety, as the returned
Storycomponent has fully type-safe args.This might not be too interesting for users that don’t care about type-safety. However we believe that only having one API to define the meta instead of a type-safe and non-typed API would cause more confusion than it would solve.
2.
Storyslots replaced with snippetsBefore:
After:
Difference:
Using snippets also improves the type-safey of args. It also allows you to define multiple snippets and share them freely between stories however you like, by defining snippets top-level and passing them as the
childrenprop instead of the default slot.3.
Templatecomponent replaced with template snippetsSvelte has deprecated support for slots in favour of snippets. They indeed give us more flexibility, and with this, we have three ways of setting a template for our
<Story>components.Tip
It’s also no longer required to define a template, stories without templates will just render the component with args becoming props.
Before:
After:
{#snippet template(args)} <Button {...args}> Click me </Button> {/snippet} <Story name="Default" args={{ size: "medium" }} children={template} />The above can also be written as:
However, if you like to stop repeating yourself. We provide an alternative on how to set a template to every stories at once -
setTemplate:TypeScript support
By default, the following snippet from above example is untyped:
{#snippet sharedTemplate(args)} <!-- ^ args is typeof 'any'--> <Button {...args}> Click me </Button> {/snippet}We’ve created two type helpers,
ArgsandStoryContext, which you can import from this addon package:And then, we can use this type for out snippet:
Breaking Changes
1. Dropped Webpack support
The Svelte community has been converging on Vite for years in favor of Webpack, something we’ve also been seeing in Storybook usage. As this addon relies more and more on transformations via builder plugins, we’ve decided that now is a good time to drop support for Webpack and only support Vite-based Storybooks. This is a simple matter of prioritising time, only supporting Vite means we can focus more of our effort on improving the experience with new features and bug fixes.
2.
<Meta>component removedThe
<Meta>component has been removed, after being deprecated for 10 months. You can migrate to the current API withexport const metaor the newdefineMeta()API described above.3.
<Story>propautodocsremovedBefore:
After:
This aligns better with regular CSF, making it easier to follow the complete Storybook docs as reference.
4.
<Story>propsourcehas been removedBefore:
After:
We’ve been able to improve the default source generation a lot because of the new snippets syntax, and therefore the
sourceprop (as a boolean) shouldn’t be necessary anymore. You can still customize the generated source with the built-in parametersparameters.docs.source.codeandparameters.docs.source.transform. The string-based form of thesourceprop was in fact just a shorthand for thecodeparameter - streamlining this means fewer APIs to learn.Beta Was this translation helpful? Give feedback.
All reactions