From 43c8d3a7dab8ac499061d0e845416cc0e680e4ee Mon Sep 17 00:00:00 2001 From: jimizai <359743984@qq.com> Date: Thu, 1 Feb 2024 18:17:36 +0800 Subject: [PATCH 1/2] feat: use async call replace sync call --- packages/cache-canvas/src/index.tsx | 124 +++++++++++++--------------- 1 file changed, 58 insertions(+), 66 deletions(-) diff --git a/packages/cache-canvas/src/index.tsx b/packages/cache-canvas/src/index.tsx index dbb4707bb6..2872e7feee 100644 --- a/packages/cache-canvas/src/index.tsx +++ b/packages/cache-canvas/src/index.tsx @@ -1,8 +1,5 @@ import { useEffect, useState, useImperativeHandle, forwardRef, useCallback } from 'react'; -import type { - HTMLAttributes, - ReactElement, -} from 'react'; +import type { HTMLAttributes, ReactElement } from 'react'; import * as React from 'react'; import { isNode } from 'universal-env'; import { Storage } from './storage'; @@ -47,17 +44,7 @@ export type CacheCanvasProps = { }; export const CacheCanvas = forwardRef((props: CacheCanvasProps, ref) => { - const { - id, - init, - useCache = true, - getSnapshot, - fallback, - style, - className, - bizID = '', - ...rest - } = props; + const { id, init, useCache = true, getSnapshot, fallback, style, className, bizID = '', ...rest } = props; const [renderedCanvas, setRenderedCanvas] = useState(!useCache); const [mounted, setMounted] = useState(false); @@ -102,69 +89,74 @@ export const CacheCanvas = forwardRef((props: CacheCanvasProps, ref) => { return ( <> - - { - !renderedCanvas && (<> + + {!renderedCanvas && ( + <> - { - (typeof fallback === 'function') && (