Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Drop unneeded UPDATE_STORY_ARGS which was for SSv6 #25993

Merged
merged 2 commits into from
Apr 12, 2024
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
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
Loading