Skip to content

slots are now functions instead of arrays #2045

@Haroenv

Description

@Haroenv

Version

3.0.0-rc.10

Reproduction link

v2: https://codesandbox.io/s/new-silence-wx19w?file=/src/components/Provider.js

v3 https://codesandbox.io/s/eager-currying-uqj9y?file=/src/Provider.js

Steps to reproduce

Run this:

import { h } from 'vue';

export default {
  render() {
    return h('div', {}, this.$slots.default);
  },
};

and use it like <Provider> some content </Provider>

What is expected?

this.$slots.default renders the children

What is actually happening?

this.$slots.default() renders the children


I'm trying to make a library compatible with v2 & v3 at the same time, but I had a hard time finding out that slots now need to be called. In https://v3.vuejs.org/guide/migration/slots-unification.html#_3-x-syntax this doesn't seem to be mentioned

Workaround I found:

import { h } from "vue";

export default {
  render(localH) {
    return (h || localH)(
      "div",
      {},
      typeof this.$slots.default === "function"
        ? this.$slots.default()
        : this.$slots.default
    );
  }
};

Should this be documented or am I missing something? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions