Skip to content

Commit

Permalink
fix: prevent Yoga init from running more than once (#2878)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmezzacappa authored Nov 14, 2024
1 parent f5a8b02 commit 58f9a04
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-ravens-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@react-pdf/layout": patch
---

Prevent Yoga init from running more than once
10 changes: 4 additions & 6 deletions packages/layout/src/yoga/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

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

let instance;
let instancePromise;

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

const config = instance.Config.create();

Expand Down

0 comments on commit 58f9a04

Please sign in to comment.