Skip to content

Commit

Permalink
Async load Yoga after all
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Jun 28, 2024
1 parent 77b12f3 commit b1e2d6c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/layout/src/steps/resolveYoga.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { loadYoga } from '../yoga/index';

const resolveYoga = (root) => {
const yoga = loadYoga();
const resolveYoga = async (root) => {
const yoga = await loadYoga();

return Object.assign({}, root, { yoga });
};
Expand Down
9 changes: 5 additions & 4 deletions packages/layout/src/yoga/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/* eslint-disable import/prefer-default-export */

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

export const loadYoga = () => {
const config = Yoga.Config.create();
export const loadYoga = async () => {
const instance = await importedLoadYoga();
const config = instance.Config.create();

config.setPointScaleFactor(0);

const node = { create: () => Yoga.Node.createWithConfig(config) };
const node = { create: () => instance.Node.createWithConfig(config) };

return { node };
};
10 changes: 5 additions & 5 deletions packages/layout/tests/steps/resolvePagination.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const calcLayout = (node) => resolvePagination(resolveDimensions(node));

describe('pagination step', () => {
test('should stretch absolute block to full page size', async () => {
const yoga = loadYoga();
const yoga = await loadYoga();

const root = {
type: 'DOCUMENT',
Expand Down Expand Up @@ -63,7 +63,7 @@ describe('pagination step', () => {
});

test('should force new height for split nodes', async () => {
const yoga = loadYoga();
const yoga = await loadYoga();

const root = {
type: 'DOCUMENT',
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('pagination step', () => {
});

test('should force new height for split nodes with fixed height', async () => {
const yoga = loadYoga();
const yoga = await loadYoga();

const root = {
type: 'DOCUMENT',
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('pagination step', () => {
});

test('should not wrap page with false wrap prop', async () => {
const yoga = loadYoga();
const yoga = await loadYoga();

const root = {
type: 'DOCUMENT',
Expand Down Expand Up @@ -187,7 +187,7 @@ describe('pagination step', () => {
});

test('should break on a container whose children can not fit on a page', async () => {
const yoga = loadYoga();
const yoga = await loadYoga();

const root = {
type: 'DOCUMENT',
Expand Down

0 comments on commit b1e2d6c

Please sign in to comment.