Skip to content

Functional component not receiving context when using the rest parameters #13182

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

Open
s-montigny-desautels opened this issue Apr 9, 2025 · 3 comments

Comments

@s-montigny-desautels
Copy link
Contributor

Vue version

3.5.13

Link to minimal reproduction

https://play.vuejs.org/#eNp9UsFOwzAM/RWTSztpyoTgNAoI0CTgAAiQOBAOVet2HWlSJemoVPXfcdKt7ADc4vee7Wc7PbtqGr5tkS1ZYjNTNQ4sura5EKqqG20c9GCwgAEKo2uISBpN1I2umxEXjC98xJ0VTCihMq2sg9qWcO7z4+gWpdTwpo3Mj6KZUMlibEeNKHBYNzJ1SBFA4iuFF0DfU41hCHDoQHiyOJCzOXOWuhVVyTdWKxqk92rBMlJXEs1j4ypyI9gSAuO5lMx83QfMmRbnezxbY/b5C76xnccEezJo0WxRsIlzqSnRjfTq5QE7ek9krfNWkvof8hmtlq33OMquW5WT7QNdcHsXdl6p8tWuOofK7ofyRr1yCHrB6ER+UX+N/mP3hJ+GPKEG2uLufLS/6fDr/dlDUcHO/K2wC2yORdpKB0WrMt8k5pxTZTsbOxn6REbBOhYsr7Y0C3jy/fiDW6md5bv0Sx7P6DMMbPgGnPHYTg==

Steps to reproduce

Create a functional component like this

export default function(...args) {
  return h("div", args[1].slots.default?.())
}

What is expected?

The slots to be rendered.

What is actually happening?

The slots is not rendered, since null is passed as second argument to the function

System Info

System:
    OS: Linux 6.13 Fedora Linux 41 (Workstation Edition)
    CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
    Memory: 11.61 GB / 31.12 GB
    Container: Yes
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.14.0 - /usr/bin/node
    Yarn: 1.22.22 - ~/.local/share/pnpm/yarn
    npm: 10.9.2 - /usr/bin/npm
    pnpm: 10.7.0 - ~/.local/share/pnpm/pnpm
    bun: 1.2.4 - ~/.local/share/pnpm/bun
  Browsers:
    Chrome: 135.0.7049.52

Any additional comments?

The length of the function seems to be checked. Is this optimization necessary?

render.length > 1
? render(
__DEV__ ? shallowReadonly(props) : props,
__DEV__
? {
get attrs() {
markAttrsAccessed()
return shallowReadonly(attrs)
},
slots,
emit,
}
: { attrs, slots, emit },
)
: render(
__DEV__ ? shallowReadonly(props) : props,
null as any /* we know it doesn't need it */,
),

@edison1105
Copy link
Member

edison1105 commented Apr 10, 2025

The length of the function seems to be checked. Is this optimization necessary?

Not sure, but a clear declaration of parameters, is always reasonable

a workaround.

export default function(props, ctx) {
  return h("div", ctx.slots.default?.())
}

@s-montigny-desautels
Copy link
Contributor Author

Not sure, but a clear declaration of parameters, is always reasonable

I agree. I was just confused why the context was null on a test I was doing (not real production code, quick prototyping), and I did not find a good reason for this behavior.

@jvxiao
Copy link

jvxiao commented Apr 23, 2025

Not sure, but a clear declaration of parameters, is always reasonable

I agree. I was just confused why the context was null on a test I was doing (not real production code, quick prototyping), and I did not find a good reason for this behavior.

Any clue?

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

No branches or pull requests

3 participants