Skip to content

Commit e299b1e

Browse files
committed
fix: prevent loading and overriding CanvasKit multiple times
1 parent 4ee9621 commit e299b1e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

package/src/web/LoadSkiaWeb.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ declare global {
1010
var CanvasKit: CanvasKitType;
1111
}
1212

13+
let ckSharedPromise: Promise<CanvasKitType>;
14+
1315
export const LoadSkiaWeb = async (opts?: CanvasKitInitOptions) => {
1416
if (global.CanvasKit !== undefined) {
1517
return;
1618
}
17-
const CanvasKit = await CanvasKitInit(opts);
19+
ckSharedPromise = ckSharedPromise ?? CanvasKitInit(opts);
20+
const CanvasKit = await ckSharedPromise;
1821
// The CanvasKit API is stored on the global object and used
1922
// to create the JsiSKApi in the Skia.web.ts file.
2023
global.CanvasKit = CanvasKit;

0 commit comments

Comments
 (0)