]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip: suspense feature flag
authorEvan You <yyx990803@gmail.com>
Mon, 9 Sep 2019 20:28:32 +0000 (16:28 -0400)
committerEvan You <yyx990803@gmail.com>
Wed, 11 Sep 2019 15:10:13 +0000 (11:10 -0400)
jest.config.js
packages/global.d.ts
packages/runtime-core/src/component.ts
packages/runtime-core/src/createRenderer.ts
rollup.config.js

index ab41aafa3781d5c89d44a039e2bc1ad1f805898a..956e0f7a42983b2670184d562f662fe19b6d5106 100644 (file)
@@ -4,7 +4,8 @@ module.exports = {
     __DEV__: true,
     __JSDOM__: true,
     __FEATURE_OPTIONS__: true,
-    __FEATURE_PRODUCTION_TIP__: false
+    __FEATURE_PRODUCTION_TIP__: false,
+    __FEATURE_SUSPENSE__: true
   },
   coverageDirectory: 'coverage',
   coverageReporters: ['html', 'lcov', 'text'],
index 60adb6451c692eaea1ea0e83c8987edc275876cd..6e0808fe0ff34c2956e016f6faf866f49bdbba17 100644 (file)
@@ -5,3 +5,4 @@ declare var __JSDOM__: boolean
 // Feature flags
 declare var __FEATURE_OPTIONS__: boolean
 declare var __FEATURE_PRODUCTION_TIP__: boolean
+declare var __FEATURE_SUSPENSE__: boolean
index e4524d33be2fbd1e5fc1998d3593582741de073f..60dfcbca6e34a9a3f074458a7a6d318bcc657829 100644 (file)
@@ -242,9 +242,16 @@ export function setupStatefulComponent(instance: ComponentInternalInstance) {
       isFunction(setupResult.then) &&
       isFunction(setupResult.catch)
     ) {
-      // async setup returned Promise.
-      // bail here and wait for re-entry.
-      instance.asyncDep = setupResult as Promise<any>
+      if (__FEATURE_SUSPENSE__) {
+        // async setup returned Promise.
+        // bail here and wait for re-entry.
+        instance.asyncDep = setupResult as Promise<any>
+      } else if (__DEV__) {
+        warn(
+          `setup() returned a Promise, but the version of Vue you are using ` +
+            `does not support it yet.`
+        )
+      }
       return
     } else {
       handleSetupResult(instance, setupResult)
index a582faeb1c0acbba340d94e66ce0c94806b6babe..1889aa469b22a56855023f7e98cbd4d113202420 100644 (file)
@@ -194,15 +194,19 @@ export function createRenderer<
         )
         break
       case Suspense:
-        processSuspense(
-          n1,
-          n2,
-          container,
-          anchor,
-          parentComponent,
-          isSVG,
-          optimized
-        )
+        if (__FEATURE_SUSPENSE__) {
+          processSuspense(
+            n1,
+            n2,
+            container,
+            anchor,
+            parentComponent,
+            isSVG,
+            optimized
+          )
+        } else if (__DEV__) {
+          warn(`Suspense is not enabled in the version of Vue you are using.`)
+        }
         break
       default:
         if (shapeFlag & ShapeFlags.ELEMENT) {
@@ -730,10 +734,16 @@ export function createRenderer<
     } else {
       const instance = (n2.component =
         n1.component) as ComponentInternalInstance
+
       // async still pending
-      if (instance.asyncDep && !instance.asyncResolved) {
+      if (
+        __FEATURE_SUSPENSE__ &&
+        instance.asyncDep &&
+        !instance.asyncResolved
+      ) {
         return
       }
+
       // a resolved async component, on successful re-entry.
       // pickup the mounting process and setup render effect
       if (!instance.update) {
@@ -741,7 +751,8 @@ export function createRenderer<
       } else if (
         shouldUpdateComponent(n1, n2, optimized) ||
         // TODO use context suspense
-        (instance.provides.suspense &&
+        (__FEATURE_SUSPENSE__ &&
+          instance.provides.suspense &&
           !(instance.provides.suspense as any).isResolved)
       ) {
         // normal update
@@ -791,7 +802,7 @@ export function createRenderer<
 
     // setup() is async. This component relies on async logic to be resolved
     // before proceeding
-    if (instance.asyncDep) {
+    if (__FEATURE_SUSPENSE__ && instance.asyncDep) {
       // TODO use context suspense
       const suspense = (instance as any).provides.suspense
       if (!suspense) {
index 3f530bbcaf321eb56c44ee3ba21086e95d5d327a..e94a5ce17ad4e397f78d7985e23dc14a64f5f0a9 100644 (file)
@@ -140,6 +140,7 @@ function createReplacePlugin(isProduction, isBunlderESMBuild, isBrowserBuild) {
     // support options?
     // the lean build drops options related code with buildOptions.lean: true
     __FEATURE_OPTIONS__: !packageOptions.lean,
+    __FEATURE_SUSPENSE__: true,
     // this is only used during tests
     __JSDOM__: false
   })