]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(runtime-core): remove the need for currentSuspense
authorEvan You <yyx990803@gmail.com>
Mon, 30 Mar 2020 15:49:51 +0000 (11:49 -0400)
committerEvan You <yyx990803@gmail.com>
Mon, 30 Mar 2020 15:49:51 +0000 (11:49 -0400)
packages/runtime-core/src/apiAsyncComponent.ts
packages/runtime-core/src/apiWatch.ts
packages/runtime-core/src/component.ts
packages/runtime-core/src/renderer.ts
packages/server-renderer/src/renderToString.ts

index 62b50a1ecda084288a420ece077b5d7c7c6a498b..20c3a48ff74e416530b96a5364c99813422e64c6 100644 (file)
@@ -1,7 +1,6 @@
 import {
   PublicAPIComponent,
   Component,
-  currentSuspense,
   currentInstance,
   ComponentInternalInstance,
   isInSSRComponentSetup
@@ -118,7 +117,7 @@ export function defineAsyncComponent<
 
       // suspense-controlled or SSR.
       if (
-        (__FEATURE_SUSPENSE__ && suspensible && currentSuspense) ||
+        (__FEATURE_SUSPENSE__ && suspensible && instance.suspense) ||
         (__NODE_JS__ && isInSSRComponentSetup)
       ) {
         return load()
index 9d477ac8d43b4211acbb4c40e8206530912178d5..967c77f8f977bc920eb034ad8df5ab0955da1796 100644 (file)
@@ -20,7 +20,6 @@ import {
 import {
   currentInstance,
   ComponentInternalInstance,
-  currentSuspense,
   Data,
   isInSSRComponentSetup,
   recordInstanceBoundEffect
@@ -139,7 +138,6 @@ function doWatch(
   }
 
   const instance = currentInstance
-  const suspense = currentSuspense
 
   let getter: () => any
   if (isArray(source)) {
@@ -238,9 +236,7 @@ function doWatch(
       }
     }
   } else {
-    scheduler = job => {
-      queuePostRenderEffect(job, suspense)
-    }
+    scheduler = job => queuePostRenderEffect(job, instance && instance.suspense)
   }
 
   const runner = effect(getter, {
index a346eb0c81fff44af90c853ec731caf6cc7e0060..bf5aaeeb7061f46fbea53ec0924f18c49a162307 100644 (file)
@@ -145,6 +145,7 @@ export interface ComponentInternalInstance {
   emit: Emit
 
   // suspense related
+  suspense: SuspenseBoundary | null
   asyncDep: Promise<any> | null
   asyncResolved: boolean
 
@@ -177,7 +178,8 @@ const emptyAppContext = createAppContext()
 
 export function createComponentInstance(
   vnode: VNode,
-  parent: ComponentInternalInstance | null
+  parent: ComponentInternalInstance | null,
+  suspense: SuspenseBoundary | null
 ) {
   // inherit parent app context - or - if root, adopt from root vnode
   const appContext =
@@ -213,7 +215,8 @@ export function createComponentInstance(
     components: Object.create(appContext.components),
     directives: Object.create(appContext.directives),
 
-    // async dependency management
+    // suspense related
+    suspense,
     asyncDep: null,
     asyncResolved: false,
 
@@ -266,7 +269,6 @@ export function createComponentInstance(
 }
 
 export let currentInstance: ComponentInternalInstance | null = null
-export let currentSuspense: SuspenseBoundary | null = null
 
 export const getCurrentInstance: () => ComponentInternalInstance | null = () =>
   currentInstance || currentRenderingInstance
@@ -351,7 +353,6 @@ function setupStatefulComponent(
       setup.length > 1 ? createSetupContext(instance) : null)
 
     currentInstance = instance
-    currentSuspense = parentSuspense
     pauseTracking()
     const setupResult = callWithErrorHandling(
       setup,
@@ -361,7 +362,6 @@ function setupStatefulComponent(
     )
     resetTracking()
     currentInstance = null
-    currentSuspense = null
 
     if (isPromise(setupResult)) {
       if (isSSR) {
@@ -478,10 +478,8 @@ function finishComponentSetup(
   // support for 2.x options
   if (__FEATURE_OPTIONS__) {
     currentInstance = instance
-    currentSuspense = parentSuspense
     applyOptions(instance, Component)
     currentInstance = null
-    currentSuspense = null
   }
 }
 
index 976022fcfe5212e1e14a523b82b9c0e847cb23f5..5952abc73459b6383eb68941910a66788f210bb1 100644 (file)
@@ -1028,7 +1028,8 @@ function baseCreateRenderer(
   ) => {
     const instance: ComponentInternalInstance = (initialVNode.component = createComponentInstance(
       initialVNode,
-      parentComponent
+      parentComponent,
+      parentSuspense
     ))
 
     if (__HMR__ && instance.type.__hmrId) {
index 5c84ae7aec70a52c10a3e4e222e19a375e369fbd..8cb4b392f305062532f4ae8cfc2b45818af8a0c8 100644 (file)
@@ -144,7 +144,7 @@ function renderComponentVNode(
   vnode: VNode,
   parentComponent: ComponentInternalInstance | null = null
 ): ResolvedSSRBuffer | Promise<ResolvedSSRBuffer> {
-  const instance = createComponentInstance(vnode, parentComponent)
+  const instance = createComponentInstance(vnode, parentComponent, null)
   const res = setupComponent(
     instance,
     null /* parentSuspense (no need to track for SSR) */,