Skip to content

Commit 58f9a04

Browse files
authored
fix: prevent Yoga init from running more than once (#2878)
1 parent f5a8b02 commit 58f9a04

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

.changeset/slow-ravens-type.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@react-pdf/layout": patch
3+
---
4+
5+
Prevent Yoga init from running more than once

packages/layout/src/yoga/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22

33
import { loadYoga as yogaLoadYoga } from 'yoga-layout/load';
44

5-
let instance;
5+
let instancePromise;
66

77
export const loadYoga = async () => {
8-
if (!instance) {
9-
// Yoga WASM binaries must be asynchronously compiled and loaded
10-
// to prevent Event emitter memory leak warnings, Yoga must be loaded only once
11-
instance = await yogaLoadYoga();
12-
}
8+
// Yoga WASM binaries must be asynchronously compiled and loaded
9+
// to prevent Event emitter memory leak warnings, Yoga must be loaded only once
10+
const instance = await (instancePromise ??= yogaLoadYoga());
1311

1412
const config = instance.Config.create();
1513

0 commit comments

Comments
 (0)