Skip to content

Conversation

@whitphx
Copy link
Contributor

@whitphx whitphx commented Nov 27, 2025

This PR excludes MessagePort objects from the transferable object list passed to structuredClone.
Because, if the MessagePort objects are in the transfer list, the onmessage event listener on the paired port won't be called.

Description

Follows #9078.
#9078 made MessagePort work with @vitest/web-worker but it was not complete where the ports are not working as expected when clone === "native".
This PR fixes it.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

…ject list passed to structuredClone

If the MessagePort objects are in the `transfer` list, the `onmessage` event listener on the paired port won't be called.
@netlify
Copy link

netlify bot commented Nov 27, 2025

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 17dfca2
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6928889858a410000888a0c3
😎 Deploy Preview https://deploy-preview-9118--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@whitphx whitphx changed the title fix(web-worker): Exclude MessagePort objects from the transferable object list passed to structuredClone fix(web-worker): MessagePort objects passed to Worker.postMessage work when clone === "native" Nov 27, 2025
@whitphx whitphx marked this pull request as ready for review November 27, 2025 17:28
'none',
] satisfies Array<NonNullable<Parameters<typeof defineWebWorkers>[0]>['clone']>
cloneTypes.forEach((clone) => {
suite(`defineWebWorkers with clone=${clone}`, () => {
Copy link
Member

Choose a reason for hiding this comment

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

Let's not mix describe and suite. describe was already imported, let's use it instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, done.

@sheremet-va sheremet-va merged commit deee83e into vitest-dev:main Nov 28, 2025
13 of 16 checks passed
@whitphx whitphx deleted the fix-web-worker-port-native-clone branch November 28, 2025 09:55
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