Skip to content

Commit f8ce0f4

Browse files
authored
Merge pull request #32172 from storybookjs/reset-on-change-story
Core: Prevent `BAIL` state from showing in interactions panel when switching stories
2 parents 95e41e2 + 72b63e9 commit f8ce0f4

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

code/core/src/component-testing/components/Panel.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ export const Panel = memo<{ refId?: string; storyId: string; storyUrl: string }>
247247
return () => observer?.disconnect();
248248
}, []);
249249

250+
const lastStoryId = useRef<string>(undefined);
250251
const lastRenderId = useRef<number>(0);
251252
const emit = useChannel(
252253
{
@@ -261,12 +262,16 @@ export const Panel = memo<{ refId?: string; storyId: string; storyUrl: string }>
261262
);
262263
},
263264
[STORY_RENDER_PHASE_CHANGED]: (event) => {
264-
if (event.newPhase === 'preparing' || event.newPhase === 'loading') {
265-
// A render cycle may not actually make it to the rendering phase.
265+
if (
266+
lastStoryId.current === event.storyId &&
267+
['preparing', 'loading'].includes(event.newPhase)
268+
) {
269+
// A rerender cycle may not actually make it to the rendering phase.
266270
// We don't want to update any state until it does.
267271
return;
268272
}
269273

274+
lastStoryId.current = event.storyId;
270275
lastRenderId.current = Math.max(lastRenderId.current, event.renderId || 0);
271276
if (lastRenderId.current !== event.renderId) {
272277
return;

code/core/src/controls/components/SaveStory.stories.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,12 @@ export const Creating = {
4242
} satisfies Story;
4343

4444
export const Created: Story = {
45-
play: async ({ canvas, context, userEvent }) => {
45+
play: async ({ canvas, context }) => {
4646
await Creating.play(context);
47-
const event = userEvent.setup({ delay: null });
4847

4948
const dialog = await canvas.findByRole('dialog');
5049
const input = await within(dialog).findByRole('textbox');
51-
await event.type(input, 'MyNewStory');
52-
50+
await fireEvent.change(input, { target: { value: 'MyNewStory' } });
5351
await fireEvent.submit(dialog.getElementsByTagName('form')[0]);
5452
await expect(context.args.createStory).toHaveBeenCalledWith('MyNewStory');
5553
},

code/core/src/preview-api/modules/preview-web/render/StoryRender.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,15 @@ export class StoryRender<TRenderer extends Renderer> implements Render<TRenderer
116116
}
117117

118118
private checkIfAborted(signal: AbortSignal): boolean {
119-
if (signal.aborted) {
119+
if (signal.aborted && !['finished', 'aborted', 'errored'].includes(this.phase as RenderPhase)) {
120120
this.phase = 'aborted';
121121
this.channel.emit(STORY_RENDER_PHASE_CHANGED, {
122122
newPhase: this.phase,
123123
renderId: this.renderId,
124124
storyId: this.id,
125125
});
126-
return true;
127126
}
128-
return false;
127+
return signal.aborted;
129128
}
130129

131130
async prepare() {

0 commit comments

Comments
 (0)