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

Skip empty Vue 3 slot generation #23650

Closed

Conversation

aapokiiso
Copy link

@aapokiiso aapokiiso commented Jul 28, 2023

What I did

We have structures like this in our components:

<div v-if="$slots.icon" class="p-4">
    <slot name="icon" />
</div>

With Storybook 7.1, these broke due to the Vue 3 renderer's updated slot generation. Previously it used story props to populate Vue component slots, but this was changed to use argTypes in 6c806b6, after which all stories had all slots defined. This would cause such conditions as the example above to always be truthy.

This commit modifies the slot generation a bit to allow slots to be undefined rather than defaulting to an () => undefined function value.

How to test

  1. Run a sandbox for template, e.g. yarn task --task sandbox --start-from auto --template vue3-vite/default-ts
  2. Open Storybook in your browser
  3. Access the Example/Button story and verify that the icon wrapper <span> does not exist on the button stories with no icon slot value defined.

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

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli/src/sandbox-templates.ts
  • Make sure this PR contains one of the labels below.

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

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>

We have this kind of structures in our components:

```
<div v-if="$slots.icon" class="p-4">
    <slot name="icon" />
</div>
```

With Storybook 7.1, these broke due to the Vue 3 renderer's updated slot generation.
Previously it used story props to populate Vue component slots, but this was
changed to use argTypes in 6c806b6, after which all stories had all slots defined.
This would cause such conditions as the example above to always be truthy.

This commit modifies the slot generation a bit to allow slots to be undefined
rather than defaulting to an `() => undefined` function value.
@aapokiiso aapokiiso force-pushed the vue3-skip-empty-slot-generation branch from e1202a9 to 88ac5c1 Compare July 28, 2023 14:21
@kasperpeulen kasperpeulen self-assigned this Jul 31, 2023
@kasperpeulen
Copy link
Contributor

I made another PR that should also fix this:
#23697

@kasperpeulen
Copy link
Contributor

Is fixed in 7.3.0-alpha.0

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.

None yet

3 participants