Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cyan-comics-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"solid-js": patch
---

fix: prevent createDeferred from keeping Node.js process alive
6 changes: 6 additions & 0 deletions packages/solid/src/reactive/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ const maxSigned31BitInt = 1073741823;
function setupScheduler() {
const channel = new MessageChannel(),
port = channel.port2;
// In Node.js, active MessagePort listeners keep the event loop alive.
// Calling unref() allows the process to exit naturally when there is no
// other work keeping it alive (e.g. after dispose). unref is not available
// in browsers, so we guard the call.
if (typeof channel.port1.unref === "function") channel.port1.unref();
if (typeof port.unref === "function") port.unref();
scheduleCallback = () => port.postMessage(null);
channel.port1.onmessage = () => {
if (scheduledCallback !== null) {
Expand Down