Skip to content

fix(wasm-sdk): strip the default wasm URL from the sanitized glue - #5389

Merged
shumkov merged 1 commit into
dashpay:v5.0-devfrom
PastaPastaPasta:fix/wasm-sdk-sanitize-wasm-url
Oct 13, 2026
Merged

shumkov merged 1 commit into
dashpay:v5.0-devfrom
PastaPastaPasta:fix/wasm-sdk-sanitize-wasm-url

Conversation

@PastaPastaPasta

@PastaPastaPasta PastaPastaPasta commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

packages/wasm-sdk/scripts/bundle.cjs produces dist/raw/wasm_sdk.no_url.js by removing wasm-bindgen's default new URL('wasm_sdk_bg.wasm', import.meta.url) init path. The regex no longer matches, so wasm_sdk.no_url.js is byte-identical to wasm_sdk.js in the published @dashevo/wasm-sdk 5.0.0-beta.3, beta.4 and beta.5 packages (checked with cmp).

Bundlers that follow that new URL(...) (webpack, Next.js) therefore emit wasm_sdk_bg.wasm as a static asset, even though sdk.js / sdk.compressed.js always 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:

  • it used \\. inside a regex literal, which matches a literal backslash followed by any character, not a dot;
  • it only knew the old typeof module_or_path === 'undefined' guard, while current wasm-bindgen emits module_or_path === undefined.

What was done?

In packages/wasm-sdk/scripts/bundle.cjs only:

  • the regex accepts both guard forms, either quote style, optional semicolon and whitespace, and correctly escapes the dots;
  • the build throws if the pattern is not found, so the sanitized variant can no longer silently equal the raw one after a wasm-bindgen upgrade;
  • after replacement, the build asserts that no new URL('wasm_sdk_bg.wasm' remains in the output;
  • the removed default branch now throws wasm-sdk: init() requires the wasm module or bytes; the default wasm URL is not bundled instead 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 leave module_or_path undefined, and __wbg_init would then fail with an opaque TypeError inside WebAssembly.instantiate(undefined). The explicit error fails the same call with a readable message. ./raw and ./raw/* still point at the unmodified wasm_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 because bundle.cjs only consumes pkg/):

  • master script: wasm_sdk.no_url.js is identical to wasm_sdk.js (bug reproduced).
  • this change: files differ only in the replaced 3-line block, and grep "new URL('wasm_sdk_bg.wasm'" on wasm_sdk.no_url.js finds nothing.
  • Node: import('dist/sdk.js') and import('dist/sdk.compressed.js'), then await init() succeeds in both (273 exports); a second init() is a no-op.
  • init() with no argument on dist/raw/wasm_sdk.no_url.js throws the new clear error.
  • Negative test: glue without the default URL pattern makes the build fail with the new error.
  • webpack 5 production build of import init from './dist/sdk.js': with the master script's output it emits 9f80...wasm (26,385,737 B) next to main.js; with this change only main.js is emitted.

Breaking Changes

None. Only the sanitized internal glue changes; the public wrappers and the ./raw exports are unchanged.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed
  • If I added or changed GroveDB structure, I described it in the area's structure.rs, regenerated grovedb-structure.json, and checked the structure viewer link posted on this pull request

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • WASM initialization now reports an explicit error when no module or byte data is provided.
    • Builds now fail if the expected WASM URL handling cannot be updated or a WASM asset URL remains in the generated glue.

PR Hygiene · 66356c5

  • Bots — coderabbitai ✓ · thepastaclaw ✓
  • Self-review — post /self-reviewed
  • Reviewer requests paused — your 5 review slots are occupied; this PR is excluded from reviewers' queues. Required approvals still count without a slot.
  • Build green
  • Approvals
    • js-wasm-sdk (packages/wasm-sdk/scripts/bundle.cjs) — shumkov

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

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]>
@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: dashpay/platform/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 05836736-ffbe-4488-8e14-44d3adfded34

📥 Commits

Reviewing files that changed from the base of the PR and between 371a3b3 and 66356c5.


📒 Files selected for processing (1)
  • packages/wasm-sdk/scripts/bundle.cjs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.



📝 Walkthrough

Walkthrough

The bundle sanitizer now recognizes current and older wasm-bindgen default WASM URL branches. It replaces the branch with an explicit initialization error and fails when the branch is missing or the sanitized output still references the WASM asset URL.

Changes

WASM URL sanitization

Layer / File(s) Summary
Default URL branch handling
packages/wasm-sdk/scripts/bundle.cjs
The sanitizer matches both supported branch forms with flexible quoting and whitespace. It throws if the branch is absent, replaces the default URL assignment with an explicit error, and checks that no matching WASM URL reference remains.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix


Merge Risk: ⚪ Minimal · up to 66356

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 | Passed 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: removing the default WASM URL from the sanitized glue.
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@thepastaclaw

thepastaclaw commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit 66356c5) · triage: low

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai ✓ · thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Oct 12, 2026
@github-actions github-actions Bot added this to the v5.0.0 milestone Oct 12, 2026

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: low by gpt-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); agent phase1-reviewer
  • Phase 1 model: glm-5.3-flash — zai quota: 5h 99% left, weekly 98% left; passed over gemini-3.8-flash-high (antigravity below 15% reserve: weekly 14% left, 5h 100% left)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — ffi-engineer (completed, effort medium); agent phase2-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 its wasm_dpp2.no_url.js output 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.

@github-actions

Copy link
Copy Markdown
Contributor

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Oct 13, 2026
@PastaPastaPasta

Copy link
Copy Markdown
Member Author

/self-reviewed

@shumkov
shumkov merged commit 2938e49 into dashpay:v5.0-dev Oct 13, 2026
27 of 28 checks passed
@PastaPastaPasta
PastaPastaPasta deleted the fix/wasm-sdk-sanitize-wasm-url branch October 13, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-self-review Waiting for the author to post /self-reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants