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 4694d20
Show file tree
Hide file tree
Showing 2 changed files with 17 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
16 changes: 16 additions & 0 deletions src/react/ssr/__tests__/messageChannel-polyfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { MessageChannel as MC } from "node:worker_threads";

const messageChannels: MC[] = [];

afterEach(() => {
for (const mc of messageChannels) {
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 4694d20

Please sign in to comment.