build: fix buffer import shims for stellar-sdk 16, release 0.5.29 - #45
Merged
Conversation
stellar-sdk 16 ESM emits two buffer import forms the post-build patches
did not handle, so the invite gate browser bundle failed to evaluate and
the app rendered nothing:
1. Bare side-effect imports (import "buffer";) in base/generated and
base/numbers. Browsers cannot resolve the bare specifier and the whole
module graph fails with: Failed to resolve module specifier "buffer".
Now stripped; Buffer is provided by the injected shim.
2. Named imports (import { Buffer as BufferN } from "buffer") at hoisted
positions that execute before the injected shim initializes, so binding
them to globalThis.__buffer_polyfill produced
"__buffer_polyfill is undefined". Now bound through the bundled npm
buffer package's CJS factory, which is defined near the top of the
bundle, idempotent, and whose name survives minification via its
un-renamable path-string key.
Verified: local-dev ./test.sh invite-gate green 6/6, and the login page
renders the connect wallet button with no console errors.
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.
Root cause
stellar-sdk 16's ESM build emits two buffer import forms that the post-build patches in
src/build.tsdid not handle, so the browser bundle failed to evaluate and the app rendered nothing (the Invite Gate failure on this repo):Bare side-effect imports (
import "buffer";) inlib/esm/base/generatedandlib/esm/base/numbers(23 sites). Browsers cannot resolve a bare specifier:TypeError: Failed to resolve module specifier "buffer"kills the whole module graph. Fix: stripped, same as the existing named-import handling; Buffer is provided globally by the injected shim.Named imports (
import { Buffer as BufferN } from "buffer") at hoisted bundle positions that execute before the injected shim's lazy init runs. Binding them toglobalThis.__buffer_polyfill(previous approach) throws__buffer_polyfill is undefined. Fix: bind through the bundled npm buffer package's CJS factory (require_buffer().Buffer), which is defined near the top of the bundle, idempotent, and detected via its path-string key so it survives production minification.Verification
local-dev ./test.sh invite-gate: 6/6 green (was 4/6 with both moonlight-pay tests failing)Notes
deno:latest). That PR also uploads Playwright artifacts so the next browser-side failure is a log read instead of a hunt.deno.lockuntouched; version bumped to 0.5.29 per release convention.