Skip to content

Builder-Vite: Disable Vite publicDir to prevent conflicts with Storybook's staticDirs#33703

Open
yatishgoel wants to merge 1 commit into
storybookjs:nextfrom
yatishgoel:fix/24627-vite-publicdir-conflicts
Open

Builder-Vite: Disable Vite publicDir to prevent conflicts with Storybook's staticDirs#33703
yatishgoel wants to merge 1 commit into
storybookjs:nextfrom
yatishgoel:fix/24627-vite-publicdir-conflicts

Conversation

@yatishgoel
Copy link
Copy Markdown
Contributor

@yatishgoel yatishgoel commented Jan 29, 2026

Closes #24627

What I did

Disabled Vite's default publicDir copying in the Storybook Vite builder config to prevent conflicts with
Storybook's staticDirs.

The Problem:
Vite automatically copies the publicDir (defaults to public/) to the build output root. This causes issues
when:

  • Users have files in public/ that conflict with Storybook's generated files (e.g., index.json)
  • Users configure staticDirs to place public assets elsewhere, but Vite still copies to root

The Fix:

  • Added publicDir: false to Storybook's Vite builder config
  • Users should use Storybook's staticDirs config to manage static assets instead
  • Added unit test to ensure this behavior is maintained

Example of the bug:

# Before fix: public/index.json overwrites Storybook's index.json                                               
storybook-static/index.json = {"broken": true}  ❌                                                              
                                                                                                                
# After fix: Storybook's index.json is preserved                                                                
storybook-static/index.json = {"v":5,"entries":{...}}  ✅         

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

Caution

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

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.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>

Summary by CodeRabbit

  • Bug Fixes

    • Fixed Vite builder configuration to prevent conflicts between public directory and static directories.
  • Tests

    • Added test coverage for file-based configuration handling in the Vite builder.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 29, 2026

📝 Walkthrough

Walkthrough

Adds publicDir: false configuration to the Vite builder's common config and includes a test case to verify the setting is applied when loading file-based configurations. This prevents the public directory from being served, avoiding conflicts with staticDirs.

Changes

Cohort / File(s) Summary
Vite Configuration with publicDir Flag
code/builders/builder-vite/src/vite-config.ts, code/builders/builder-vite/src/vite-config.test.ts
Adds publicDir: false to sbConfig in the common Vite configuration, with a corresponding test case verifying the setting is properly applied when loading file-based configs.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

✨ Finishing touches
  • 📝 Generate docstrings

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

@valentinpalkovic valentinpalkovic self-assigned this Feb 2, 2026
@valentinpalkovic valentinpalkovic added bug ci:normal Run our default set of CI jobs (choose this for most PRs). builder-vite labels Feb 2, 2026
@valentinpalkovic valentinpalkovic moved this to Empathy Queue (prioritized) in Core Team Projects Feb 2, 2026
@valentinpalkovic valentinpalkovic changed the title Fix: Disable Vite publicDir to prevent conflicts with Storybook's staticDirs Builder-Vite: Disable Vite publicDir to prevent conflicts with Storybook's staticDirs Feb 2, 2026
@valentinpalkovic valentinpalkovic added this to the 11 milestone Feb 2, 2026
@storybook-app-bot
Copy link
Copy Markdown

Package Benchmarks

Commit: f8fd78f, ran on 2 February 2026 at 13:34:05 UTC

The following packages have significant changes to their size or dependencies:

@storybook/cli

Before After Difference
Dependency count 183 183 0
Self size 776 KB 776 KB 0 B
Dependency size 67.55 MB 67.54 MB 🎉 -10 KB 🎉
Bundle Size Analyzer Link Link

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

Labels

BREAKING CHANGE bug builder-vite ci: do not merge ci:normal Run our default set of CI jobs (choose this for most PRs). Stale

Projects

Status: Empathy Queue (prioritized)

Development

Successfully merging this pull request may close these issues.

[Bug]: "../public" is always copied in the static build root even if I set it to go elsewhere

2 participants