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]: Storybook bundle not deterministic #24747

Closed
henkerik opened this issue Nov 7, 2023 · 4 comments · Fixed by #24833
Closed

[Bug]: Storybook bundle not deterministic #24747

henkerik opened this issue Nov 7, 2023 · 4 comments · Fixed by #24833

Comments

@henkerik
Copy link
Contributor

henkerik commented Nov 7, 2023

Describe the bug

The storybook bundle is not build deterministically from the source files. The order the stories in the bundle is determined by the listStories function:

export async function listStories(options: Options) {

This function uses a glob, but the order of the results from a glob are given in no arbitrary order. This results in a Storybook bundle in which the list of story imports may differ from one build to the next.

This breaks artifact based build systems like Bazel or Buck2 because they assume every build action is deterministic.

Screenshot 2023-10-29 at 18 42 26

Fix

This bug in Storybook was easily patched by sorting the list of stories at the end of line:

).reduce((carry, stories) => carry.concat(stories.map(normalizePath)), []);

The sort order doesn't matter, as long as it is consistent from one build to the next.

To Reproduce

Take a large Storybook and build it multiple times from sources. The resulting bundle does not always have the same file hash.

System

No response

Additional context

No response

@valentinpalkovic
Copy link
Contributor

Hi @henkerik,

Thanks for reporting this! These findings are very interesting. Do you mind opening a PR with a fix? Do you know, whether this bug also applies to the webpack5 builder?

@henkerik
Copy link
Contributor Author

Hey @valentinpalkovic ,

Sure, this is how we fixed (*) this bug:

#24833

(*) were are currently running Storybook with a patch (https://pnpm.io/cli/patch)

@henkerik
Copy link
Contributor Author

FYI, I don't see any usage of glob in the webpack5 builder, so I don't think this specific bug is present in the webpack5 builder.

@valentinpalkovic
Copy link
Contributor

Great! Thanks for checking the Webpack5 builder!

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