storybook icon indicating copy to clipboard operation
storybook copied to clipboard

[Bug]: storySort is never called, sort has not effect

Open NathanVss opened this issue 2 years ago • 1 comments

Describe the bug

The options.storySort option is ignored.

To Reproduce

Here is my preview.cjs file:

export const parameters = {
  actions: { argTypesRegex: '^on[A-Z].*' },
  controls: {
    matchers: {
      color: /(background|color)$/i,
      date: /Date$/,
    },
  },
  options: {
    storySort: (a, b) => {
      console.log(a, b);
      return a[1].kind === b[1].kind ? 0 : a[1].id.localeCompare(b[1].id, undefined, { numeric: true });

    }
  },
};

console.log(parameters);

The sort has not effect, proof is that console.log(parameters); is well printed but the console.log from storySort is not.

I also tried using options.storySort.order with hard-coded array but it does not work too.

Here are the dependencies defined in package.json:

    "@storybook/addon-actions": "6.5.15",
    "@storybook/addon-essentials": "6.5.15",
    "@storybook/addon-interactions": "6.5.15",
    "@storybook/addon-links": "6.5.15",
    "@storybook/builder-vite": "0.2.6",
    "@storybook/preset-scss": "1.0.3",
    "@storybook/react": "6.5.15",
    "@storybook/testing-library": "0.0.13",

For more context, here is the current sidebar:

Capture d’écran 2023-01-19 à 11 14 51

System

System:
    OS: macOS 13.0.1
    CPU: (10) arm64 Apple M1 Pro
  Binaries:
    Node: 16.19.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 8.19.3 - /usr/local/bin/npm
  Browsers:
    Chrome: 109.0.5414.87
    Safari: 16.1

Additional context

No response

NathanVss avatar Jan 19 '23 10:01 NathanVss

Ok got it, I renamed preview.cjs to preview.js and it works now.

But I will be happy to understand how this could affect the sorting behavior ?

NathanVss avatar Jan 19 '23 10:01 NathanVss

Yes, because Storybook is expecting preview.@(js|jsx|ts|tsx). I have created #20718 to handle the processing better.

sheriffMoose avatar Jan 21 '23 05:01 sheriffMoose

Gadzooks!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.0.0-rc.5 containing PR #21637 that references this issue. Upgrade today to the @next NPM tag to try it out!

npx sb@next upgrade --prerelease

shilman avatar Mar 20 '23 09:03 shilman