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

fix: CalledPreviewMethodBeforeInitializationError (8.2) #587

Merged
merged 5 commits into from
Sep 14, 2024

Conversation

stevoland
Copy link
Contributor

Fix this error in 8.2-alpha1 with large number of stories:

ERROR [SB_PREVIEW_API_0005 (CalledPreviewMethodBeforeInitializationError): Called `Preview.loadStory()` before initialization.

The preview needs to load the story index before most methods can be called. If you want
to call `loadStory`, try `await preview.initializationPromise;` first.

If you didn't call the above code, then likely it was called by an addon that needs to
do the above.]

What I did

Add waits for initialization

How to test

Start with large number of stories, eg: stevoland@aca843b

@stevoland stevoland requested a review from dannyhw as a code owner July 23, 2024 11:11
@dannyhw
Copy link
Member

dannyhw commented Jul 23, 2024

thanks @stevoland 🙏

@dannyhw
Copy link
Member

dannyhw commented Jul 23, 2024

seem to be getting a build error here

Error: src/View.tsx(151,25): error TS2445: Property 'storeInitializationPromise' is protected and only accessible within class 'Preview' and its subclasses.
Error: src/View.tsx(183,21): error TS2445: Property 'storeInitializationPromise' is protected and only accessible within class 'Preview' and its subclasses.

I wonder if theres another way to call it.

@stevoland
Copy link
Contributor Author

Bah, sorry didn't get the tests to run locally.

The error message says initializationPromise but that's undefined. I'll have a dig around

@stevoland
Copy link
Contributor Author

I guess we can just add a subclass and expose it https://github.com/storybookjs/react-native/blob/feat/v8/packages/react-native/src/Start.tsx#L211

@stevoland
Copy link
Contributor Author

Hmm, actually leave this for now. There's a ready() method on preview to use but also I get another early initialisation error when web socket is enabled so needs more work

@stevoland
Copy link
Contributor Author

Ok, I think this does the job now, thanks

@dannyhw
Copy link
Member

dannyhw commented Sep 14, 2024

sorry for not following up earlier I've had a lot going on, taking another look now

@dannyhw
Copy link
Member

dannyhw commented Sep 14, 2024

seems to be working, thanks for the fix 🙏

@dannyhw dannyhw merged commit b1af9c7 into storybookjs:feat/v8 Sep 14, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants