Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion code/core/src/preview-api/modules/preview-web/PreviewWeb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -963,10 +963,31 @@ describe('PreviewWeb', () => {
mockChannel.emit.mockClear();
docsRenderer.render.mockClear();
emitter.emit(UPDATE_GLOBALS, { globals: { a: 'd' } });
await waitForEvents([GLOBALS_UPDATED]);
await waitForEvents([DOCS_RENDERED]);

expect(docsRenderer.render).toHaveBeenCalled();
});

it('waits for inline stories to rerender before rerendering the docs container', async () => {
document.location.search = '?id=component-one--docs&viewMode=docs';
const preview = await createAndRenderPreview();
const [inlineStoryRerender, finishInlineStoryRerender] = createGate();
const rerenderInlineStory = vi.fn(() => inlineStoryRerender);
preview.storyRenders.push({
rerender: rerenderInlineStory,
} as unknown as (typeof preview.storyRenders)[number]);
const rerenderDocs = vi.spyOn(preview.currentRender!, 'rerender');
Comment thread
valentinpalkovic marked this conversation as resolved.

const updateGlobals = preview.onUpdateGlobals({ globals: { a: 'd' } });
await vi.waitFor(() => expect(rerenderInlineStory).toHaveBeenCalled());

expect(rerenderDocs).not.toHaveBeenCalled();

finishInlineStoryRerender();
await updateGlobals;

expect(rerenderDocs).toHaveBeenCalledOnce();
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export class PreviewWithSelection<TRenderer extends Renderer> extends Preview<TR
async onUpdateGlobals({ globals }: { globals: Globals }) {
const currentStory =
(this.currentRender instanceof StoryRender && this.currentRender.story) || undefined;
super.onUpdateGlobals({ globals, currentStory });
await super.onUpdateGlobals({ globals, currentStory });
Comment thread
valentinpalkovic marked this conversation as resolved.
if (
this.currentRender instanceof MdxDocsRender ||
this.currentRender instanceof CsfDocsRender
Expand Down
Loading