Skip to content

Core: Viewport UX fixes#33557

Merged
ghengeveld merged 9 commits into
nextfrom
viewport-fixes
Jan 19, 2026
Merged

Core: Viewport UX fixes#33557
ghengeveld merged 9 commits into
nextfrom
viewport-fixes

Conversation

@ghengeveld
Copy link
Copy Markdown
Member

@ghengeveld ghengeveld commented Jan 15, 2026

What I did

  • Ensure values on drag handles respect minimum viewport size
  • Update values on drag handles to account for zoom scale factor
  • Fix scrollIntoView when dragging
  • Prevent panel drag handle from rendering outside of container
  • Prevent floating point numbers on drag handles

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

    • Resizing enforces minimum dimensions, aborts invalid drags early, and applies correct final size when dragging ends.
  • Improvements

    • Edge-drag behavior and auto-scrolling are more reliable with edge tracking; drag handles show scaled, rounded dimensions and react to canvas scale changes.
    • Overlapping resizer behavior refined for panel placements.
  • Refactor

    • Layout sizing centralized via CSS-variable driven styles, simplifying component props.

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

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Jan 15, 2026

View your CI Pipeline Execution ↗ for commit 8fba269

Command Status Duration Result
nx run-many -t compile,check,knip,test,pretty-d... ✅ Succeeded 10m 42s View ↗

☁️ Nx Cloud last updated this comment at 2026-01-19 08:59:24 UTC

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 15, 2026

📝 Walkthrough

Walkthrough

Per-dimension, scale-aware viewport drag/resize with guarded drag-target tracking and clamped sizing; layout refactor to drive nav/right/bottom sizes via CSS custom properties and add overlapping-aware resizer behavior.

Changes

Cohort / File(s) Summary
Viewport resize & drag flow
code/core/src/manager/components/preview/Viewport.tsx
Adds dragScrollTarget to track dragged edge; early guards in onDrag; per-dimension clamped width/height updates with scale-aware data-value on handles; computes final size from element dims × scale on drag end; introduces memoized dimensions (frame & display) and uses it for styling/attributes; includes scale in deps.
Layout sizing & resizer behavior
code/core/src/manager/components/layout/Layout.tsx
Replaces numeric prop drilling with CSS custom properties (--nav-width, --right-panel-width, --bottom-panel-height) passed via style; narrows LayoutContainer and Drag props; computes grid sizing via CSS vars; adds overlapping flag affecting resizer geometry/behavior; updates PanelContainer/Drag styling and grid-area logic; imports CSSProperties.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

✨ Finishing touches
  • 📝 Generate docstrings

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@code/core/src/manager/components/preview/Viewport.tsx`:
- Around line 233-242: Clamp the minimums in logical (unscaled) units before
applying scale: when computing width/height in the drag handlers (use symbols
dragSide, dragStart, scale, targetRef, dragRefX, dragRefY, VIEWPORT_MIN_WIDTH,
VIEWPORT_MIN_HEIGHT), convert the raw pixel measurement to logical units by
dividing by scale, apply Math.max with VIEWPORT_MIN_*, then multiply back by
scale for the DOM size; set targetRef.current.style.width/height using the
scaled value and set dragRefX.current.dataset.value /
dragRefY.current.dataset.value to the logical value. Apply the same pattern to
the other drag blocks referenced (around the other occurrences noted).
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8486c72 and 4f956a4.

📒 Files selected for processing (1)
  • code/core/src/manager/components/preview/Viewport.tsx
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{js,jsx,ts,tsx,json,md,html,css,scss}

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

Format code using Prettier with yarn prettier --write <file>

Files:

  • code/core/src/manager/components/preview/Viewport.tsx
**/*.{js,jsx,json,html,ts,tsx,mjs}

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

Run ESLint checks using yarn lint:js:cmd <file> or the full command cross-env NODE_ENV=production eslint --cache --cache-location=../.cache/eslint --ext .js,.jsx,.json,.html,.ts,.tsx,.mjs --report-unused-disable-directives to fix linting errors before committing

Files:

  • code/core/src/manager/components/preview/Viewport.tsx
**/*.{ts,tsx}

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

Enable TypeScript strict mode across all packages

Files:

  • code/core/src/manager/components/preview/Viewport.tsx
**/*.{ts,tsx,js,jsx}

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

**/*.{ts,tsx,js,jsx}: Export functions from modules if they need to be tested
Do not use console.log, console.warn, or console.error directly unless in isolated files where importing loggers would significantly increase bundle size

Files:

  • code/core/src/manager/components/preview/Viewport.tsx
code/{core,lib,addons,builders,frameworks,presets}/**/*.{ts,tsx,js,jsx}

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

Use logger from storybook/internal/node-logger for server-side logging in Node.js code

Files:

  • code/core/src/manager/components/preview/Viewport.tsx
⏰ 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-generated
  • GitHub Check: nx
🔇 Additional comments (1)
code/core/src/manager/components/preview/Viewport.tsx (1)

279-279: Dependency update looks right.

Adding scale to the effect dependencies keeps drag math and dataset updates in sync with zoom changes.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment thread code/core/src/manager/components/preview/Viewport.tsx Outdated
@ghengeveld ghengeveld requested a review from ndelangen January 16, 2026 14:17
Comment thread code/core/src/manager/components/preview/Viewport.tsx Outdated
@storybook-app-bot
Copy link
Copy Markdown

storybook-app-bot Bot commented Jan 16, 2026

Package Benchmarks

Commit: f337cff, ran on 19 January 2026 at 09:31:47 UTC

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

@storybook/react-native-web-vite

Before After Difference
Dependency count 159 159 0
Self size 30 KB 30 KB 🚨 +8 B 🚨
Dependency size 23.00 MB 23.12 MB 🚨 +115 KB 🚨
Bundle Size Analyzer Link Link

@storybook/cli

Before After Difference
Dependency count 183 183 0
Self size 775 KB 775 KB 🚨 +139 B 🚨
Dependency size 67.38 MB 67.45 MB 🚨 +73 KB 🚨
Bundle Size Analyzer Link Link

@storybook/codemod

Before After Difference
Dependency count 176 176 0
Self size 30 KB 30 KB 🎉 -4 B 🎉
Dependency size 65.95 MB 66.03 MB 🚨 +73 KB 🚨
Bundle Size Analyzer Link Link

@ghengeveld ghengeveld requested a review from ndelangen January 17, 2026 09:50
Comment thread code/core/src/manager/components/layout/Layout.tsx
Comment thread code/core/src/manager/components/layout/Layout.tsx
@ghengeveld ghengeveld merged commit a9bb066 into next Jan 19, 2026
114 checks passed
@ghengeveld ghengeveld deleted the viewport-fixes branch January 19, 2026 09:41
@github-actions github-actions Bot mentioned this pull request Jan 19, 2026
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants