From b1af9c74f3fb37c01c0a36c41f21578d77455813 Mon Sep 17 00:00:00 2001 From: "Stephen J. Collings" Date: Sat, 14 Sep 2024 15:47:31 +0100 Subject: [PATCH] fix: CalledPreviewMethodBeforeInitializationError (8.2) (#587) * fix: CalledPreviewMethodBeforeInitializationError * fix: protected property access * Revert "fix: protected property access" This reverts commit fef8b08eb25ffa37209703fd1ff02bbcb136d00c. * fix: Cannot call initializeWithStoryIndex until project annotations resolve --------- Co-authored-by: Daniel Williams --- packages/react-native/src/View.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/react-native/src/View.tsx b/packages/react-native/src/View.tsx index 84f63ab634..3f9b05ae52 100644 --- a/packages/react-native/src/View.tsx +++ b/packages/react-native/src/View.tsx @@ -148,10 +148,12 @@ export class View { }; createPreparedStoryMapping = async () => { - await Promise.all( - Object.keys(this._storyIndex.entries).map(async (storyId: StoryId) => { - this._idToPrepared[storyId] = await this._preview.loadStory({ storyId }); - }) + await this._preview.ready().then(() => + Promise.all( + Object.keys(this._storyIndex.entries).map(async (storyId: StoryId) => { + this._idToPrepared[storyId] = await this._preview.loadStory({ storyId }); + }) + ) ); }; @@ -178,7 +180,7 @@ export class View { this._preview.channel = channel; this._preview.setupListeners(); channel.emit(Events.CHANNEL_CREATED); - this._preview.initializeWithStoryIndex(this._storyIndex); + this._preview.ready().then(() => this._preview.onStoryIndexChanged()); } managerAddons.loadAddons({