diff --git a/code/core/src/component-testing/components/Panel.tsx b/code/core/src/component-testing/components/Panel.tsx index 16df7a552a67..0a6b07906201 100644 --- a/code/core/src/component-testing/components/Panel.tsx +++ b/code/core/src/component-testing/components/Panel.tsx @@ -239,6 +239,7 @@ export const Panel = memo<{ refId?: string; storyId: string; storyUrl: string }> return () => observer?.disconnect(); }, []); + const lastStoryId = useRef(undefined); const lastRenderId = useRef(0); const emit = useChannel( { @@ -253,12 +254,16 @@ export const Panel = memo<{ refId?: string; storyId: string; storyUrl: string }> ); }, [STORY_RENDER_PHASE_CHANGED]: (event) => { - if (event.newPhase === 'preparing' || event.newPhase === 'loading') { - // A render cycle may not actually make it to the rendering phase. + if ( + lastStoryId.current === event.storyId && + ['preparing', 'loading'].includes(event.newPhase) + ) { + // A rerender cycle may not actually make it to the rendering phase. // We don't want to update any state until it does. return; } + lastStoryId.current = event.storyId; lastRenderId.current = Math.max(lastRenderId.current, event.renderId || 0); if (lastRenderId.current !== event.renderId) { return; diff --git a/code/core/src/controls/components/SaveStory.stories.tsx b/code/core/src/controls/components/SaveStory.stories.tsx index a08dba96d183..c643750cf4b1 100644 --- a/code/core/src/controls/components/SaveStory.stories.tsx +++ b/code/core/src/controls/components/SaveStory.stories.tsx @@ -42,14 +42,12 @@ export const Creating = { } satisfies Story; export const Created: Story = { - play: async ({ canvas, context, userEvent }) => { + play: async ({ canvas, context }) => { await Creating.play(context); - const event = userEvent.setup({ delay: null }); const dialog = await canvas.findByRole('dialog'); const input = await within(dialog).findByRole('textbox'); - await event.type(input, 'MyNewStory'); - + await fireEvent.change(input, { target: { value: 'MyNewStory' } }); await fireEvent.submit(dialog.getElementsByTagName('form')[0]); await expect(context.args.createStory).toHaveBeenCalledWith('MyNewStory'); }, diff --git a/code/core/src/preview-api/modules/preview-web/render/StoryRender.ts b/code/core/src/preview-api/modules/preview-web/render/StoryRender.ts index 4e5bc7d89c4c..27c0f4167a97 100644 --- a/code/core/src/preview-api/modules/preview-web/render/StoryRender.ts +++ b/code/core/src/preview-api/modules/preview-web/render/StoryRender.ts @@ -116,16 +116,15 @@ export class StoryRender implements Render