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]: "useArgs" hook updates wrong story when rendered in "Stories" block #28333

Open
brycenaddison opened this issue Jun 24, 2024 · 2 comments

Comments

@brycenaddison
Copy link

Describe the bug

When writing a story for a controlled component, one should expect the useArgs hook to update the args being passed to the story it is being called in. However, when used inside a "Stories" block, it updates the page's primary story instead of itself. This isn't an issue when using a "Canvas" block or any other block that selects a specific story. I'm sure this could be user error but I don't see why there would then be a discrepancy between the functionality between the "Stories" block and an individual "Story" block.

Reproduction link

https://stackblitz.com/edit/github-n2sxrc?file=src%2Fstories%2FInput.tsx

Reproduction steps

  1. Go to the "Input" docs in Storybook.
  2. Attempt to edit one of the stories under the "Stories" header.
  3. Notice that value of top story is changing, instead of the story being edited.

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.20.3 - /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

Additional context

No response

@brycenaddison
Copy link
Author

brycenaddison commented Jun 28, 2024

For anyone having a similar issue, I was able to work around it by making a custom block to use instead of Stories.

/** A block for showing a list of stories. */
export const MyStories = ({
  of,
  exclude = ['Primary'],
}) => {
  const resolvedOf = useOf(of ?? 'meta', ['meta']);
  const moduleExports = resolvedOf.csfFile.moduleExports;
  const exportsOrder = moduleExports.__namedExportsOrder;

  return (
    <>
      {exportsOrder
        .filter((name) => !exclude.includes(name))
        .map((name) => (
          // Title, description, and canvas blocks
          <MyStory key={name} of={moduleExports[name]} />
        ))}
    </>
  );
};

@asso1985
Copy link

+1

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

3 participants