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

In production, stories do not appear in export order #17611

Closed
rdebeasi opened this issue Mar 2, 2022 · 18 comments
Closed

In production, stories do not appear in export order #17611

rdebeasi opened this issue Mar 2, 2022 · 18 comments

Comments

@rdebeasi
Copy link

rdebeasi commented Mar 2, 2022

Describe the bug
In production, stories do not appear in export order. Instead, they are sorted alphabetically.

#15574 describes similar behavior and was closed when a fix was released in v6.14.13 and v6.5.0-alpha.17. I'm still experiencing this problem with Storybook 6.5.0-alpha.45, however.

Screenshot of dev server and production server

Thank you in advance for your help!! 😄

To Reproduce

  1. Clone https://github.com/rdebeasi/storybook-sort-repro

  2. Run yarn storybook to start Storybook in dev mode. Stories appear in export order (Story C, Story B, Story A). This is the expected behavior.

  3. Run yarn build-storybook && npx serve to start Storybook in production mode. Shows appear in sorted in alphabetical order (Story A, Story B, Story C). This behavior appears to be a bug.

System

  OS: macOS 11.6.4

  CPU: (8) x64 Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz

 Binaries:

  Node: 14.15.1 - ~/.nvm/versions/node/v14.15.1/bin/node

  Yarn: 3.2.0 - ~/.yarn/bin/yarn

  npm: 6.14.8 - ~/.nvm/versions/node/v14.15.1/bin/npm

 Browsers:

  Chrome: 98.0.4758.109

  Firefox: 97.0.1

  Safari: 15.3

 npmPackages:

  @storybook/addon-actions: ^6.5.0-alpha.45 => 6.5.0-alpha.45 

  @storybook/addon-docs: ^6.5.0-alpha.45 => 6.5.0-alpha.45 

  @storybook/addon-essentials: ^6.5.0-alpha.45 => 6.5.0-alpha.45 

  @storybook/addon-interactions: ^6.5.0-alpha.45 => 6.5.0-alpha.45 

  @storybook/addon-links: ^6.5.0-alpha.45 => 6.5.0-alpha.45 

  @storybook/angular: ^6.5.0-alpha.45 => 6.5.0-alpha.45 

  @storybook/builder-webpack5: ^6.5.0-alpha.45 => 6.5.0-alpha.45 

  @storybook/manager-webpack5: ^6.5.0-alpha.45 => 6.5.0-alpha.45 

  @storybook/testing-library: ^0.0.9 => 0.0.9 
@himerus
Copy link

himerus commented Mar 3, 2022

I have seen this repeatedly in about 8 different Storybook environments at minimum.

This is a major issue as on many stories, we may intentionally build the first story to handle all the controls and be a flexible demonstration of all the options. THEN we will choose to iterate out more "hard coded" stories for some of the additional ones to provide multiple varying scenarios we can run a11y tests against, etc.

I wish I'd have had time to look into this, but we've definitely seen this for MONTHS.

@shilman
Copy link
Member

shilman commented Mar 4, 2022

Did you see this comment

#15574 (comment)

@rdebeasi
Copy link
Author

rdebeasi commented Mar 4, 2022

Thanks for sharing that link! Unfortunately, it does not resolve this issue.

That comment refers to a problem with a custom Webpack config. In the repro above, we are using the default configuration, without any Webpack customization.

@shilman
Copy link
Member

shilman commented Mar 4, 2022

@rdebeasi @himerus I'm seeing an inconsistency between the babel config for angular (broken) vs. react (works). will investigate further. are all the projects you're seeing this on using Angular? If not, what framework? thanks! 🙏

@himerus
Copy link

himerus commented Mar 4, 2022

@shilman we are using web components 100%.

image

Thanks for taking a look!! This has been an annoyance, and I've never found the time to look into what was causing it.

@shilman
Copy link
Member

shilman commented Mar 4, 2022

@himerus in your case i think it's your custom babel config that's overriding the defaults. try adding babel-plugin-named-exports-order to process your story files and i think it should work. please let me know either way! 🙏

@rdebeasi
Copy link
Author

rdebeasi commented Mar 4, 2022

Yes, I'm seeing this problem only with Storybook Angular. I'm not able to reproduce the problem with Storybook React.

@himerus
Copy link

himerus commented Mar 4, 2022

@himerus in your case i think it's your custom babel config that's overriding the defaults. try adding babel-plugin-named-exports-order to process your story files and i think it should work. please let me know either way! 🙏

