storybookjs / storybook

Storybook is the industry standard workshop for building, documenting, and testing UI components in isolation
https://storybook.js.org
MIT License
83.77k stars 9.18k forks source link

[Bug]: Disabled toc in story produces error spam on scroll #27181

Open SetupCoding opened 3 months ago

SetupCoding commented 3 months ago

Describe the bug

Console error spam from toc (table of contents), if toc: { disable: true } is set and scrolling is triggered.

index-c882a240.js:442 Uncaught TypeError: Cannot read properties of undefined (reading 'querySelector')
    at Object.v [as updateToc] (index-c882a240.js:442:3110)
    at HTMLDocument.<anonymous> (index-c882a240.js:442:9940)
    at HTMLDocument.<anonymous> (index-c882a240.js:442:8472)

To Reproduce

https://stackblitz.com/edit/github-jmtuvf?file=.storybook%2Fpreview.ts,src%2Fstories%2FButton.stories.ts&preset=node

  1. Open the reproduction example
  2. See enabled toc in preview.tsx
  3. See disabled toc in Button.stories.ts
  4. Go to Storybook Button Docs page
  5. Open Dev tools
  6. Scroll down on the docs page
  7. See error spam in console stemming from toc query selector var oldActiveTocLink = tocElement.querySelector("." + options.activeLinkClass);
Uncaught TypeError: Cannot read properties of undefined (reading 'querySelector')
    at Object.updateToc (chunk-Z2YT5RER.js?v=aaea24c7:257:41)
    at HTMLDocument.<anonymous> (chunk-Z2YT5RER.js?v=aaea24c7:648:16)
    at HTMLDocument.<anonymous> (chunk-Z2YT5RER.js?v=aaea24c7:736:10)

System

Storybook Environment Info:

  System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.18.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm <----- active
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @storybook/addon-essentials: ^8.2.0-alpha.1 => 8.2.0-alpha.1 
    @storybook/addon-interactions: ^8.2.0-alpha.1 => 8.2.0-alpha.1 
    @storybook/addon-links: ^8.2.0-alpha.1 => 8.2.0-alpha.1 
    @storybook/addon-onboarding: ^8.2.0-alpha.1 => 8.2.0-alpha.1 
    @storybook/blocks: ^8.2.0-alpha.1 => 8.2.0-alpha.1 
    @storybook/react: ^8.2.0-alpha.1 => 8.2.0-alpha.1 
    @storybook/react-vite: ^8.2.0-alpha.1 => 8.2.0-alpha.1 
    @storybook/test: ^8.2.0-alpha.1 => 8.2.0-alpha.1 
    storybook: ^8.2.0-alpha.1 => 8.2.0-alpha.1

Additional context

Many thanks in advance!

SetupCoding commented 1 month ago

Any update on this?