Skip to main content
GoodFirstPicks
DashboardIssuesReposLeaderboard

GoodFirstPicks by Leaveitblank © 2026

CreatorRequest a RepoPrivacy PolicyTerms of Service
Bug: MessageChannel in Scheduler prevents Jest test from exiting | GoodFirstPicks

Bug: MessageChannel in Scheduler prevents Jest test from exiting

facebook/react 22 comments 22d ago
View on GitHub
lowopenScope: clearSkill match: yesTest focusedReactJavaScriptTypeScript

Why this is a good first issue

The issue involves a clear Jest test failure due to an unclosed MessageChannel handle.

AI Summary

The issue describes a Jest test that fails to exit because the Scheduler's MessageChannel handle remains open. The proposed solution involves modifying the Scheduler code to unref the MessageChannel port, which should allow Jest to exit properly. The requirements are clear, and the fix appears to be straightforward.

Issue Description

React version: any Scheduler version: any up to current (0.23.0)

Steps To Reproduce

  1. Create Jest unit test.
  2. Select JSDom as test environment so that runtime will not have setImmediate function.
  3. JSDom still does not implement MessageChannel https://github.com/jsdom/jsdom/issues/2448. If MessageChannel is required to test some important functionality, one can add an implementation from Node.js as recommended in comment https://github.com/jsdom/jsdom/issues/2448#issuecomment-536242756
    window.MessageChannel = require('node:worker_threads').MessageChannel;
    
  4. Add Scheduler or React as a dependency and require it in the test or one of the files under test.
  5. Run test

Link to code example: https://github.com/victor-homyakov/scheduler-jest-jsdom-example

The current behavior

Test is endless. Jest won't stop. Console shows a message

Jest did not exit one second after the test run has completed.

'This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.

Running Jest with --detectOpenHandles outputs:

Jest has detected the following 1 open handle potentially keeping Jest from exiting:

  ●  MESSAGEPORT

    > 1 | require('scheduler');
        |                     ^

      at node_modules/scheduler/cjs/scheduler.development.js:569:17

The expected behavior

Code at https://github.com/facebook/react/blob/5426af3d50ff706f3ebeb4764f838e0a3812bf9a/packages/scheduler/src/forks/Scheduler.js#L621 should unref the handle:

  channel.port1.onmessage = performWorkUntilDeadline;
  // Allow the thread to exit if this is the only active handle in the event system
  if (channel.port1.unref) {
    channel.port1.unref();
  }

GitHub Labels

Status: Unconfirmed

Want to work on this?

Claim this issue to let others know you're working on it. You'll earn 10 points when you complete it!

Risk Flags

  • potential cross-environment impact
Loading labels...

Details

Points10 pts
Difficultylow
Scopeclear
Skill Matchyes
Test Focusedyes