Skip to content

Conversation

@valentinpalkovic
Copy link
Contributor

@valentinpalkovic valentinpalkovic commented Oct 9, 2025

Closes #32631

What I did

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

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 pull request has been released as version 0.0.0-pr-32678-sha-bda76dca. Try it out in a new sandbox by running npx [email protected] sandbox or in an existing project with npx [email protected] upgrade.

More information
Published version 0.0.0-pr-32678-sha-bda76dca
Triggered by @valentinpalkovic
Repository storybookjs/storybook
Branch valentin/fix-sb-mock-on-subpath-deployed-storybooks
Commit bda76dca
Datetime Thu Oct 9 08:03:09 UTC 2025 (1759996989)
Workflow run 18369640830

To request a new release of this pull request, mention the @storybookjs/core team.

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

Summary by CodeRabbit

  • Bug Fixes
    • The injected mocker script now loads via a relative URL (./...), fixing failures when the app is hosted in subdirectories, behind reverse proxies, or on custom/static bases.
    • No public interfaces were changed.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 9, 2025

📝 Walkthrough

Walkthrough

Replaced the injected module entry path from an absolute-like path /vite-inject-mocker-entry.js to a relative path ./vite-inject-mocker-entry.js in the Vite inject-mocker plugin. No other logic, templates, or exports changed.

Changes

Cohort / File(s) Summary of Changes
Vite inject mocker plugin
code/core/src/core-server/presets/vitePlugins/vite-inject-mocker/plugin.ts
Switched injected module entry path from "/vite-inject-mocker-entry.js""./vite-inject-mocker-entry.js". No other modifications.

Sequence Diagram(s)

(Skipped — change is a single-file path adjustment that does not alter control flow.)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch valentin/fix-sb-mock-on-subpath-deployed-storybooks

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a8b6fcd and 206a686.

📒 Files selected for processing (1)
  • code/core/src/core-server/presets/vitePlugins/vite-inject-mocker/plugin.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Adhere to ESLint and Prettier rules across all JS/TS source files

Files:

  • code/core/src/core-server/presets/vitePlugins/vite-inject-mocker/plugin.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Fix type errors and prefer precise typings instead of using any or suppressions, consistent with strict mode

Files:

  • code/core/src/core-server/presets/vitePlugins/vite-inject-mocker/plugin.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: normal
  • GitHub Check: Core Unit Tests, windows-latest
🔇 Additional comments (1)
code/core/src/core-server/presets/vitePlugins/vite-inject-mocker/plugin.ts (1)

14-14: LGTM! The fix correctly addresses the subpath deployment issue.

The change from an absolute path to a relative path ensures the script loads correctly when Storybook is deployed to a subpath. Relative paths resolve relative to the current document's location, whereas absolute paths would incorrectly resolve from the domain root.

Verify the fix in a deployed subpath environment.

Since the PR has no documented manual testing steps, please verify that:

  1. The fix resolves the issue described in [Bug]: SB10 - Module mocking does not work when accessing deployed Storybook in subpath route #32631 (module mocking works in subpath deployments).
  2. The fix doesn't break existing functionality (mocking still works in standard deployments and locally).
  3. The canary release (0.0.0-pr-32678-sha-bda76dca) can be tested in the failing scenario from the issue.

You can test the canary by following the reproduction steps from issue #32631 using the published canary version.


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

@ndelangen ndelangen changed the title Mocking: Fix sb.mock usage in Storybook's deployed in subpaths Mocking: Fix sb.mock usage in Storybook's deployed in subpaths Oct 9, 2025
@nx-cloud
Copy link

nx-cloud bot commented Oct 9, 2025

View your CI Pipeline Execution ↗ for commit 206a686

Command Status Duration Result
nx run-many -t check -c production --parallel=7 ✅ Succeeded 1s View ↗
nx run-many -t build -c production --parallel=3 ✅ Succeeded 2s View ↗

☁️ Nx Cloud last updated this comment at 2025-10-09 12:29:58 UTC

@valentinpalkovic valentinpalkovic force-pushed the valentin/fix-sb-mock-on-subpath-deployed-storybooks branch from a8b6fcd to 206a686 Compare October 9, 2025 11:37
@valentinpalkovic valentinpalkovic added the patch:yes Bugfix & documentation PR that need to be picked to main branch label Oct 9, 2025
@valentinpalkovic valentinpalkovic merged commit 25af7cd into next Oct 9, 2025
58 of 62 checks passed
@valentinpalkovic valentinpalkovic deleted the valentin/fix-sb-mock-on-subpath-deployed-storybooks branch October 9, 2025 12:27
ndelangen pushed a commit that referenced this pull request Oct 15, 2025
…bpath-deployed-storybooks

Mocking: Fix `sb.mock` usage in Storybook's deployed in subpaths
(cherry picked from commit 25af7cd)
@github-actions github-actions bot mentioned this pull request Oct 15, 2025
13 tasks
@ndelangen ndelangen mentioned this pull request Oct 16, 2025
13 tasks
@github-actions github-actions bot added the patch:done Patch/release PRs already cherry-picked to main/release branch label Oct 16, 2025
@ndelangen ndelangen mentioned this pull request Oct 16, 2025
3 tasks
@ndelangen ndelangen removed the patch:yes Bugfix & documentation PR that need to be picked to main branch label Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug ci:normal patch:done Patch/release PRs already cherry-picked to main/release branch test utilities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: SB10 - Module mocking does not work when accessing deployed Storybook in subpath route

3 participants