vue icon indicating copy to clipboard operation
vue copied to clipboard

Optimized async functional components fail to server-side render on initial render

Open vetruvet opened this issue 1 year ago • 0 comments

Version

2.7.14

Reproduction link

stackblitz.com

Steps to reproduce

Run main.js in the reproduction link

What is expected?

Each render in that reproduction would work

What is actually happening?

The first render of OptimizedAsyncFunctionalComponent fails, but subsequent ones succeed.


It appears that vue-server-renderer calls installSSRHelpers which adds _ssrNode and other SSR optimization helpers to Vue.prototype and Vue.FunctionalRenderContext.prototype. However, when rendering an async functional component, the built version of vue-server-renderer has its own definition of FunctionalRenderContext (appears to be bundled at build time along with things like createFunctionalComponent instead of importing from vue itself at runtime) which does not have the SSR helpers on it.

Setting optimizeSSR: false in vue-loader options seems to work as a bandaid solution since the optimization helpers are not used, but this seems like a bad idea for performance. EDIT: also, changing it to a regular component (not functional) also works as a workaround

vetruvet avatar Mar 15 '23 16:03 vetruvet