Repository navigation
Conversation
Since HarfBuzz text shaping was added, `satori/standalone` fails on runtimes that only run WebAssembly modules uploaded with the code: - The Emscripten glue reads `self.location.href`, which Workers don't define, when `harfbuzzjs` is imported. - The bundled HarfBuzz bytes are compiled at runtime. - `hbjs` creates the blob destroy callback with `addFunction`, which compiles a small module at runtime. Start HarfBuzz on the first render instead of on import, let `init` take a precompiled `harfbuzz.wasm` module, and let HarfBuzz copy font data so blobs need no destroy callback. Fixes vercel#878
Contributor
|
@levish0 is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #878
satori/standalonehas been broken on Cloudflare Workers since HarfBuzz landed in 0.33. Workers don't defineself.locationand won't compile wasm from bytes at runtime. HarfBuzz ran into that in three places:self.location.hrefas soon asharfbuzzjsis importedhb.wasmgets compiled at runtimehbjsregisters its blob destroy callback withaddFunction, which compiles a tiny wasm module on the flyWhat this changes:
init({ layout, harfbuzz })takes a precompiled module and hands it to Emscripten throughinstantiateWasm.init(layout)works like before.satori/harfbuzz.wasmis exported. It's copied fromharfbuzzjs/hb.wasmat build time, so it's the same binary as the inlined one.self.location?.href, and blobs useHB_MEMORY_MODE_DUPLICATEso they don't need a destroy callbacktest/workers-build.mjsimports the standalone build with Workers-like globals and renders once. It fails if any of the three fixes is reverted.On Workers:
Tested with the repro from #878 under
wrangler dev. Onmainit fails withreading 'href'. On this branch it renders, with or withoutnodejs_compatand whether or notinitis awaited.pnpm testpasses, except the canvas tests, which I couldn't run locally (no nativeglbuild).