Skip to content

Commit 8f80968

Browse files
authored
Merge pull request #2122 from DaniHv/fix/web-wasm-duplicated-loads
Make LoadSkiaWeb() load the CanvasKit wasm only once
2 parents b92f764 + e299b1e commit 8f80968

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)