Skip to content

Viewport: Skip viewport validation before parameters load#33794

Merged
valentinpalkovic merged 1 commit into
storybookjs:nextfrom
ia319:bug/33777-viewport-initial-globals-race-condition
Feb 9, 2026
Merged

Viewport: Skip viewport validation before parameters load#33794
valentinpalkovic merged 1 commit into
storybookjs:nextfrom
ia319:bug/33777-viewport-initial-globals-race-condition

Conversation

@ia319
Copy link
Copy Markdown
Member

@ia319 ia319 commented Feb 7, 2026

Closes #33777

What I did

Skip viewport validation when parameter is not yet available to prevent premature resets

Why

initialGlobals.viewport.value is validated before INITIAL_VIEWPORTS is loaded, causing valid viewports to be treated as invalid and reset.

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

Add the configuration to preview.ts:

import { INITIAL_VIEWPORTS } from "storybook/viewport";

const preview: Preview = {
  parameters: {
    viewport: {
      options: INITIAL_VIEWPORTS,
    },
  },
  initialGlobals: {
    viewport: {
      value: "iphone14",
      isRotated: true,
    },
  },
};

PS

If initialGlobals.viewport.value is not present in parameters.viewport.options, it is silently reset without warning or error.

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
    • Resolved an issue where viewport configuration could be applied before required parameters finished loading, ensuring stable initialization behavior.

@ia319 ia319 changed the title Viewport: Skip option validation when parameter not loaded to pr… Viewport: Skip viewport validation before parameters load Feb 7, 2026
@ia319 ia319 added ci:normal Run our default set of CI jobs (choose this for most PRs). bug labels Feb 7, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 7, 2026

📝 Walkthrough

Walkthrough

Updates a viewport hook to prevent processing when a parameter has not yet loaded, adding a guard condition and extending the dependency array to avoid race conditions with default values.

Changes

Cohort / File(s) Summary
Parameter Loading Guard
code/core/src/viewport/useViewport.ts
Adds early return and dependency array extension to prevent processing before parameter is loaded, avoiding race conditions with default MINIMAL_VIEWPORTS.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

✨ Finishing touches
  • 📝 Generate docstrings

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

@valentinpalkovic valentinpalkovic self-assigned this Feb 9, 2026
@valentinpalkovic valentinpalkovic moved this to In Progress in Core Team Projects Feb 9, 2026
@valentinpalkovic valentinpalkovic merged commit c617583 into storybookjs:next Feb 9, 2026
122 of 133 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Core Team Projects Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

addon: viewport bug ci:normal Run our default set of CI jobs (choose this for most PRs).

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug]: initialGlobals viewport does not apply in stories with Storybook ^1.2.0

2 participants