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

After updating to 5.3.8 getStorybook() always returns an empty array #9622

Closed
faberyx opened this issue Jan 24, 2020 · 10 comments
Closed

After updating to 5.3.8 getStorybook() always returns an empty array #9622

faberyx opened this issue Jan 24, 2020 · 10 comments

Comments

@faberyx
Copy link

faberyx commented Jan 24, 2020

Describe the bug
After upgrading to latest 5.3.8 version when calling getStorybook() from a story or from a configuration file always returns an empty array, before on 5.2 I was correctly getting an array of all stories.

Did something change in the new version?

@shilman shilman added this to the 5.3.x milestone Jan 24, 2020
@shilman
Copy link
Member

shilman commented Jan 24, 2020

Did you change anything, or is your code identical? Can you share a repro?

I made some changes the story store here, but neither should affect you: #9424 #9482

It's also possible that something related to main.js config could have introduced a regression.

@faberyx
Copy link
Author

faberyx commented Jan 24, 2020

I did update all configuration files according to the 5.3 specifications.

On 5.2 I used to get the stories from the old config.js file and from a CSF story, this is actually the code:

/** @jsx createElement */
import { createElement } from 'react';
import CorePaletteComponent from './palette/palette';
import { getStorybook } from '@storybook/react';

const stories = getStorybook();
console.log(stories);

export default {
  title: 'Core UI/Elements'
};
export const ColorPalette = () => <CorePaletteComponent />;

console.log now returns an empty array, but it works if I save the file and hot reload kicks in, then I get the correct list of stories in the log.

@shilman
Copy link
Member

shilman commented Jan 24, 2020

cc @ndelangen @tmeasday

@ndelangen
Copy link
Member

Did the code work before changing to main.js?

I'm thinking that CSF doesn't work together with get Storybook.

One thing that you might try is wrapping the getStorybook call in a setTimout.

The problem is that CSF stories evaluate first THEN agree injected into the storystore.

getStorybook asks the storystore which at this point in the runtime is Emory.

@ndelangen ndelangen reopened this Jan 24, 2020
@ndelangen
Copy link
Member

I'm fairly sure this is NOT a bug in tri-config @shilman

@shilman
Copy link
Member

shilman commented Jan 24, 2020

sounds like it worked in 5.2 w/ CSF tho?

i touched the story_store (w/ @tmeasday) recently. @faberyx what happens if you revert to 5.3.0? those changes started in 5.3.3.

@ndelangen
Copy link
Member

At best getStorybook returns an incomplete storystore.

@faberyx
Copy link
Author

faberyx commented Jan 24, 2020

In 5.2.8 I was able to get the list, also I could get the list of stories in the configuration file .storybook/config.js

import { configure, addDecorator, addParameters } from '@storybook/react';
import { getStorybook } from '@storybook/react';
configure([require.context('../src', true, /\.stories\.tsx$/)], module);

const myStories = getStorybook();

console.log(myStories);

now I moved the same code to preview.js and the array was also empty here.

Using a setTimeout fixed the problem, so Ill close the issue, thanks!

@faberyx faberyx closed this as completed Jan 24, 2020
@ndelangen
Copy link
Member

Preview.js executes before the configure call automated by main.js

This is by design.

@jonyw4
Copy link

jonyw4 commented Dec 28, 2020

@faberyx @ndelangen can you share how you get all stories (including CSF files) using getStorybook with setTimeout? (maybe in this discussion too)

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

5 participants