Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to node style listener to avoid using undici's (node dep) MessageEvent class #704

Merged
merged 2 commits into from
Aug 21, 2024

Conversation

appurva21
Copy link
Member

@appurva21 appurva21 commented Aug 20, 2024

Issue

In Node v22.3.0, Node's MessageEvent was replaced with undici's (nodejs/node#52370). MessageEvent is loaded lazily and requires globalThis and global during initialization. If a consumer of UVM mutates the global scope in bootCode before the MessageEvent gets loaded, it can lead to a less stable system.

Fix

Right now bridge.js relies on parentPort.addEventListener for node environment to keep the interface consistent with web workers. The addEventListener registers a listener that gets fired with MessageEvent's instance as an argument. This is now replaced with parentPort.on, which registers a node-style listener, i.e., listener gets called directly with data received, and usage of MessageEvent class is avoided.

worker.browser.js is also updated to expose on method for consistency.

@appurva21 appurva21 requested a review from codenirvana August 20, 2024 06:50
@appurva21 appurva21 changed the title Switch to node style listener to avoid using undici's (node dep) Message event class Switch to node style listener to avoid using undici's (node dep) MessageEvent class Aug 20, 2024
@appurva21 appurva21 force-pushed the feature/avoid-using-undici-message-event-class branch from c0241e3 to 74cc6ad Compare August 20, 2024 15:28
@appurva21 appurva21 marked this pull request as ready for review August 21, 2024 05:57
Copy link

codecov bot commented Aug 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (fd04626) to head (560e509).
Report is 3 commits behind head on develop.

Additional details and impacted files
@@            Coverage Diff            @@
##           develop      #704   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            5         5           
  Lines          124       124           
  Branches        15        15           
=========================================
  Hits           124       124           
Flag Coverage Δ
unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@appurva21 appurva21 merged commit 6494d76 into develop Aug 21, 2024
10 checks passed
@appurva21 appurva21 deleted the feature/avoid-using-undici-message-event-class branch August 21, 2024 08:38
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