Subscribe on changes!

[SSR Warning Bug] "SSR-optimized slot function detected"

avatar
Feb 22nd 2021

Version

3.0.5

Steps to reproduce

In any SSR'd application that makes use of slots, you should see the erroneous warning. [Vue warn]: SSR-optimized slot function detected in a non-SSR-optimized render function. You need to mark this component with $dynamic-slots in the parent template.

Solution

On this line: https://github.com/vuejs/vue-next/blob/f81484dbc07734926e47faab07153ea7e6e3b672/packages/runtime-core/src/helpers/renderSlot.ts#L32

A length check is being applied to a function When using length on a function, it will return the number of arguments.

Since the number of arguments is always 4, it will always return 4.

Since the check looks for a length greater than 1, it will always issue a warning.

...Assuming this length check was intended for an array, not a function.

HOWEVER, if this check was intended and there is some magic going on with the number of arguments.. then please document the $dynamic-slots config as nothing is coming up on a search (except other confused users) #2970

avatar
Feb 23rd 2021

Hi, thank you for your interest in Vue, but do you agree that this is a duplicate of #2970?

avatar
Feb 23rd 2021

@HcySunYang sure, close this one or the other to prevent duplication. I just wanted to surface the issue.

avatar
Feb 23rd 2021

Duplicate of #2970?

avatar
Feb 24th 2021

@HcySunYang can you please close the other ticket in favor of this one? I provide the (easy) fix and also I'm worried that ticket is buried already.

In SSR it creates super annoying output: Screen Shot 2021-02-24 at 12 05 35 PM

avatar
Feb 24th 2021

@arpowers in that case, it will make more sense if you open the PR with the fix and the test and reference the other issue which was opened first.

avatar
Mar 22nd 2021

@HcySunYang suggest this check is removed since it also causes slots not to work with SSR