Skip to content

[Bug]: Vitest doesnt work with Svelte CSF when using the legacyTemplate option to support the old v4 API #30320

Open
@valentinpalkovic

Description

@valentinpalkovic

Describe the bug

The new v5 of the addon has a legacyTemplate option that allows users to keep using deprecated APIs (how to define stories) until they've successfully migrated to the new API.

The legacy support works by injecting a Vite plugin that has enforce: 'pre' that will behind the scenes, migrate the stories source to the new API.

This means it has to run as the very first plugin, before the Svelte plugin compiles the source to JS.
But in Vitest, the plugin is added after the Svelte plugin. This would have been fixed by enforce: 'pre', except the Svelte Vite plugin also uses enforce: 'pre', so that gets to go first because it is the first plugin in the list.

Workaround:
There's a fairly straight forward userland workaround right now.
When configuring the Storybook Vitest workspace, don't extend the existing Vite config, but instead copy it in manually to the definition, so that the user can add the storybookTest() plugin before the Svelte plugin

Reproduction link

Reproduction steps

No response

System

-

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions