Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Setting nextjs.appDirectory to true causes error on 7.6.0 #25016

Closed
terrymun opened this issue Nov 28, 2023 · 0 comments · Fixed by #25032
Closed

[Bug]: Setting nextjs.appDirectory to true causes error on 7.6.0 #25016

terrymun opened this issue Nov 28, 2023 · 0 comments · Fixed by #25032

Comments

@terrymun
Copy link

terrymun commented Nov 28, 2023

Describe the bug

When upgrading from 7.5.3 to 7.6.0, I noticed that all my components are throwing an error:

Storybook preview hooks can only be called inside decorators and story functions.

Downgrading to 7.5.3 fixes the issue.

When attempting to

To Reproduce

There are some stories that import components dependent on the app router feature of Next.js. On versions 7.5.3 and below, this works without any issue:

import type { Preview } from '@storybook/react';

const preview: Preview = {
  parameters: {
    nextjs: {
      appDirectory: true,
      navigation: {
        pathname: '/',
        query: {},
      },
    },
  },
};

export default preview;

However, after upgrading to 7.6.0, any attempts to load any story will lead to this error:

Storybook preview hooks can only be called inside decorators and story functions.

You can see a live example of this error here: https://stackblitz.com/edit/github-i8rkrx-6doqzc

Screenshot 2023-11-28 at 17 00 05

Downgrading to 7.5.3 will cause this issue to go away: https://stackblitz.com/edit/github-i8rkrx-8encmk

Screenshot 2023-11-28 at 17 00 21

System

System:
  OS: macOS 14.1.1
  CPU: (10) arm64 Apple M1 Pro
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 18.18.2 - ~/.volta/tools/image/node/18.18.2/bin/node
  Yarn: 3.6.3 - ~/.volta/tools/image/yarn/1.22.19/bin/yarn <----- active
  npm: 9.8.1 - ~/.volta/tools/image/node/18.18.2/bin/npm
Browsers:
  Chrome: 119.0.6045.159
  Safari: 17.1
npmPackages:
  @storybook/addon-a11y: 7.6.0 => 7.6.0 
  @storybook/addon-essentials: 7.6.0 => 7.6.0 
  @storybook/addon-interactions: 7.6.0 => 7.6.0 
  @storybook/addon-mdx-gfm: 7.6.0 => 7.6.0 
  @storybook/addon-themes: 7.6.0 => 7.6.0 
  @storybook/blocks: 7.6.0 => 7.6.0 
  @storybook/core-server: 7.6.0 => 7.6.0 
  @storybook/jest: 0.2.3 => 0.2.3 
  @storybook/manager-api: 7.6.0 => 7.6.0 
  @storybook/nextjs: 7.6.0 => 7.6.0 
  @storybook/react: 7.6.0 => 7.6.0 
  @storybook/testing-library: 0.2.2 => 0.2.2 
  @storybook/theming: 7.6.0 => 7.6.0 
  chromatic: 9.1.0 => 9.1.0 
  eslint-plugin-storybook: 0.6.15 => 0.6.15 
  storybook-addon-swc: 1.2.0 => 1.2.0

Additional context

Removing nextjs.appDirectory: true will fix this warning, but it will cause all stories that import components that consume the app router to throw a new error:

invariant expected app router to be mounted
@terrymun terrymun changed the title [Bug]: Setting next.js.appDirectory to true causes error on 7.6.0 [Bug]: Setting nextjs.appDirectory to true causes error on 7.6.0 Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants