Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Prevent Yoga init from running more than once #2878

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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