Interesting. Now I have to figure out/remember why we have that large babel config in place to begin with. It is a leftover remnant from long ago. Adding babel-plugin-named-exports-order almost solved the problem. They are listed in the correct order in the sidebar menu, but not in the story itself.

image

Any additional thoughts welcome, otherwise I'll dig more into that configuration.

@shilman
Copy link
Member

shilman commented Mar 6, 2022

They are listed in the correct order in the sidebar menu, but not in the story itself.

@himerus To clarify, do you mean in the DocsPage for that story on the Docs tab?

@shilman shilman added the angular label Mar 6, 2022
@himerus
Copy link

himerus commented Mar 6, 2022

@shilman Exactly. This is on the Docs tab.

@shilman
Copy link
Member

shilman commented Mar 7, 2022

@tmeasday any ideas why the DocsPage story order wouldn't match the sidebar order?

@tmeasday
Copy link
Member

tmeasday commented Mar 9, 2022

@himerus -- am I correct in saying you are NOT using storyStoryV7?

If so, I don't really see any obvious reason why the order here (which drives the docs page):

return Object.keys(csfFile.stories).map((storyId: StoryId) =>

would differ from the order in extract (which drives the sidebar):

return Object.entries(this.storyIndex.stories).reduce((acc, [storyId, { importPath }]) => {

However, I suppose technically there's definitely a bug there, as the order in the index could definitely be different from the raw export order (e.g. if you are using sorting, or __namedExportsOrder). I'll send a fix for that in any case @shilman. (#17669)

On the surface it doesn't seem like what's happening here though -- in the v6 store (without sorting, or order), the index just ends up walking the exports anyway:

Object.entries(sortedExports)
.filter(([key]) => isExportStory(key, defaultExport))
.forEach(([key, storyExport]: [string, any]) => {

@shilman
Copy link
Member

shilman commented Mar 9, 2022

Great Caesar's ghost!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.5.0-alpha.47 containing PR #17669 that references this issue. Upgrade today to the @next NPM tag to try it out!

npx sb upgrade --prerelease

Closing this issue. Please re-open if you think there's still more to do.

@shilman shilman closed this as completed Mar 9, 2022
@rdebeasi
Copy link
Author

Thanks for making this change! I've updated the repro to Storybook 6.5.0-alpha.48. Stories are now sorted in alphabetical order in both local and development.

My understanding is that the intended behavior is for stories to be sorted in export order, not alphabetical order. For example, in the How to write stories docs, the Button stories are shown in export order:

  • Primary
  • Secondary
  • Large
  • Small

Closing this issue. Please re-open if you think there's still more to do.

I think there's still more to do, but I don't have permission to re-open this issue because I'm not a collaborator and I didn't close the issue. Could someone please re-open this issue? Thank you!

@liverant
Copy link

liverant commented Mar 24, 2022

With the new version:

 "@nrwl/storybook": "^13.10.0-beta.1",
    "@storybook/addon-docs": "^6.5.0-alpha.50",
    "@storybook/addon-essentials": "^6.5.0-alpha.50",
    "@storybook/addon-viewport": "^6.5.0-alpha.50",
    "@storybook/angular": "^6.5.0-alpha.50",
    "@storybook/builder-webpack5": "^6.5.0-alpha.50",
    "@storybook/manager-webpack5": "^6.5.0-alpha.50",

And the default config (preview.js):

export const parameters = {
  viewMode: 'docs',
  docs: {
    inlineStories: true,
    container: DocsContainer,
    page: DocsPage,
    source: {
      state: 'open',
    },
  },
  viewport: {
    viewports: INITIAL_VIEWPORTS,
  },
};

Stories in prod build are still not in their imported order
("Playground" should be first, instead we get alphabetical order)
image

@shilman can you reopen?

@shilman
Copy link
Member

shilman commented Apr 1, 2022

Shiver me timbers!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.4.20 containing PR #17669 that references this issue. Upgrade today to the @latest NPM tag to try it out!

npx sb upgrade

@platon-rov
Copy link

Still sorted in the wrong order. Tried even 6.5-alpha.55 version. HTML framework.

@rdebeasi
Copy link
Author

rdebeasi commented Apr 4, 2022

I'm unable to reopen this issue, so I'd recommend continuing the conversation in #17665, which appears to describe a similar problem. Thanks! 😄

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

6 participants