Skip to content

Commit

Permalink
Merge pull request #2122 from DaniHv/fix/web-wasm-duplicated-loads
Browse files Browse the repository at this point in the history
Make LoadSkiaWeb() load the CanvasKit wasm only once
  • Loading branch information
wcandillon authored Jan 7, 2024
2 parents b92f764 + e299b1e commit 8f80968
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 8f80968

Please sign in to comment.