UI: Prevent docs page scroll reset on HMR re-render#35021
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughThe PR adds a conditional scroll-position reset to the docs rendering flow: ChangesScroll Reset Control in Docs Preparation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@code/addons/docs/template/stories/docs2/UtfSymbolScroll.mdx`:
- Around line 9-10: Fix the typo in the manual test text in UtfSymbolScroll.mdx
by replacing "T hat" with "That" in the sentence following the link "Click on
[link](`#anchor-with-utf-symbols-абвг`)" so the instruction reads "That will jump
scroll to anchor after green block below." Ensure only the whitespace/typo is
corrected and no other text is altered.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: aeda7c6e-3e4a-49e4-9e2c-96a28f73a245
📒 Files selected for processing (4)
code/addons/docs/template/stories/docs2/UtfSymbolScroll.mdxcode/core/src/preview-api/modules/preview-web/PreviewWithSelection.tsxcode/core/src/preview-api/modules/preview-web/View.tscode/core/src/preview-api/modules/preview-web/WebView.ts
|
Thank you so much for your contribution and your thorough proof-of-work videos! This is so helpful! |
Package BenchmarksCommit: The following packages have significant changes to their size or dependencies:
|
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 72 | 72 | 0 |
| Self size | 20.41 MB | 20.39 MB | 🎉 -13 KB 🎉 |
| Dependency size | 36.11 MB | 36.11 MB | 0 B |
| Bundle Size Analyzer | Link | Link |
@storybook/cli
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 203 | 203 | 0 |
| Self size | 908 KB | 908 KB | 🎉 -144 B 🎉 |
| Dependency size | 88.60 MB | 88.58 MB | 🎉 -13 KB 🎉 |
| Bundle Size Analyzer | Link | Link |
@storybook/codemod
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 196 | 196 | 0 |
| Self size | 32 KB | 32 KB | 0 B |
| Dependency size | 87.08 MB | 87.07 MB | 🎉 -13 KB 🎉 |
| Bundle Size Analyzer | Link | Link |
create-storybook
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 73 | 73 | 0 |
| Self size | 1.08 MB | 1.08 MB | 0 B |
| Dependency size | 56.52 MB | 56.50 MB | 🎉 -13 KB 🎉 |
| Bundle Size Analyzer | node | node |
UI: Prevent docs page scroll reset on HMR re-render (cherry picked from commit f0f3863)
Closes #26060
What I did
Fixed a bug where hot-reloading a story or MDX file while scrolled down on a docs page
causes the page to jump back to the top.
WebView.prepareForDocs()was unconditionally resettingscrollTop/scrollLeftto 0 on every docs render, including HMR re-renders. The scroll reset is only appropriate when navigating to a new docs page (story or view mode changed), not when the same page reloads due to HMR.Fix:
scrollResetoption toprepareForDocs()(defaulting totruefor backwards compatibility).PreviewWithSelectionnow passesscrollReset: storyIdChanged || viewModeChanged, so scroll only resets on actual navigation, not HMR.Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
Caution
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
a trivial change (add a space or letter), then save
Also verify normal navigation still resets scroll correctly:
Video Demo
Before Fix
bug_replicate_1mp4.mp4
bug_replicate_2.mp4
After Fix
hot_reload_bug_fix.mp4
Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal,ci:mergedorci:dailyGH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli-storybook/src/sandbox-templates.tsMake 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/coreteam 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
Documentation
Bug Fixes