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]: Infinite Loading State When Using Dynamic Import Between Storybook Files #28382

Open
yuheiy opened this issue Jun 28, 2024 · 0 comments
Open

Comments

@yuheiy
Copy link
Contributor

yuheiy commented Jun 28, 2024

Describe the bug

In my project, I are using two different configurations of Storybook. One configuration uses the [name].stories.tsx file, while the other uses [name].test.stories.tsx. I encountered an issue when trying to dynamically import stories from [name].stories.tsx into [name].test.stories.tsx. While everything works fine during development, the build process results in an infinite loading state for the pages where this dynamic import is used.

When I open my Storybook, it shows a loading state

Reproduction link

https://github.com/yuheiy/storybook-issue-infinite-loading-state-when-using-dynamic-import-between-storybook-files

Reproduction steps

  1. Set up a project with two Storybook configurations:
    • One using [name].stories.tsx file.
    • Another using [name].test.stories.tsx file.
  2. Use dynamic import in the [name].test.stories.tsx to load stories from [name].stories.tsx.

Button.stories.ts:

import type { Meta, StoryObj } from '@storybook/react';
import { Button } from './Button';

const meta = {
  title: 'Button',
  component: Button,
} satisfies Meta<typeof Button>;

export default meta;
type Story = StoryObj<typeof meta>;

export const Primary: Story = {
  args: {
    primary: true,
    label: 'Button',
  },
};

Button.test.stories.ts:

import type { Meta, StoryObj } from '@storybook/react';
import { Button } from './Button';

const meta = {
  title: 'Button',
  component: Button,
} satisfies Meta<typeof Button>;

export default meta;
type Story = StoryObj<typeof meta>;

export const Primary: Story = {
  ...(await import('./Button.stories')).Primary,
};

System

Storybook Environment Info:

  System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M1 Max
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.13.1 - ~/.nvm/versions/node/v20.13.1/bin/node
    npm: 10.5.2 - ~/.nvm/versions/node/v20.13.1/bin/npm <----- active
  Browsers:
    Chrome: 126.0.6478.127
    Safari: 17.5
  npmPackages:
    @storybook/react: ^8.1.11 => 8.1.11 
    @storybook/react-vite: ^8.1.11 => 8.1.11 
    storybook: ^8.1.11 => 8.1.11

Additional context

  • The issue occurs only when using dynamic import. Static imports do not cause this issue.
  • The problem arises specifically when importing story files associated with a different Storybook configuration. For example, importing from [name].stories.tsx to [name].stories.tsx or from [name].test.stories.tsx to [name].test.stories.tsx does not cause any issues.
  • The issue is not present during development but only appears after the build process.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant