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

Experimental support for Svelte 5 #181

Merged
merged 246 commits into from
Jul 14, 2024
Merged

Conversation

xeho91
Copy link
Collaborator

@xeho91 xeho91 commented May 14, 2024

Caution

This is still a work in progress 🚧.
Breaking changes may occur at any time, so do not use it for other purposes than experimenting yet.

Credits


Additional goals

  1. Simplify the usage - align closer to regular CSF format, without extras
  2. Take advantage of the Svelte 5 features
  3. Improve examples demonstration

Resources

Tip

Call for contribution on the demo (by add missing or improving examples) to help us find potential issues. Some of them we can fix the next major version 🙏.


Breaking changes

  • Dropped support for webpack - See discussion [RFC] Official support for Svelte CSF storybook#27092
  • Removed <Meta /> component
  • Removed <Template /> component in favor of Svelte snippets
  • <Story /> components no longer has a prop autodocs, use tags={['autodocs']} instead
  • <Story /> components no longer has a prop source, we've revamped the behaviour
  • Removed codebase with support for Storybook < v7.4

New features

  1. Improved TypeScript experience - defineMeta({ ... }) - works in TypeScript and with JSDoc
  2. Added a function setTemplate to allow adding a default {#snippet children()} to all of the <Story> in the stories file.
  3. Added type helpers Args<typeof Story> and StoryContext<typeof Story> to get typings while creating Svelte v5 snippets outside the <Story />

TODO

  • Refactor of indexer.ts - it uses Svelte AST from svelte.compile to extract the data required for indexer
  • Refactor of parser:
    • move from estree-walker to zimmerframe,
    • use modernAst option in the svelte.compile
    • fix issues with parsing description from comment,
    • remove codebase related to <Meta> and <Template> component
  • Improve naming
  • Improve type-safety on the entire codebase
  • Migrate <Story> to use Svelte 5 features
  • Migrate addon's components context to use Svelte 5 runes instead of writable()
  • Update examples in stories/
  • Remove unused dependencies
  • Update tests
  • Improve error messages
    • compiler
    • parser
      • analyse
      • extract
    • runtime
  • Revamp prop source in component Story, see: Experimental support for Svelte 5 #181 (comment) and comment: Experimental support for Svelte 5 #181 (comment)
  • Update documentation:
    • Error messages in the ./ERRORS.md (below are the error categories):
      • PARSER_EXTRACT_SVELTE
      • PARSER_EXTRACT_COMPILED
      • PARSER_ANALYSE_DEFINE_META
      • PARSER_ANALYSE_STORY
    • Provide better examples in ./examples/ directory
    • Provide MIGRATION.md guide
    • Update README.md
    • CHANGELOG.md with migration guide, new prerequisites and breaking changes
    • Finish RFC

Issues

Legend:

  • 🔴 - serious - blocks usage at runtime
  • 🟡 - minor - doesn't block usage at runtime, nor releasing an experimental version to collect feedback

Related to tests

  1. 🟡 Tests emit error that the components should use render from svelte/render instead of mount - I'm not sure how to deal with this one yet. Perhaps using environment variable TEST?
  2. 🟡 Related to above. It seems we can't use setContext during the tests - we used' the render instead of mount, it will break while running vitest, AFAIK.
  3. 🟡 I can't find a way to inject other Vite plugin's transformation (from @storybook/vite-builder & @storybook/svelte-vite). Based the compiled output, I want to test the snippets which analyse/extract AST nodes from the compiled output. To see if creating appendix to the compiled output works as expected.

Related to runtime

  1. Actions tab doesn't work, I couldn't figure out whether is related to the breaking change that on:* should be replaced with on* (removed colon)
  2. Typings for args used in {#snippet children(args)} - no idea yet how to crack this one
  3. Setting the layout in export meta parameters is broken
  4. Importing the zimmerframe fails due to vite not being able to get exports correctly - current workaround to continue developing: manual override import to default in ./node_modules/zimmerframe/package.json.
  5. 🔴 Inserting HTML comments as description & <Story> doesn't work in the development mode - see: Experimental support for Svelte 5 #181 (comment)

Related to TypeScript

  1. 🟡 Stories with required children snippet, and not being explicitly set. See comment: Experimental support for Svelte 5 #181 (comment)
  2. 🟡 Experimental support for Svelte 5 #181 (comment)

📦 Published PR as canary version: 5.0.0--canary.181.26b0f68.0

✨ Test out this PR locally via:

npm install @storybook/addon-svelte-csf@5.0.0--canary.181.26b0f68.0
# or 
yarn add @storybook/addon-svelte-csf@5.0.0--canary.181.26b0f68.0

Version

Published prerelease version: v5.0.0-next.0

Changelog

💥 Breaking Change

🐛 Bug Fix

Authors: 4

@xeho91 xeho91 added the skip-release Preserve the current version when merged label May 14, 2024
This reverts commit 6e5ccae.
@JReinhold JReinhold changed the base branch from main to next May 14, 2024 07:07
@JReinhold JReinhold added enhancement New feature or request major Increment the major version when merged and removed skip-release Preserve the current version when merged labels May 14, 2024
@axel7083
Copy link

axel7083 commented Jul 11, 2024

@axel7083 looks like you upgraded all your Storybook dependencies but storybook. They need to be in sync. npx storybook@latest doctor can maybe help you.

Oh sorry I took for granted the depandabot branch, thanks for helping! Now this is going back to

=> Failed to build the preview
[vite-plugin-svelte] [plugin vite-plugin-svelte] ../node_modules/@storybook/addon-svelte-csf/dist/runtime/Story.svelte (12:24): C:/Users/axels/Documents/github/redhat/podman-desktop/node_modules/@storybook/addon-svelte-csf/dist/runtime/Story.svelte:12:24 `p` has already been declared

Tried with 5.0.0--canary.181.82ac172.0 but same result

@JReinhold JReinhold merged commit 2577ae1 into next Jul 14, 2024
7 checks passed
@shilman
Copy link
Member

shilman commented Jul 14, 2024

🚀 PR was released in v5.0.0-next.0 🚀

@shilman shilman added the prerelease This change is available in a prerelease. label Jul 14, 2024
@tsar-boomba
Copy link

Happy to see this get an official release! Glad I could help getting this kickstarted 😁 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request major Increment the major version when merged prerelease This change is available in a prerelease.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants