Skip to content

Fix serialization of functions from import_js_module#6632

Merged
hoodmane merged 1 commit intomainfrom
hoodmane/fix-function-serialization
Apr 21, 2026
Merged

Fix serialization of functions from import_js_module#6632
hoodmane merged 1 commit intomainfrom
hoodmane/fix-function-serialization

Conversation

@hoodmane
Copy link
Copy Markdown
Contributor

This change was originally part of #6173 but it got reverted. This caused cloudflare/workers-sdk#12961

This change was originally part of #6173 but it got reverted. This caused
cloudflare/workers-sdk#12961
@hoodmane hoodmane requested review from a team as code owners April 21, 2026 22:42
@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented Apr 21, 2026

UnknownError: ProviderInitError

github run

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented Apr 21, 2026

@hoodmane Bonk workflow failed. Check the logs for details.

View workflow run · To retry, trigger Bonk again.

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented Apr 21, 2026

The change is a one-line fix. The old code at line 70 was:

if (!mod || typeof mod !== 'object') {

The new code is:

if (!mod || !['object', 'function'].includes(typeof mod)) {

This allows createImportProxy to also wrap function values in a Proxy, not just object values. This is consistent with line 96 inside the get trap which already uses the same ['object', 'function'].includes(typeof orig) pattern.

The logic is correct: Proxy targets in JavaScript can be either objects or functions. The old code was returning functions un-proxied, which means functions from import_js_module would fail serialization since they wouldn't get the importName/getAccessorList symbol handlers. This matches the linked issue about function serialization.

The fix is minimal, targeted, and consistent with the existing pattern on line 96. No backward compatibility concerns since this only affects the IS_CREATING_SNAPSHOT path. No security implications.

LGTM

github run

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 21, 2026

Merging this PR will improve performance by 38.42%

⚡ 1 improved benchmark
✅ 71 untouched benchmarks
⏩ 129 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
simpleStringBody[Response] 26.7 µs 19.3 µs +38.42%

Comparing hoodmane/fix-function-serialization (5eb82f3) with main (d9d8fa6)

Open in CodSpeed

Footnotes

  1. 129 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.56%. Comparing base (7a7288e) to head (5eb82f3).
⚠️ Report is 441 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6632      +/-   ##
==========================================
- Coverage   70.68%   66.56%   -4.12%     
==========================================
  Files         420      405      -15     
  Lines      113010   117533    +4523     
  Branches    18531    19382     +851     
==========================================
- Hits        79881    78240    -1641     
- Misses      22086    27721    +5635     
- Partials    11043    11572     +529     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hoodmane hoodmane merged commit e403bb8 into main Apr 21, 2026
25 of 26 checks passed
@hoodmane hoodmane deleted the hoodmane/fix-function-serialization branch April 21, 2026 23:27
@ryanking13
Copy link
Copy Markdown
Contributor

Ahh, thanks. This was part of my reverted PR (#6173), but I forgot to reland before changing workers-py... Thakns a lot

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.

4 participants