UI: Keep preview frame stable in overall layout#33447
Conversation
|
View your CI Pipeline Execution ↗ for commit a48e809
☁️ Nx Cloud last updated this comment at |
📝 WalkthroughWalkthroughRestructures the Layout component's rendering logic by relocating PanelContainer from the desktop conditional branch to a separate condition, deferring MainContentMatcher rendering, and making notifications mobile-only. The component now conditionally renders PanelContainer based on Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes ✨ Finishing touches
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (5)**/*.{js,jsx,ts,tsx,json,md,html,css,scss}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
**/*.{js,jsx,json,html,ts,tsx,mjs}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
**/*.{ts,tsx}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
code/{core,lib,addons,builders,frameworks,presets}/**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
🧠 Learnings (1)📓 Common learnings⏰ 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). (5)
🔇 Additional comments (2)
Comment |
ndelangen
left a comment
There was a problem hiding this comment.
what an amazing improvement ❤️
Closes #32970, hopefully
What I did
I believe crashes occured because the preview element is positioned in different DOM trees between the mobile and desktop layouts, causing React to re-render it entirely when we open DevTools with the right layout.
This causes React to use its internal
restoreComponentfunction that attempts to restore a previously discarded element. Among other things, it attempts to restore focus. This is a useful heuristic per se, but in our case, the preview frame runs with Testing Library, and Testing Library'spatchedFocusmethod fails when called throughrestoreComponent. It appears a reference towindowhas gone stale in the meantime.I am not fixing the underlying issue in TL here, but rather, ensuring our preview stays stable when switching layouts. This circumvents the issue and improves performance and perceived speed by keeping the preview element mounted.
Checklist for Contributors
Testing
Manual testing
edit: Check #32970 for more info on reproduction if needed
Documentation
ø
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
✏️ Tip: You can customize this high-level summary in your review settings.