Skip to content

Docs: Fix MDX docs HMR when referenced CSF changes#34868

Open
tatakaisun wants to merge 1 commit into
storybookjs:nextfrom
tatakaisun:fix/29127-mdx-docs-hmr-repro
Open

Docs: Fix MDX docs HMR when referenced CSF changes#34868
tatakaisun wants to merge 1 commit into
storybookjs:nextfrom
tatakaisun:fix/29127-mdx-docs-hmr-repro

Conversation

@tatakaisun
Copy link
Copy Markdown

@tatakaisun tatakaisun commented May 21, 2026

Summary

Fix MDX docs render equality so referenced CSF file changes trigger a docs rerender.

Why

When an MDX docs page imports stories, the MDX module can remain unchanged while the referenced CSF module changes via HMR. The previous equality check only compared the MDX exports, so the docs render could be treated as unchanged.

Changes

  • Include referenced CSF files in MdxDocsRender.isEqual().
  • Add a unit test covering same MDX exports with changed referenced CSF files.

Testing

  • git diff --check
  • Targeted unit test not run locally because dependencies are not installed.

Known Issues

  • Full watch/HMR reproduction was not run in this environment.

Summary by CodeRabbit

  • Bug Fixes
    • Improved render equality checking to properly detect changes in referenced component story files, ensuring accurate content updates when source files are modified.

Review Change Stack

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

Fails
🚫 PR description is missing the mandatory "#### Manual testing" section. Please add it so that reviewers know how to manually test your changes.

Generated by 🚫 dangerJS against 623d0c6

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 21, 2026

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: 4cf0ea11-04b8-4386-8db1-d6c9922c7edf

📥 Commits

Reviewing files that changed from the base of the PR and between 3a16f34 and 623d0c6.

📒 Files selected for processing (2)
  • code/core/src/preview-api/modules/preview-web/render/MdxDocsRender.test.ts
  • code/core/src/preview-api/modules/preview-web/render/MdxDocsRender.ts

📝 Walkthrough

Walkthrough

MdxDocsRender.isEqual now accounts for CSF file referential changes when comparing render instances. The implementation checks that referenced CSF files match in length and by reference, and a new test validates that renders backed by different CSF files correctly report inequality.

Changes

CSF File Equality Checking

Layer / File(s) Summary
CSF file equality check in MdxDocsRender
code/core/src/preview-api/modules/preview-web/render/MdxDocsRender.ts, code/core/src/preview-api/modules/preview-web/render/MdxDocsRender.test.ts
MdxDocsRender.isEqual adds a sameReferencedCsfFiles comparison that validates length and per-index referential equality of CSF file arrays, and a new test verifies that renders with different CSF files report inequality.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Possibly related PRs

  • storybookjs/storybook#34111: Both PRs modify CSF file tracking behavior in MdxDocsRender—one restores attached CSF file references and the other updates equality checking to account for CSF file changes.

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.

@Sidnioulz Sidnioulz changed the title Fix MDX docs rerender when referenced CSF changes Docs: Fix MDX docs HMR when referenced CSF changes May 21, 2026
@Sidnioulz Sidnioulz requested a review from Copilot May 21, 2026 15:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes an HMR edge case for MDX docs pages that import CSF stories: when the referenced CSF module changes (via HMR) but the MDX module’s exports stay referentially equal, Storybook should still treat the docs render as changed and re-render.

Changes:

  • Extend MdxDocsRender.isEqual() to also compare referenced CSF files (not just MDX exports).
  • Add a unit test ensuring a referenced CSF change makes two docs renders unequal.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
code/core/src/preview-api/modules/preview-web/render/MdxDocsRender.ts Updates docs-render equality to include referenced CSF files so CSF HMR triggers a docs rerender.
code/core/src/preview-api/modules/preview-web/render/MdxDocsRender.test.ts Adds a regression test covering “same MDX exports, different referenced CSF file” equality behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@storybook-app-bot
Copy link
Copy Markdown

Package Benchmarks

Commit: 623d0c6, ran on 21 May 2026 at 15:59:33 UTC

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

@storybook/builder-webpack5

Before After Difference
Dependency count 184 184 0
Self size 79 KB 79 KB 🎉 -48 B 🎉
Dependency size 33.24 MB 33.34 MB 🚨 +94 KB 🚨
Bundle Size Analyzer Link Link

@storybook/ember

Before After Difference
Dependency count 188 188 0
Self size 15 KB 15 KB 🚨 +18 B 🚨
Dependency size 29.96 MB 30.06 MB 🚨 +94 KB 🚨
Bundle Size Analyzer Link Link

@storybook/nextjs

Before After Difference
Dependency count 534 534 0
Self size 662 KB 662 KB 0 B
Dependency size 61.37 MB 61.46 MB 🚨 +94 KB 🚨
Bundle Size Analyzer Link Link

@storybook/react-webpack5

Before After Difference
Dependency count 271 271 0
Self size 23 KB 23 KB 🚨 +12 B 🚨
Dependency size 45.91 MB 46.00 MB 🚨 +94 KB 🚨
Bundle Size Analyzer Link Link

@storybook/server-webpack5

Before After Difference
Dependency count 196 196 0
Self size 16 KB 16 KB 0 B
Dependency size 34.51 MB 34.60 MB 🚨 +94 KB 🚨
Bundle Size Analyzer Link Link

@storybook/preset-react-webpack

Before After Difference
Dependency count 164 164 0
Self size 18 KB 18 KB 0 B
Dependency size 32.25 MB 32.34 MB 🚨 +94 KB 🚨
Bundle Size Analyzer Link Link

@valentinpalkovic
Copy link
Copy Markdown
Contributor

Hi @tatakaisun,

Due to a recent high volume of unreviewed AI-generated PRs, we are requesting verification and proof that the implemented fix actually works. Please provide a simple GIF/Video or image of how the fix works, optimally with before-and-after comparisons.

Thank you for your understanding!

@tatakaisun
Copy link
Copy Markdown
Author

This PR only updates documentation/comments and does not change runtime behavior.

The changes clarify replay semantics in:

  • README
  • package documentation
  • Context.Sleep godoc

Verification performed:

  • go test ./...
  • git diff --check

No implementation logic or durable execution behavior was changed.

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

Projects

Status: Human verification

Development

Successfully merging this pull request may close these issues.

4 participants