]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat: warn ref usage on functional components
authorEvan You <yyx990803@gmail.com>
Sun, 3 Nov 2019 01:33:37 +0000 (21:33 -0400)
committerEvan You <yyx990803@gmail.com>
Sun, 3 Nov 2019 01:33:37 +0000 (21:33 -0400)
packages/runtime-core/src/renderer.ts

index 8f67ce6b4f037445f6494cb57ee7db3eac3c7646..3416cccd0ed4414973477d229fbb161871d0bc1a 100644 (file)
@@ -804,6 +804,14 @@ export function createRenderer<
       }
     }
     if (n2.ref !== null && parentComponent !== null) {
+      if (__DEV__ && !(n2.shapeFlag & ShapeFlags.STATEFUL_COMPONENT)) {
+        pushWarningContext(n2)
+        warn(
+          `Functional components do not support "ref" because they do not ` +
+            `have instances.`
+        )
+        popWarningContext()
+      }
       setRef(n2.ref, n1 && n1.ref, parentComponent, n2.component!.renderProxy)
     }
   }