diff --git a/src/yoga/index.ts b/src/yoga/index.ts index 1dc3bf91..89c55b0a 100644 --- a/src/yoga/index.ts +++ b/src/yoga/index.ts @@ -4,10 +4,22 @@ export function init(yoga: typeof Yoga) { Yoga = yoga } +let initializationPromise = null + export default async function getYoga(): Promise { - if (!Yoga) { - const mod = await import('@yoga') - Yoga = await mod.getYogaModule() + if (Yoga) return Yoga + + if (initializationPromise) { + await initializationPromise + return Yoga } + + initializationPromise = import('@yoga') + .then((mod) => mod.getYogaModule()) + .then((yogaInstance) => (Yoga = yogaInstance)) + + await initializationPromise + initializationPromise = null + return Yoga }