Explorar o código

async components: timeout should not trigger if already resolved (fix #5635)

Evan You %!s(int64=9) %!d(string=hai) anos
pai
achega
8d54aecdd0

+ 7 - 5
src/core/vdom/helpers/resolve-async-component.js

@@ -97,11 +97,13 @@ export function resolveAsyncComponent (
 
         if (isDef(res.timeout)) {
           setTimeout(() => {
-            reject(
-              process.env.NODE_ENV !== 'production'
-                ? `timeout (${res.timeout}ms)`
-                : null
-            )
+            if (isUndef(factory.resolved)) {
+              reject(
+                process.env.NODE_ENV !== 'production'
+                  ? `timeout (${res.timeout}ms)`
+                  : null
+              )
+            }
           }, res.timeout)
         }
       }

+ 23 - 0
test/unit/features/component/component-async.spec.js

@@ -292,5 +292,28 @@ describe('Component async', () => {
         done()
       }
     })
+
+    it('should not trigger timeout if resolved', done => {
+      const vm = new Vue({
+        template: `<div><test/></div>`,
+        components: {
+          test: () => ({
+            component: new Promise((resolve, reject) => {
+              setTimeout(() => {
+                resolve({ template: '<div>hi</div>' })
+              }, 10)
+            }),
+            error: { template: `<div>error</div>` },
+            timeout: 20
+          })
+        }
+      }).$mount()
+
+      setTimeout(() => {
+        expect(vm.$el.textContent).toBe('hi')
+        expect(`Failed to resolve async component`).not.toHaveBeenWarned()
+        done()
+      }, 30)
+    })
   })
 })