Skip to content

Commit

Permalink
Merge pull request #25993 from storybookjs/tom/drop-unneeded-set-args
Browse files Browse the repository at this point in the history
Core: Drop unneeded `UPDATE_STORY_ARGS` which was there for SSv6 and back-compat.
  • Loading branch information
tmeasday committed Apr 12, 2024
2 parents 391f7d6 + 5bc5c11 commit 3b8495b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 32 deletions.
41 changes: 17 additions & 24 deletions code/lib/preview-api/src/modules/preview-web/PreviewWeb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,19 @@ describe('PreviewWeb', () => {
one: 1,
});
});
it('updates args from the URL', async () => {

it('prepares story with args from the URL', async () => {
document.location.search = '?id=component-one--a&args=foo:url';

await createAndRenderPreview();

expect(mockChannel.emit).toHaveBeenCalledWith(STORY_ARGS_UPDATED, {
storyId: 'component-one--a',
args: { foo: 'url', one: 1 },
});
expect(mockChannel.emit).toHaveBeenCalledWith(
STORY_PREPARED,
expect.objectContaining({
id: 'component-one--a',
args: { foo: 'url', one: 1 },
})
);
});

it('allows async getProjectAnnotations', async () => {
Expand Down Expand Up @@ -2798,20 +2802,6 @@ describe('PreviewWeb', () => {
});
});

it('emits STORY_ARGS_UPDATED with new args', async () => {
document.location.search = '?id=component-one--a';
const preview = await createAndRenderPreview();
mockChannel.emit.mockClear();

preview.onStoriesChanged({ importFn: newImportFn });
await waitForRender();

expect(mockChannel.emit).toHaveBeenCalledWith(STORY_ARGS_UPDATED, {
storyId: 'component-one--a',
args: { foo: 'edited', one: 1 },
});
});

it('applies loaders with story context', async () => {
document.location.search = '?id=component-one--a';
const preview = await createAndRenderPreview();
Expand Down Expand Up @@ -3402,18 +3392,21 @@ describe('PreviewWeb', () => {
});
});

it('emits SET_STORY_ARGS with new values', async () => {
it('emits SET_PREPARED with new args', async () => {
document.location.search = '?id=component-one--a';
const preview = await createAndRenderPreview();

mockChannel.emit.mockClear();
preview.onGetProjectAnnotationsChanged({ getProjectAnnotations: newGetProjectAnnotations });
await waitForRender();

expect(mockChannel.emit).toHaveBeenCalledWith(STORY_ARGS_UPDATED, {
storyId: 'component-one--a',
args: { foo: 'a', one: 1, global: 'added' },
});
expect(mockChannel.emit).toHaveBeenCalledWith(
STORY_PREPARED,
expect.objectContaining({
id: 'component-one--a',
args: { foo: 'a', one: 1, global: 'added' },
})
);
});

it('calls renderToCanvas teardown', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
PRELOAD_ENTRIES,
PREVIEW_KEYDOWN,
SET_CURRENT_STORY,
STORY_ARGS_UPDATED,
STORY_CHANGED,
STORY_ERRORED,
STORY_MISSING,
Expand Down Expand Up @@ -404,13 +403,6 @@ export class PreviewWithSelection<TRenderer extends Renderer> extends Preview<TR
argTypes,
args: unmappedArgs,
});

// For v6 mode / compatibility
// If the implementation changed, or args were persisted, the args may have changed,
// and the STORY_PREPARED event above may not be respected.
if (implementationChanged || persistedArgs) {
this.channel.emit(STORY_ARGS_UPDATED, { storyId, args: unmappedArgs });
}
} else {
// Default to the project parameters for MDX docs
let { parameters } = this.storyStoreValue.projectAnnotations;
Expand Down

0 comments on commit 3b8495b

Please sign in to comment.