Skip to content

Commit

Permalink
fix: load yoga binaries only once (#2864)
Browse files Browse the repository at this point in the history
  • Loading branch information
nnaku authored Sep 22, 2024
1 parent c2326ec commit e425ca4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/bright-ghosts-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@react-pdf/layout": patch
---

Prevent loading yoga-layout wasm binaries more than once
9 changes: 8 additions & 1 deletion packages/layout/src/yoga/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

import * as Yoga from 'yoga-layout';

let instance;

export const loadYoga = async () => {
const instance = await Yoga.loadYoga();
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 Yoga.loadYoga();
}

const config = instance.Config.create();

config.setPointScaleFactor(0);
Expand Down

0 comments on commit e425ca4

Please sign in to comment.