]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(ssr): inherit scope id on functional component during ssr
authorEvan You <yyx990803@gmail.com>
Tue, 17 May 2022 09:45:53 +0000 (17:45 +0800)
committerEvan You <yyx990803@gmail.com>
Tue, 17 May 2022 09:45:53 +0000 (17:45 +0800)
fix #5817

packages/server-renderer/src/render.ts

index 4090ef9f451530f47c0cc538cd2afc71b2197491..ae71a9e627583e577d07f41dc936ffe5e0620cca 100644 (file)
@@ -4,6 +4,7 @@ import {
   ComponentInternalInstance,
   DirectiveBinding,
   Fragment,
+  FunctionalComponent,
   mergeProps,
   ssrUtils,
   Static,
@@ -112,12 +113,17 @@ function renderComponentSubTree(
   const comp = instance.type as Component
   const { getBuffer, push } = createBuffer()
   if (isFunction(comp)) {
-    renderVNode(
-      push,
-      (instance.subTree = renderComponentRoot(instance)),
-      instance,
-      slotScopeId
-    )
+    let root = renderComponentRoot(instance)
+    // #5817 scope ID attrs not falling through if functional component doesn't
+    // have props
+    if (!(comp as FunctionalComponent).props) {
+      for (const key in instance.attrs) {
+        if (key.startsWith(`data-v-`)) {
+          ;(root.props || (root.props = {}))[key] = ``
+        }
+      }
+    }
+    renderVNode(push, (instance.subTree = root), instance, slotScopeId)
   } else {
     if (
       (!instance.render || instance.render === NOOP) &&