Skip to content

fix(svelte): keep PreviewRender dep-scan safe under Vite 8#34745

Open
mike-lmctl wants to merge 4 commits into
storybookjs:nextfrom
mike-lmctl:fix-svelte-vite8-depscan
Open

fix(svelte): keep PreviewRender dep-scan safe under Vite 8#34745
mike-lmctl wants to merge 4 commits into
storybookjs:nextfrom
mike-lmctl:fix-svelte-vite8-depscan

Conversation

@mike-lmctl
Copy link
Copy Markdown

@mike-lmctl mike-lmctl commented May 7, 2026

Closes #34304

What I did

PreviewRender.svelte now imports DecoratorHandler.svelte through the existing @storybook/svelte/internal/DecoratorHandler.svelte package export instead of a relative sibling path.

That keeps the dependency scanner out of the failing path where Vite 8/Rolldown sees PreviewRender.svelte through a virtual-module: importer and then tries to resolve ./DecoratorHandler.svelte from that virtual id.

I also added a small renderer test that checks PreviewRender.svelte uses the package export and does not add relative .svelte imports.

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

I checked the focused Vite 8/Rolldown scanner path from the issue with the Windows-style virtual importer:

  1. Before this change, the scanner reported: [UNRESOLVED_IMPORT] Could not resolve './DecoratorHandler.svelte' in virtual-module:.\node_modules\@storybook\svelte\static\PreviewRender.svelte?id=0
  2. After switching to the package export, the same scan completed successfully.

I also ran:

yarn vitest run --config code/renderers/svelte/vitest.config.ts code/renderers/svelte/src/internal-imports.test.ts

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-storybook/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.

Summary by CodeRabbit

  • Chores
    • Updated internal package imports to maintain compatibility with build system configurations.

Vite 8's Rolldown dep scanner can load Storybook's Svelte PreviewRender file
through a virtual-module id. A relative sibling .svelte import from that
virtual id is not resolved reliably, which prevents dependency prebundling in
the Storybook Vitest addon path.

Use the existing @storybook/svelte internal package export for
DecoratorHandler.svelte, matching the way PreviewRender.svelte itself is
loaded by callers. Add a focused renderer test so future changes do not
reintroduce relative .svelte imports in PreviewRender.svelte.

Tested: yarn vitest run --config code/renderers/svelte/vitest.config.ts code/renderers/svelte/src/internal-imports.test.ts
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 380e05e9-9867-470b-a35a-282c62f863f8

📥 Commits

Reviewing files that changed from the base of the PR and between 1501774 and f78bbf2.

📒 Files selected for processing (1)
  • code/renderers/svelte/static/PreviewRender.svelte
✅ Files skipped from review due to trivial changes (1)
  • code/renderers/svelte/static/PreviewRender.svelte

📝 Walkthrough

Walkthrough

PreviewRender.svelte changes its DecoratorHandler import from a relative sibling path to a package-internal import path. A comment documents that relative imports break under Vite 8 + Rolldown and the package export should remain stable for correct sibling .svelte resolution.

Changes

Svelte Internal Import Path Safety

Layer / File(s) Summary
Import Path Update
code/renderers/svelte/static/PreviewRender.svelte
DecoratorHandler import changes from ./DecoratorHandler.svelte to @storybook/svelte/internal/DecoratorHandler.svelte with an added comment documenting the change for Vite 8 + Rolldown compatibility.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related PRs

  • storybookjs/storybook#31476: Both PRs modify PreviewRender.svelte and touch the DecoratorHandler usage—this PR changes its import path while the related PR changes how DecoratorHandler is rendered.

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
code/renderers/svelte/src/internal-imports.test.ts (1)

25-27: ⚡ Quick win

Broaden the .svelte relative-import detection regex.

Current pattern misses side-effect imports like import './DecoratorHandler.svelte', so this test can pass with a relative .svelte import still present.

Suggested patch
-    const relativeSvelteImports = [
-      ...previewRender.matchAll(/from ['"](\.[^'"]+\.svelte)['"]/g),
-    ];
+    const relativeSvelteImports = [
+      ...previewRender.matchAll(
+        /import\s+(?:[^'"]+\s+from\s+)?['"](\.[^'"]+\.svelte)['"]/g
+      ),
+    ];
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@code/renderers/svelte/src/internal-imports.test.ts` around lines 25 - 27, The
test's regex used in previewRender.matchAll (assigned to relativeSvelteImports)
only detects imports that use "from '... .svelte'" and therefore misses
side-effect imports like import './DecoratorHandler.svelte'; update the regex so
it matches both import ... from '... .svelte' and bare side-effect imports
import '... .svelte' (i.e., broaden the pattern to allow either "from '...
.svelte'" or "import '... .svelte'") so relativeSvelteImports will find those
additional cases.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@code/renderers/svelte/src/internal-imports.test.ts`:
- Around line 25-27: The test's regex used in previewRender.matchAll (assigned
to relativeSvelteImports) only detects imports that use "from '... .svelte'" and
therefore misses side-effect imports like import './DecoratorHandler.svelte';
update the regex so it matches both import ... from '... .svelte' and bare
side-effect imports import '... .svelte' (i.e., broaden the pattern to allow
either "from '... .svelte'" or "import '... .svelte'") so relativeSvelteImports
will find those additional cases.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a53e3372-d45b-4045-b509-8cc94c865a8c

📥 Commits

Reviewing files that changed from the base of the PR and between 245043f and 1501774.

📒 Files selected for processing (2)
  • code/renderers/svelte/src/internal-imports.test.ts
  • code/renderers/svelte/static/PreviewRender.svelte

@JReinhold JReinhold self-assigned this May 7, 2026
@JReinhold JReinhold added bug svelte ci:daily Run the CI jobs that normally run in the daily job. labels May 7, 2026
Comment thread code/renderers/svelte/static/PreviewRender.svelte Outdated
@JReinhold
Copy link
Copy Markdown
Contributor

Thanks. Made a few modifications, will test it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-scan:automated bug ci:daily Run the CI jobs that normally run in the daily job. Stale svelte

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Storybook vitest addon breaks with Vite 8 + Svelte 5 — Rolldown dep scanner can't resolve .svelte imports

3 participants