From c054164ba687a1b479f7d3e6070c0133eadf9315 Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 25 Feb 2021 10:13:36 +0800 Subject: [PATCH] fix(Toast): ssr error (#8214) --- src/toast/index.tsx | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/toast/index.tsx b/src/toast/index.tsx index 908d10495..31b017f78 100644 --- a/src/toast/index.tsx +++ b/src/toast/index.tsx @@ -1,5 +1,5 @@ import { ref, App, TeleportProps, getCurrentInstance } from 'vue'; -import { isObject, inBrowser } from '../utils'; +import { isObject, inBrowser, ComponentInstance } from '../utils'; import { mountComponent, usePopupState } from '../utils/mount-component'; import VanToast, { ToastType, ToastPosition } from './Toast'; import type { LoadingType } from '../loading'; @@ -47,8 +47,7 @@ const defaultOptions: ToastOptions = { closeOnClickOverlay: false, }; -// TODO remove any -let queue: any[] = []; +let queue: ComponentInstance[] = []; let allowMultiple = false; let currentOptions = { ...defaultOptions }; @@ -104,11 +103,6 @@ function createInstance() { } function getInstance() { - /* istanbul ignore if */ - if (!inBrowser) { - return {}; - } - if (!queue.length || allowMultiple) { const instance = createInstance(); queue.push(instance); @@ -118,6 +112,10 @@ function getInstance() { } function Toast(options: string | ToastOptions = {}) { + if (!inBrowser) { + return {} as ComponentInstance; + } + const toast = getInstance(); const parsedOptions = parseOptions(options); @@ -150,7 +148,7 @@ Toast.clear = (all?: boolean) => { } else if (!allowMultiple) { queue[0].clear(); } else { - queue.shift().clear(); + queue.shift()!.clear(); } } };