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

Vue3: Fix CSF2 support with decorators #20995

Merged
merged 18 commits into from
Feb 13, 2023

Conversation

chakAs3
Copy link
Contributor

@chakAs3 chakAs3 commented Feb 7, 2023

Closes #20903

that was one issue reported by user, CSF2 does not work in V7 + one issue I spotted in rendering decorated Stories without a defined render function

What I did

I fixed the rendering for stories with decorators both for CSF2 and CSF3 + some optimisation and code refactoring

How to test

  1. Run a sandbox for template, e.g. yarn task --task sandbox --start-from auto --template vue3-vite/default-ts
  2. you need add some stories with decorators , CSF2 and CSF3
type CSF2Story = StoryFn<typeof Button>;

export const CSF2Button: CSF2Story = (args, { argTypes }) => ({
  components: { Button },
  props: Object.keys(argTypes),
  template: '<Button v-bind="$props" />',
})


CSF2Button.args = {
  label: 'Button',
};

Small.decorators = WithRenderTemplate.decorators = CSF2Button.decorators =[  
  () => ({
    template: '<div style="display: flex; padding: 20px; background-color: #cccc72;"><story /></div>',
  }),
];
  1. Access CSF2 Button Story
    image

Checklist

  • Make sure your changes are tested (stories and/or unit, integration, or end-to-end tests)
  • Make sure to add/update documentation regarding your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Maintainers

  • If this PR should be tested against many or all sandboxes,
    make sure to add the ci:merged or ci:daily GH label to it.
  • Make sure this PR contains one of the labels below.

["cleanup", "BREAKING CHANGE", "feature request", "bug", "documentation", "maintenance", "dependencies", "other"]

@shilman shilman changed the title Vue3:fix CSF2 support with decorators Vue3: Fix CSF2 support with decorators Feb 8, 2023
@shilman shilman self-assigned this Feb 10, 2023
Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @chakAs3 !!! Thank you for fixing this 🙏

I don't know Vue well enough to comment on the core changes. However, I have a few questions about the tests.

// fetch the story with the updated context (with reactive args)
const element: StoryFnVueReturnType = storyFn(storyContext);

if (!element) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we removing error handling here?

Copy link
Contributor Author

@chakAs3 chakAs3 Feb 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, i removed it because it will never happen as we don't need to define the template any more, especially in CSF3, but I don't know if CSF2 requires this... Please guide me on this, anyway will put it back for now

Copy link
Contributor Author

@chakAs3 chakAs3 Feb 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

so if can see this will just work even if the story template has no component

export const WithRenderTemplate: Story = {
  args: {
    label: 'Button',
    size: 'small',
  },
  render(args: any){
    return ({
    components: { Button },
    setup() {
      return { args };
    },
    template: '<b> No Button Component  <pre>{{ args }}</pre></b>' ,
    })
  },
};

Copy link
Contributor Author

@chakAs3 chakAs3 Feb 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shilman I have done more tests and even with CSF2 no error rises, However, Vue handles the case when there is no template defined,it shows a Warning message on the console.
let me know if still want me to keep it.

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this snapshot test looks wrong:

https://www.chromatic.com/test?appId=630513346a8e284ae244d415&id=63e68ea075d92124fe23bb78

Looking at the play function, it seems like the story rendering in chromatic is inconsistent with the play function assertions

https://github.com/storybookjs/storybook/blob/next/code/lib/store/template/stories/args.stories.ts#L65-L80

@chakAs3
Copy link
Contributor Author

chakAs3 commented Feb 11, 2023

Also, this snapshot test looks wrong:

https://www.chromatic.com/test?appId=630513346a8e284ae244d415&id=63e68ea075d92124fe23bb78

Looking at the play function, it seems like the story rendering in chromatic is inconsistent with the play function assertions

https://github.com/storybookjs/storybook/blob/next/code/lib/store/template/stories/args.stories.ts#L65-L80

Yes should fail sorry i forgot to pass to reactiveArgs variable instead of context.args it should be fine now

@shilman shilman mentioned this pull request Feb 13, 2023
2 tasks
Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Any chance you can add a test case for CSF2 before we merge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: $props object values are undefined in Storybook 7 with vue3 and vuetify 3
2 participants