vuejs / core

🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
https://vuejs.org/
MIT License
47.75k stars 8.35k forks source link

fix(ssr): properly init slots during ssr rendering #12441

Open edison1105 opened 2 days ago

edison1105 commented 2 days ago

close #12438

during SSR rendering, the optimized parameter passed to initSlots is always false. The slots._ flag is lost when initSlots is called in setupComponent for the child component. This triggers the logic inside normalizeObjectSlots, resulting in slotFn returning an array that includes a comment node. https://github.com/vuejs/core/blob/413c9239b1751498364d2ff7e3e0cdd642ede377/packages/server-renderer/src/helpers/ssrRenderSlot.ts#L59-L65

related commit https://github.com/vuejs/core/commit/3d34f406ac7497dafd2f4e62ab23579b78a0e08a#diff-56930a63772d2e89f19432918b9d6ed851ede4159b0d32404e0c1d8c159fec99R1232 SSR rendering does not need to patch slots, so there won't be an issue similar to #10870. Perhaps the optimized parameter can always be set to true.

github-actions[bot] commented 2 days ago

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 100 kB (+3 B) 37.9 kB (-1 B) 34.2 kB (-2 B)
vue.global.prod.js 158 kB (+3 B) 57.8 kB (+3 B) 51.5 kB (+99 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 47.2 kB (+3 B) 18.3 kB (+2 B) 16.8 kB (-3 B)
createApp 55.2 kB (+3 B) 21.3 kB (+2 B) 19.5 kB (-6 B)
createSSRApp 59.3 kB (+3 B) 23.1 kB (+4 B) 21 kB (+1 B)
defineCustomElement 60.1 kB (+3 B) 22.9 kB (+3 B) 20.9 kB (+3 B)
overall 69.1 kB (+3 B) 26.5 kB (+2 B) 24.1 kB (+15 B)
pkg-pr-new[bot] commented 2 days ago

Open in Stackblitz

@vue/compiler-core

``` pnpm add https://pkg.pr.new/@vue/compiler-core@12441 ```

@vue/compiler-dom

``` pnpm add https://pkg.pr.new/@vue/compiler-dom@12441 ```

@vue/compiler-ssr

``` pnpm add https://pkg.pr.new/@vue/compiler-ssr@12441 ```

@vue/compiler-sfc

``` pnpm add https://pkg.pr.new/@vue/compiler-sfc@12441 ```

@vue/reactivity

``` pnpm add https://pkg.pr.new/@vue/reactivity@12441 ```

@vue/runtime-core

``` pnpm add https://pkg.pr.new/@vue/runtime-core@12441 ```

@vue/runtime-dom

``` pnpm add https://pkg.pr.new/@vue/runtime-dom@12441 ```

@vue/server-renderer

``` pnpm add https://pkg.pr.new/@vue/server-renderer@12441 ```

@vue/shared

``` pnpm add https://pkg.pr.new/@vue/shared@12441 ```

vue

``` pnpm add https://pkg.pr.new/vue@12441 ```

@vue/compat

``` pnpm add https://pkg.pr.new/@vue/compat@12441 ```

commit: 413c923