storybook: [Bug]: Vue3 sourcecode does not reflect given template

Describe the bug

When editing stories, sometimes you need to create your own template from the setup function, to inject big content into slots (which contain subcomponents). It was working for me with the v8.2.9, but after the migration (currently 8.5.0) nothing is working as expected.

The only code output I have is the name of the component, its args if given, and that’s it. To be honest I’m quite surprised, because there is no specific configuration/context to reproduce it. It’s directly reproducible from a fresh project.

Is there anything new since the 8.4.0 ? Do we have to use only args with named slots into it to render our slots and have the right code snippet ? It doesn’t work anyway when tryin to render other Vue components into it, from a basic string.

Thanks !

Reproduction link

None

Reproduction steps

  1. Create a new storybook project, from scratch in an empty directory: npx storybook@8.5.0
  2. Select @storybook/vue3-vite from the prompt
  3. Run the storybook locally
  4. Edit the Button example component (src/stories/Button.vue) generated by default, and add a default slot
  5. Change the story of the Button component, to use the setup system like following :
export const Primary: Story = {
  render: (args: any) => ({
    components: { Button },
    setup() {
      return { args };
    },
    template: 'Test',
  }),
  args: {
    primary: true,
    label: 'Button',
  },
};

The code snippet should render “Test” only, but it does not. I only have

<template>
  <Button :primary="false" />
</template>

Image

System

Storybook Environment Info:
  Binaries:
    Node: 18.17.1 - ~/.nvm/versions/node/v18.17.1/bin/node
    npm: 9.6.7 - ~/.nvm/versions/node/v18.17.1/bin/npm
    pnpm: 8.7.5 - ~/.nvm/versions/node/v18.17.1/bin/pnpm <----- active
  Browsers:
    Chrome: 131.0.6778.204
  npmPackages:
    @storybook/addon-essentials: 8.5.0 => 8.5.0 
    @storybook/addon-interactions: 8.5.0 => 8.5.0 
    @storybook/addon-onboarding: 8.5.0 => 8.5.0 
    @storybook/blocks: 8.5.0 => 8.5.0 
    @storybook/test: 8.5.0 => 8.5.0 
    @storybook/vue3: 8.5.0 => 8.5.0 
    @storybook/vue3-vite: 8.5.0 => 8.5.0 
    storybook: 8.5.0 => 8.5.0

Additional context

No response

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 6
  • Comments: 17 (9 by maintainers)

Most upvoted comments

@larsrickert @shilman Hi, I am also encountering this issue and before moving on to refactoring all existing stories to follow the suggested pattern, I wanted to ask whether it is planned for this to be fixed anytime soon - I saw this issue was included in the v9 milestone by @vanessayuenn , but it is not clear if the custom template code generation as a whole will be addressed on that occasion.

Thanks in advance!

Hello, I have a question. What if I want to render two components in one slot? I mean

<ButtonsContainer>
  <Button>Cancel</Button>
  <Button>Confirm</Button>
</ButtonsContainer>

Just pass them as array:

import type { Meta, StoryObj } from "@storybook/vue3";
import ButtonsContainer from "./ButtonsContainer.vue";
import { h } from "vue";

const meta: Meta<typeof ButtonsContainer> = {
  component: ButtonsContainer,
};

export default meta;
type Story = StoryObj<typeof ButtonsContainer>;

export const Default = {
  args: {
    default: [h(Button, "Cancel"), h(Button, "Confirm")],
  },
} satisfies Story;

ok thank you @larsrickert ! But I’m surprised because it used to work for years (since the v7, even v6 if I remember well)

Is there any workaround for this ? There are some good features in the latest versions.

There was a full re-write of the Vue source code generator in #27194 which has a lot of improvements, especially for generating code for slots and v-models.

Whats your use case for the custom render function? I guess originally this was needed to pass slot content which is no longer necessary because you can pass them directly as arg:

export const Primary: Story = {
  args: {
    primary: true,
    label: 'Button',
    mySlot: h(MyCustomComponent, { propA: "Hello World" })
    myOtherSlot: "I am just a string slot"
  },
};

As workaround, you can define the code snippet manually like so:

export const Primary: Story = {
  parameters: {
    docs: {
      source: {
        code: "<div> My custom source code </div>",
      },
    },
  },
};