Support JS environments without code generation #1772

Closed
opened 2024-12-17 15:42:57 -08:00 by benjavicente · 1 comment
benjavicente commented 2024-12-17 15:42:57 -08:00 (Migrated from github.com)

Report

Probably is related to https://github.com/facebook/yoga/issues/1507

Problem

The yoga-layout JavaScript library isn't compatible with environments that disallow code generation (eval), like Cloudflare's workerd (example related issue). Because of that, a library that patched how the wasm was loaded took off: yoga-wasm-web (used on satory). This split isn't great for libraries that use yoga and would like to target all modern JS environments, especially since yoga-wasm-web is stuck in yoga 2-beta.

Proposed solution

Support multiple ways to load wasm, like with a new entry point similar to yoga-wasm-web. But, since some libraries were built without the consideration that this option could be added, it might be better to provide a mechanism to globally configure how wasm is loaded before the initialization of libraries that use yoga:

import { setWASMLoader } from 'yoga-layout/load';

setWASMLoader((...) => WebAssembly.instantiate(...))

import { ... } from "@react-pdf/renderer" // or any other lib
# Report - [X] I have searched [existing issues](https://github.com/facebook/yoga/issues) and this is not a duplicate Probably is related to https://github.com/facebook/yoga/issues/1507 # Problem The `yoga-layout` JavaScript library isn't compatible with environments that disallow code generation (eval), like Cloudflare's workerd ([example related issue](https://github.com/cloudflare/next-on-pages/issues/704)). Because of that, a library that patched how the wasm was loaded took off: [yoga-wasm-web](https://www.npmjs.com/package/yoga-wasm-web) (used on [satory](https://github.com/vercel/satori)). This split isn't great for libraries that use yoga and would like to target all modern JS environments, especially since yoga-wasm-web [is stuck in yoga 2-beta](https://github.com/shuding/yoga-wasm-web/commits/main/). # Proposed solution Support multiple ways to load wasm, like with a new entry point similar to [yoga-wasm-web](https://github.com/shuding/yoga-wasm-web/blob/main/index.js). But, since some libraries were built without the consideration that this option could be added, it might be better to provide a mechanism to globally configure how wasm is loaded before the initialization of libraries that use yoga: ```ts import { setWASMLoader } from 'yoga-layout/load'; setWASMLoader((...) => WebAssembly.instantiate(...)) import { ... } from "@react-pdf/renderer" // or any other lib ```
NickGerleman commented 2024-12-24 05:08:48 -08:00 (Migrated from github.com)

I think this is mostly a dupe of #1767

I think this is mostly a dupe of #1767
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DaddyFrosty/yoga#1772
No description provided.