Skip to content

Commit

Permalink
use node:worker_threads implementation of MessageChannel
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Dec 13, 2024
1 parent 926a001 commit a3f8658
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
15 changes: 1 addition & 14 deletions src/react/ssr/__tests__/getDataFromTree.test.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import "./messageChannel-polyfill";
import React from "react";

if (React.version.startsWith("19")) {
// react-dom/server uses MessageChannel in React 19
window.MessageChannel = jest.fn().mockImplementation(() => {
return {
port1: {
set onmessage(_cb: unknown) {},
},
port2: {
postMessage(_data: unknown) {},
},
};
});
}

import gql from "graphql-tag";
import { DocumentNode } from "graphql";

Expand Down
17 changes: 17 additions & 0 deletions src/react/ssr/__tests__/messageChannel-polyfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { MessageChannel as MC } from "node:worker_threads";

const messageChannels: MC[] = [];

afterEach(() => {
let mc: MC;
while ((mc = messageChannels.pop())) {
mc.port1.close();
mc.port2.close();
}
});
//@ts-ignore
globalThis.MessageChannel = function MessageChannel() {
const mc = new MC();
messageChannels.push(mc);
return mc;
};

0 comments on commit a3f8658

Please sign in to comment.