Skip to content

[Bug]: setup-page-script's serialization overwrites global variables if window is logged #592

@vhfmag

Description

@vhfmag

Describe the bug

When serializing console.log/.error/etc. arguments, decirc calls setReplace when the depthLimit is hit or a circular reference is detected, which modifies the argument in place unless it's a non-configurable property with a getter.

That means that if window is logged, it ends up changing the value of global variables such as __STORYBOOK_ADDONS_CHANNEL__, which in turn leads to errors like page.evaluate: TypeError: channel.on is not a function.

To Reproduce

  1. Clone https://github.com/vhfmag/storybook-test-runner-serialization-bug
  2. Run pnpm install && pnpm test

System

│  Storybook Environment Info:
│

│  System:
│  OS: macOS 15.7.3
│  CPU: (12) arm64 Apple M4 Pro
│  Shell: 5.9 - /bin/zsh
│  Binaries:
│  Node: 22.22.0 - /Users/vhfmag/.volta/tools/image/node/22.22.0/bin/node
│  npm: 10.9.4 - /Users/vhfmag/.volta/tools/image/node/22.22.0/bin/npm
│  pnpm: 10.18.0 - /Users/vhfmag/.volta/bin/pnpm <----- active
│  Browsers:
│  Chrome: 143.0.7499.193
│  Safari: 18.6
│  npmPackages:
│  @storybook/addon-a11y: ^10.2.0-beta.0 => 10.2.0-beta.0
│  @storybook/addon-docs: ^10.2.0-beta.0 => 10.2.0-beta.0
│  @storybook/addon-onboarding: ^10.2.0-beta.0 => 10.2.0-beta.0
│  @storybook/addon-webpack5-compiler-swc: ^4.0.2 => 4.0.2
│  @storybook/react-webpack5: ^10.2.0-beta.0 => 10.2.0-beta.0
│  @storybook/test-runner: ^0.24.2 => 0.24.2
│  storybook: ^10.2.0-beta.0 => 10.2.0-beta.0

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions