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

Webpack5 Builder - Stories cannot be explicitly sorted #17665

Closed
sashafklein opened this issue Mar 9, 2022 · 16 comments
Closed

Webpack5 Builder - Stories cannot be explicitly sorted #17665

sashafklein opened this issue Mar 9, 2022 · 16 comments

Comments

@sashafklein
Copy link

sashafklein commented Mar 9, 2022

Describe the bug

I just updated from the Webpack 4 Builder to Webpack 5, and my stories are suddenly sorted differently. Specifically, whereas they used to display in order of export, they now sort alphabetically. In other words, the below code would produce a storybook with Later showing up before MeFirst

// This would show up first
export const MeFirst = ...
// This would show up later, even though L precedes M
export const Later = ...

Looked at the sorting docs, and the objects passed to the storySort option in parameters, but it appears the native export order is not given to this sorting function. Is there any way to have the order of the story exports determine their appearance?

System

  System:
    OS: macOS 12.0.1
    CPU: (10) x64 Apple M1 Pro
  Binaries:
    Node: 12.13.0 - ~/.nvm/versions/node/v12.13.0/bin/node
    npm: 7.5.3 - ~/.nvm/versions/node/v12.13.0/bin/npm
  Browsers:
    Chrome: 99.0.4844.51
    Firefox: 96.0.2
    Safari: 15.1
  npmPackages:
    @storybook/addon-a11y: ^6.4.19 => 6.4.19 
    @storybook/addon-actions: ^6.4.19 => 6.4.19 
    @storybook/addon-essentials: ^6.4.19 => 6.4.19 
    @storybook/addon-links: ^6.4.19 => 6.4.19 
    @storybook/builder-webpack5: ^6.4.19 => 6.4.19 
    @storybook/manager-webpack5: ^6.4.19 => 6.4.19 
    @storybook/node-logger: ^6.4.19 => 6.4.19 
    @storybook/preset-create-react-app: ^4.0.1 => 4.0.1 
    @storybook/preset-scss: ^1.0.3 => 1.0.3 
    @storybook/react: ^6.4.19 => 6.4.19 
@sashafklein sashafklein changed the title Webpack5 Builder - Sort stories explicitly Webpack5 Builder - Stories cannot be ex sorted Mar 9, 2022
@sashafklein sashafklein changed the title Webpack5 Builder - Stories cannot be ex sorted Webpack5 Builder - Stories cannot be explicitly sorted Mar 15, 2022
@kkakroo
Copy link

kkakroo commented Mar 16, 2022

I had been on webpack5 builder for a while but started seeing this issue after one of the recent updates.
However removing webpack5 builder fixed the issue for now, thanks.

@rdebeasi
Copy link

rdebeasi commented Apr 1, 2022

Related: #17847

@rdebeasi
Copy link

rdebeasi commented Apr 4, 2022

Here's a repro using @storybook/angular 6.5.0-alpha.55.

Thanks in advance for looking into this! 😄

@rdebeasi
Copy link

rdebeasi commented Apr 6, 2022

Thanks for your interest! In the future, you can receive updates by clicking the "subscribe" button on the right side of the page. 😄

@catdc2017
Copy link

I found a work around for this issue. The sort is occurring on the export const

export const A = () => {
    const labelText = text(LABEL, LABEL_DEFAULT, GENERAL);
    const helperText = text(HELPER_TEXT, HELPER_TEXT_DEFAULT, GENERAL);
    return {
        moduleMetadata: {
            imports: [AutocompleteReactiveModule],
        },
        component: AutocompleteReactiveComponent,
        props: {
            labelText,
            helperText,
        },
    };
};

A.storyName = 'Basic';
A.parameters = { docs: { page: AutocompleteReactiveMDX }, themes: getThemeConfig() };

So if you name the const alphabetically as you want them in your stories.ts it will work in production correctly

Example below sorts correctly in production

A.storyName = 'Basic';
B.storyName = 'API';
C.storyName = 'Guidelines';

Example below does not sort correctly in production

Basic.storyName = 'Basic';
API.storyName = 'API';
Guidelines.storyName = 'Guidelines';

@catdc2017
Copy link

catdc2017 commented Apr 6, 2022

Obviously I would be more interested in a correct fix of course rather than work around so I will be keeping an eye on this 😀

@brandonmcconnell
Copy link

I've been noticing this lately as well. Even if alphabetical is the new default, there should be a way using storySort to enforce intrinsic/export order.

This would be possible if the intrinsic order were included as an integer somewhere in the sort method's callback function, but it does not appear to be.

@shilman
Copy link
Member

shilman commented Apr 17, 2022

closing as dupe to #15574

@symmetriq
Copy link
Contributor

This was fixed in 6.5, but is now broken again in 6.5.5.

@shilman
Copy link
Member

shilman commented May 25, 2022

@symmetriq do you have a reproduction you can share? Or, specifically, can you share your stories glob from .storybook/main.js?

@symmetriq
Copy link
Contributor

@shilman

  "stories": [
    "../src/**/*.stories.mdx",
    "../src/**/*.stories.@(js|jsx|ts|tsx)"
  ],

@rshackleton
Copy link

Also seeing this issue after switching to the webpack 5 builder.

stories: ['../src/stories/**/*.stories.mdx', '../src/stories/**/*.stories.@(js|jsx|ts|tsx)']

@siminino
Copy link

siminino commented Jun 22, 2022

Also seeing this issue after upgrading to 6.5.9, using builder webpack 5 and React. (before was in storybook 6.4.22 and webpack 4)
Now, any story that comes before "Default" when alphabetically sorted (ex: Bottom), becomes the default story. So, Default is not default anymore.
Obs: and looks like Primary is not primary anymore too.

@symmetriq
Copy link
Contributor

For me, stories are sorted as expected (in export order, not alphabetical) as of Storybook 6.5.8. I'm now using 6.5.9 and it's still working correctly. There must be some other factor involved.

@siminino
Copy link

You are totally right @symmetriq. I have just found the "other factor" involved.

We use the filename format *.example.js in our project. This is our storybook main.js:

module.exports = {
  stories: ['../src/components/**/*.example.js'],
  framework: '@storybook/react',
  addons: [
    '@storybook/addon-actions',
    '@storybook/addon-viewport',
    '@storybook/addon-knobs',
    '@storybook/addon-docs',
    '@storybook/addon-controls',
    '@storybook/addon-measure',
    '@storybook/addon-outline',
  ],
  core: {
    builder: 'webpack5',
  },
}

After changing one story filename to *.stories.js and updating main.js to search for this pattern, it sorts as expected.

So, we have an issue where we must use the proposed stories filename format to make sorting works properly.

@siminino
Copy link

I open i new ticket for it #18535

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

9 participants