question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vite builder sorting stories alphabetically instead of by export order

See original GitHub issue

Describe the bug

It doesn’t seem like stories are sorted in the same way as the non-vite builders. Previously it looked like stories were sorted by the order they were exported, so if Default was exported first, it’d show first in the sidebar and in the docs page. This doesn’t seem to be the case with the new Vite builder, if I create Default and Custom, even if Custom comes after Default in the order of exports, Custom will show first. Overriding the sortOrder in the preview.js file doesn’t seem to fix it either.

Working Example

(This could probably be replicated with other setups too)

  • Create a nextjs app with npx create-next-app
  • Add storybook with npx sb init
  • Modify 1-Button.stories.js to have the following stories:
export const Default = () => <Button>Test</Button>
export const Custom = () => <Button>Test</Button>
  • Open storybook
  • Sidebar and canvas/docs (if you add and configure the docs addon) both show the order of [Default, Custom]

Failing Example (https://github.com/Rixcy/storybook-vite-repro)

  • Create a vite app with yarn create @vitejs/app
  • Add storybook with the vite loader using npx sb@next init --builder storybook-builder-vite
  • Modify Button.stories.tsx to have the following stories:
export const Default = Template.bind({})
export const Custom = Template.bind({})
  • Open storybook
  • Sidebar and canvas/docs show an order of [Custom, Default] (Expected result: [Default, Custom])

System

  System:
    OS: macOS 11.4
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Binaries:
    Node: 14.15.0 - ~/.nvm/versions/node/v14.15.0/bin/node
    Yarn: 1.22.5 - ~/.yarn/bin/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v14.15.0/bin/npm
  Browsers:
    Chrome: 91.0.4472.106
    Firefox: 88.0.1
    Safari: 14.1.1
  npmPackages:    @storybook/addon-actions: ^6.3.0-rc.11 => 6.3.0-rc.11 
    @storybook/addon-essentials: ^6.3.0-rc.11 => 6.3.0-rc.11 
    @storybook/addon-links: ^6.3.0-rc.11 => 6.3.0-rc.11 
    @storybook/react: ^6.3.0-rc.11 => 6.3.0-rc.11 

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
shilmancommented, Jun 27, 2021

The vite builder needs to be updated to use this workaround:

https://github.com/storybookjs/storybook/blob/next/lib/core-client/src/preview/loadCsf.ts#L92-L102

This was introduced to help the @web/dev-server get the right order in the Modern Web integration

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vite builder sorting stories alphabetically instead of by ...
It doesn't seem like stories are sorted in the same way as previous versions. Previously it looked like stories were sorted by the...
Read more >
Stories are not sorted by their export (in production) #15574
Describe the bug In production, stories are not sorted according to their export instead, they are sorted alphabetically. How they should be sorted...
Read more >
Sorting locations in a category
Mapme offers different options to sort the order of the locations in the map categories. Sort by alphabetical order. Mapme offers an option...
Read more >
Sort and Limit Data in a Collection
All text-based fields including picklists are sorted alphabetically. Boolean fields are sorted as False first if Sort Order is set to Ascending, or...
Read more >
Release Notes
Order collection and taxonomy fieldtype options by title. ... Support Query Builder values in reverse modifier #7006 by @stvnthomas ... Added vite tag....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found