Skip to content

Commit

Permalink
fix: prevent loading and overriding CanvasKit multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniHv committed Jan 6, 2024
1 parent 4ee9621 commit e299b1e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion package/src/web/LoadSkiaWeb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ declare global {
var CanvasKit: CanvasKitType;
}

let ckSharedPromise: Promise<CanvasKitType>;

export const LoadSkiaWeb = async (opts?: CanvasKitInitOptions) => {
if (global.CanvasKit !== undefined) {
return;
}
const CanvasKit = await CanvasKitInit(opts);
ckSharedPromise = ckSharedPromise ?? CanvasKitInit(opts);
const CanvasKit = await ckSharedPromise;
// The CanvasKit API is stored on the global object and used
// to create the JsiSKApi in the Skia.web.ts file.
global.CanvasKit = CanvasKit;
Expand Down

0 comments on commit e299b1e

Please sign in to comment.