Subscribe on changes!

(compat) slots are undefined in functional component during first render

avatar
Jun 15th 2021

Version

@vue/compat 3.1.1

Reproduction link

@vue/compat@3.1.1 - https://jsfiddle.net/yc3r45jo/ (with bug) vue@3.1.1 - https://jsfiddle.net/Ln6e9yvb/

Steps to reproduce

Open @vue/compat reproduction

What is expected?

Should render button component

What is actually happening?

App crashes because button component throws error

Uncaught TypeError: Cannot read property 'default' of undefined

and it throws an error because of this line const children = slots.default?.();

for some reason in compatibility build functional component renders twice and during first render slots object is undefined. // edit: same thing happens with attrs, also undefined

Everything works fine in vue@3.1.1


I also have a side question. Why when I log props or attrs in the console it shows me the resulat as ƒ () { [native code] } instead of just log the object? This is only the case in compatibility build.

avatar
Jun 15th 2021

It seems like it's treating the function as an async component (Vue 2 syntax)

avatar
Jun 15th 2021

oh my somehow i missed that this behaviour is intentional and I should configure compat build like this:

configureCompat({ COMPONENT_ASYNC: false });

I think we can close it now, sorry for false alarm