Repository navigation
fix(wasm-sdk): strip the default wasm URL from the sanitized glue - #5389
Conversation
bundle.cjs derives dist/raw/wasm_sdk.no_url.js from the wasm-bindgen glue by
removing the default `new URL('wasm_sdk_bg.wasm', import.meta.url)` init path,
so bundlers that follow the single-file wrappers do not emit the ~26 MB .wasm
as an extra static asset. The regex had two problems and stopped matching:
it escaped the dots twice (`\\.` in a regex literal matches a literal backslash)
and only knew the old `typeof module_or_path === 'undefined'` guard, while
current wasm-bindgen emits `module_or_path === undefined`. The sanitized file
was byte-identical to the raw one (5.0.0-beta.3, beta.4, beta.5), and webpack
and Next.js emitted wasm_sdk_bg.wasm even though it is never fetched.
Match both guard forms, fail the build if the pattern is not found, and assert
that no default wasm URL remains in the output. The default branch now throws a
clear error instead of being emptied, since init() without a module could only
fail inside WebAssembly.instantiate(undefined) anyway.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to The sanitizer handles the default URL branch produced by the pinned wasm-bindgen version, so no actionable merge-blocking risk is established. Pre-merge checks |
|
|
✅ Final review complete — no blockers (commit 66356c5) · triage: low |
|
Waiting for bot review — coderabbitai ✓ · thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
The change correctly fixes the wasm-bindgen URL sanitization, fails fast when the expected initialization block is absent, and verifies that the sanitized glue contains no remaining default WASM URL. No in-scope correctness issues were found; the wasm-sdk test and lint checks were still pending in the supplied CI snapshot.
Review provenance
Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
lowbygpt-6.1-sol(effort low) — This is a small, self-contained build-script fix with straightforward regex validation and sanitized WASM glue behavior, and it does not affect consensus, funds, cryptography, or other critical surfaces. - Phase 1 reviewers:
glm-5.3-flash— general (completed, effort high); agentphase1-reviewer - Phase 1 model:
glm-5.3-flash— zai quota: 5h 99% left, weekly 98% left; passed overgemini-3.8-flash-high(antigravity below 15% reserve: weekly 14% left, 5h 100% left) - Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort medium); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort medium); agentphase2-reviewer,gpt-6.1-sol— ffi-engineer (completed, effort medium); agentphase2-reviewer
Out-of-scope follow-up suggestions (1)
These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.
- Identical broken sanitizer regex remains in packages/wasm-dpp2/scripts/bundle.cjs — The sibling wasm-dpp2 bundler still uses the pre-fix sanitizer at lines 38-40. Its regex incorrectly contains
\\.inside a regex literal, only handles the older guard form, and has no fail-fast or residual-reference assertion, so itswasm_dpp2.no_url.jsoutput can likewise remain identical to the raw glue.- Follow-up: Apply the equivalent sanitizer fix to packages/wasm-dpp2/scripts/bundle.cjs in a separate change.
|
Bots are done — your move: post |
|
/self-reviewed |
Issue being fixed or feature implemented
packages/wasm-sdk/scripts/bundle.cjsproducesdist/raw/wasm_sdk.no_url.jsby removing wasm-bindgen's defaultnew URL('wasm_sdk_bg.wasm', import.meta.url)init path. The regex no longer matches, sowasm_sdk.no_url.jsis byte-identical towasm_sdk.jsin the published@dashevo/wasm-sdk5.0.0-beta.3, beta.4 and beta.5 packages (checked withcmp).Bundlers that follow that
new URL(...)(webpack, Next.js) therefore emitwasm_sdk_bg.wasmas a static asset, even thoughsdk.js/sdk.compressed.jsalways pass the inlined module and the file is never fetched. The file is 26,385,737 B in beta.5 (26,225,711 B in beta.4), above Cloudflare Pages' 25 MiB (26,214,400 B) per-file limit, so Next.js static exports using the SDK fail to deploy.Why the regex stopped matching:
\\.inside a regex literal, which matches a literal backslash followed by any character, not a dot;typeof module_or_path === 'undefined'guard, while current wasm-bindgen emitsmodule_or_path === undefined.What was done?
In
packages/wasm-sdk/scripts/bundle.cjsonly:new URL('wasm_sdk_bg.wasm'remains in the output;wasm-sdk: init() requires the wasm module or bytes; the default wasm URL is not bundledinstead of being emptied.On throwing vs. an empty block: the wrappers never call the glue with an undefined module (Node uses
initSync({ module }), browsers pass{ module_or_path: mod }), so behaviour for them is unchanged. An empty block would leavemodule_or_pathundefined, and__wbg_initwould then fail with an opaque TypeError insideWebAssembly.instantiate(undefined). The explicit error fails the same call with a readable message../rawand./raw/*still point at the unmodifiedwasm_sdk.js, so users of the raw glue keep the default URL.How Has This Been Tested?
Ran the script against the wasm-bindgen output (
pkg/) taken from the published 5.0.0-beta.5 package (a full Rust/wasm build was not needed becausebundle.cjsonly consumespkg/):wasm_sdk.no_url.jsis identical towasm_sdk.js(bug reproduced).grep "new URL('wasm_sdk_bg.wasm'"onwasm_sdk.no_url.jsfinds nothing.import('dist/sdk.js')andimport('dist/sdk.compressed.js'), thenawait init()succeeds in both (273 exports); a secondinit()is a no-op.init()with no argument ondist/raw/wasm_sdk.no_url.jsthrows the new clear error.import init from './dist/sdk.js': with the master script's output it emits9f80...wasm(26,385,737 B) next tomain.js; with this change onlymain.jsis emitted.Breaking Changes
None. Only the sanitized internal glue changes; the public wrappers and the
./rawexports are unchanged.Checklist:
structure.rs, regeneratedgrovedb-structure.json, and checked the structure viewer link posted on this pull requestFor repository code-owners and collaborators only
🤖 Generated with Claude Code
Summary by CodeRabbit
PR Hygiene ·
66356c5/self-reviewedjs-wasm-sdk(packages/wasm-sdk/scripts/bundle.cjs) — shumkovWhen every merge requirement is met, the
PR Hygienecheck passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.