Skip to content

feat(wasm): patch non-streaming load paths & dedupe web worker patching - #23767

Open
d2anamaria wants to merge 2 commits into
developfrom
ana/feat/wasm-non-streaming
Open

feat(wasm): patch non-streaming load paths & dedupe web worker patching#23767
d2anamaria wants to merge 2 commits into
developfrom
ana/feat/wasm-non-streaming

Conversation

@d2anamaria

Copy link
Copy Markdown

Register wasm modules when apps load via fetch → arrayBuffer → WebAssembly.instantiate/compile, not only streaming APIs.

  • Patch Response.prototype.arrayBuffer and bytes so wasm buffers remember their fetch URL
  • Wrap WebAssembly.instantiate and compile to register modules after byte-based loads
  • Reuse patchWebAssembly(register) for workers so non-streaming registration works there too
  • Add tests for tagged-buffer registration and untagged-buffer negative case

Implementation

  • patchWasmResponse.ts tags wasm buffers in a WeakMap when read from a wasm-like Response; getWasmSourceUrl() resolves them at instantiate/compile time
  • patchWebAssembly() orchestrates response patching, non-streaming hooks, then streaming hooks (unchanged behavior)
  • Skip registration when instantiate receives an already-compiled WebAssembly.Module
  • Workers call patchWebAssembly((module, url) => registerModuleAndForward(...)) instead of duplicating streaming patches in index.ts

@d2anamaria
d2anamaria marked this pull request as draft August 31, 2026 12:44
@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 28.56 kB - -
@sentry/browser - with treeshaking flags 26.92 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 26.82 kB - -
@sentry/browser (incl. Tracing) 48.75 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 48.76 kB - -
@sentry/browser (incl. Tracing, Profiling) 51.68 kB - -
@sentry/browser (incl. Tracing, Replay) 88.23 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 77.63 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 92.93 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 105.85 kB - -
@sentry/browser (incl. Feedback) 46.05 kB - -
@sentry/browser (incl. sendFeedback) 33.62 kB - -
@sentry/browser (incl. FeedbackAsync) 38.73 kB - -
@sentry/browser (incl. Metrics) 29.51 kB - -
@sentry/browser (incl. Logs) 29.8 kB - -
@sentry/browser (incl. Metrics & Logs) 30.43 kB - -
@sentry/react 30.3 kB - -
@sentry/react (incl. Tracing) 50.94 kB - -
@sentry/vue 35.73 kB - -
@sentry/vue (incl. Tracing) 51.02 kB - -
@sentry/svelte 28.59 kB - -
CDN Bundle 30.35 kB - -
CDN Bundle (incl. Tracing) 49.38 kB - -
CDN Bundle (incl. Logs, Metrics) 32.58 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 51.25 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73.17 kB - -
CDN Bundle (incl. Tracing, Replay) 86.86 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 88.73 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 92.8 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 94.64 kB - -
CDN Bundle - uncompressed 89.95 kB - -
CDN Bundle (incl. Tracing) - uncompressed 147.2 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 96.24 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 152.89 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 225.41 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 266.69 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 272.37 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 280.4 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 286.06 kB - -
@sentry/nextjs (client) 53.56 kB - -
@sentry/sveltekit (client) 49.19 kB - -
@sentry/core/server 65.7 kB - -
@sentry/core/browser 51.86 kB - -
@sentry/node 123.77 kB +0.02% +17 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 85.53 kB - -
@sentry/node - without tracing 88.03 kB +0.02% +14 B 🔺
@sentry/node - without channel injection 103.18 kB +0.02% +19 B 🔺
@sentry/aws-serverless 96.42 kB +0.03% +26 B 🔺
@sentry/cloudflare (withSentry) - minified 201.04 kB - -
@sentry/cloudflare (withSentry) 500.26 kB - -

View base workflow run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 583b876. Configure here.

Comment thread packages/wasm/test/patchWebAssembly.test.ts
@andreiborza
andreiborza requested review from msonnb and removed request for msonnb August 31, 2026 13:45
@d2anamaria
d2anamaria marked this pull request as ready for review August 31, 2026 17:13
@d2anamaria
d2anamaria requested a review from andreiborza August 31, 2026 17:14
d2anamaria and others added 2 commits August 31, 2026 23:37
- Patch `Response.prototype.arrayBuffer` and `bytes` to tag wasm buffers with `response.url` in a `WeakMap`
- Hook `WebAssembly.instantiate` and `compile` to use tagged URL to register module
- Skip registration when `instantiate` receives an already-compiled `WebAssembly.Module`
- Split `patchWebAssembly` into response, non-streaming, and streaming setup; guard non-streaming with `nonStreamingPatched`

- Add `patchWebAssembly.test.ts` for fetch → arrayBuffer → instantiate/compile
- Extend `webworker.test.ts` to restore patched globals and assert `instantiate` is hooked
@andreiborza
andreiborza force-pushed the ana/feat/wasm-non-streaming branch from 3a55a63 to 99a2a60 Compare August 31, 2026 22:15
Comment thread packages/wasm/src/patchWebAssembly.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants