From 35cf9bd6f74572368a3dc56fc2277b23e7c87988 Mon Sep 17 00:00:00 2001 From: Kasper Peulen Date: Mon, 24 Apr 2023 12:48:00 +0200 Subject: [PATCH] Vue3: Try reactivity without invoking args as props --- code/renderers/vue3/src/decorateStory.ts | 17 ++++------ code/renderers/vue3/src/render.ts | 6 ++-- ...CustomRenderFunctionalComponent.stories.ts | 2 -- ...CustomRenderOptionsArgsFromData.stories.ts | 2 -- ...ustomRenderOptionsArgsFromProps.stories.ts | 33 ------------------- .../stories/ReactiveDecorators.stories.ts | 21 ------------ 6 files changed, 10 insertions(+), 71 deletions(-) delete mode 100644 code/renderers/vue3/template/stories/CustomRenderOptionsArgsFromProps.stories.ts diff --git a/code/renderers/vue3/src/decorateStory.ts b/code/renderers/vue3/src/decorateStory.ts index 3955eba07644..c831c3e1b450 100644 --- a/code/renderers/vue3/src/decorateStory.ts +++ b/code/renderers/vue3/src/decorateStory.ts @@ -1,9 +1,7 @@ -import type { ConcreteComponent, Component, ComponentOptions } from 'vue'; +import type { Component, ComponentOptions, ConcreteComponent } from 'vue'; import { h } from 'vue'; -import type { DecoratorFunction, StoryContext, LegacyStoryFn, Args } from '@storybook/types'; +import type { DecoratorFunction, LegacyStoryFn, StoryContext } from '@storybook/types'; import { sanitizeStoryContextUpdate } from '@storybook/preview-api'; -// eslint-disable-next-line import/no-extraneous-dependencies -import { looseEqual } from '@vue/shared'; import type { VueRenderer } from './types'; /* @@ -45,7 +43,6 @@ export function decorateStory( storyFn: LegacyStoryFn, decorators: DecoratorFunction[] ): LegacyStoryFn { - let updatedArgs: Args; return decorators.reduce( (decorated: LegacyStoryFn, decorator) => (context: StoryContext) => { let story: VueRenderer['storyResult'] | undefined; @@ -55,22 +52,20 @@ export function decorateStory( ...context, ...sanitizeStoryContextUpdate(update), }); - - if (update && update.args && !looseEqual(update.args, context.args)) - updatedArgs ??= update.args; return story; }, context); - context.args = updatedArgs ?? context.args; if (!story) story = decorated(context); if (decoratedStory === story) { return story; } - const innerStory = () => h(story!, context.args); + const innerStory = () => h(story!); return prepare(decoratedStory, innerStory) as VueRenderer['storyResult']; }, - (context) => prepare(storyFn(context)) as LegacyStoryFn + (context) => { + return prepare(storyFn(context)) as LegacyStoryFn; + } ); } diff --git a/code/renderers/vue3/src/render.ts b/code/renderers/vue3/src/render.ts index 9cb7973910ac..83e06165ede3 100644 --- a/code/renderers/vue3/src/render.ts +++ b/code/renderers/vue3/src/render.ts @@ -22,7 +22,7 @@ export const render: ArgsStoryFn = (props, context) => { ); } - return h(Component, props, createOrUpdateSlots(context)); + return () => h(Component, props, createOrUpdateSlots(context)); }; let setupFunction = (_app: any) => {}; @@ -73,7 +73,9 @@ export function renderToCanvas( map.set(canvasElement, appState); return () => { - return h(rootElement, appState.reactiveArgs); + // not passing args here as props + // treat the rootElement as a component without props + return h(rootElement); }; }, }); diff --git a/code/renderers/vue3/template/stories/CustomRenderFunctionalComponent.stories.ts b/code/renderers/vue3/template/stories/CustomRenderFunctionalComponent.stories.ts index 2e723ab01b98..bf70bc34f074 100644 --- a/code/renderers/vue3/template/stories/CustomRenderFunctionalComponent.stories.ts +++ b/code/renderers/vue3/template/stories/CustomRenderFunctionalComponent.stories.ts @@ -27,8 +27,6 @@ export { NoDecorators, DecoratorFunctionalComponent, DecoratorFunctionalComponentArgsFromContext, - DecoratorFunctionalComponentArgsFromProps, DecoratorComponentOptions, DecoratorComponentOptionsArgsFromData, - DecoratorComponentOptionsArgsFromProps, } from './ReactiveDecorators.stories'; diff --git a/code/renderers/vue3/template/stories/CustomRenderOptionsArgsFromData.stories.ts b/code/renderers/vue3/template/stories/CustomRenderOptionsArgsFromData.stories.ts index 75d25b464bff..9c904283d3bd 100644 --- a/code/renderers/vue3/template/stories/CustomRenderOptionsArgsFromData.stories.ts +++ b/code/renderers/vue3/template/stories/CustomRenderOptionsArgsFromData.stories.ts @@ -40,8 +40,6 @@ export { NoDecorators, DecoratorFunctionalComponent, DecoratorFunctionalComponentArgsFromContext, - DecoratorFunctionalComponentArgsFromProps, DecoratorComponentOptions, DecoratorComponentOptionsArgsFromData, - DecoratorComponentOptionsArgsFromProps, } from './ReactiveDecorators.stories'; diff --git a/code/renderers/vue3/template/stories/CustomRenderOptionsArgsFromProps.stories.ts b/code/renderers/vue3/template/stories/CustomRenderOptionsArgsFromProps.stories.ts deleted file mode 100644 index 68c0ee37997b..000000000000 --- a/code/renderers/vue3/template/stories/CustomRenderOptionsArgsFromProps.stories.ts +++ /dev/null @@ -1,33 +0,0 @@ -import type { Meta } from '@storybook/vue3'; -import { defineComponent } from 'vue'; -import Reactivity from './Reactivity.vue'; -import * as ReactiveDecorators from './ReactiveDecorators.stories'; - -const meta = { - ...ReactiveDecorators.default, - component: Reactivity, - render: (args, { argTypes }) => { - return defineComponent({ - props: Object.keys(argTypes), - components: { Reactivity }, - template: `
Custom render uses options api and binds args to props: - - {{ $props.default }} - - -
`, - }); - }, -} satisfies Meta; - -export default meta; - -export { - NoDecorators, - DecoratorFunctionalComponent, - DecoratorFunctionalComponentArgsFromContext, - DecoratorFunctionalComponentArgsFromProps, - DecoratorComponentOptions, - DecoratorComponentOptionsArgsFromData, - DecoratorComponentOptionsArgsFromProps, -} from './ReactiveDecorators.stories'; diff --git a/code/renderers/vue3/template/stories/ReactiveDecorators.stories.ts b/code/renderers/vue3/template/stories/ReactiveDecorators.stories.ts index 01c1727c4e8b..6f169b665f9f 100644 --- a/code/renderers/vue3/template/stories/ReactiveDecorators.stories.ts +++ b/code/renderers/vue3/template/stories/ReactiveDecorators.stories.ts @@ -69,16 +69,6 @@ export const DecoratorFunctionalComponentArgsFromContext: Story = { ], }; -export const DecoratorFunctionalComponentArgsFromProps: Story = { - decorators: [ - (storyFn, context) => { - const story = storyFn(); - return (args) => - h('div', [h('h2', `Decorator using args.label: ${args.label}`), h(story, context.args)]); - }, - ], -}; - export const DecoratorComponentOptions: Story = { decorators: [ (storyFn, context) => { @@ -99,14 +89,3 @@ export const DecoratorComponentOptionsArgsFromData: Story = { }, ], }; - -export const DecoratorComponentOptionsArgsFromProps: Story = { - decorators: [ - (storyFn, context) => { - return { - props: ['label'], - template: '

Decorator using label: {{label}}

', - }; - }, - ], -};