react-dom-server requires messagechannel now i guess

This commit is contained in:
Jarred Sumner
2025-10-29 08:14:08 +01:00
parent fe1bc56637
commit a5f8b0e8dd
4 changed files with 64 additions and 33 deletions

View File

@@ -5,7 +5,7 @@
"main": "react-hello-world.node.js", "main": "react-hello-world.node.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"build:workerd": "bun build react-hello-world.workerd.jsx --outfile=react-hello-world.workerd.js --format=esm --production" "build:workerd": "bun build react-hello-world.workerd.jsx --outfile=react-hello-world.workerd.js --format=esm --production && (echo '// MessageChannel polyfill for workerd'; echo 'if (typeof MessageChannel === \"undefined\") {'; echo ' globalThis.MessageChannel = class MessageChannel {'; echo ' constructor() {'; echo ' this.port1 = { onmessage: null, postMessage: () => {} };'; echo ' this.port2 = {'; echo ' postMessage: (msg) => {'; echo ' if (this.port1.onmessage) {'; echo ' queueMicrotask(() => this.port1.onmessage({ data: msg }));'; echo ' }'; echo ' }'; echo ' };'; echo ' }'; echo ' };'; echo '}'; cat react-hello-world.workerd.js) > temp.js && mv temp.js react-hello-world.workerd.js"
}, },
"keywords": [], "keywords": [],
"author": "Colin McDonnell", "author": "Colin McDonnell",

View File

@@ -19,5 +19,5 @@ const mainWorker :Workerd.Worker = (
(name = "worker", esModule = embed "react-hello-world.workerd.js"), (name = "worker", esModule = embed "react-hello-world.workerd.js"),
], ],
compatibilityDate = "2025-01-01", compatibilityDate = "2025-01-01",
compatibilityFlags = ["nodejs_compat"], compatibilityFlags = ["nodejs_compat_v2"],
); );

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,22 @@
// Cloudflare Workers version with export default fetch // Cloudflare Workers version with export default fetch
// Run with: workerd serve react-hello-world.workerd.config.capnp // Run with: workerd serve react-hello-world.workerd.config.capnp
// Polyfill MessageChannel for workerd
if (typeof MessageChannel === 'undefined') {
globalThis.MessageChannel = class MessageChannel {
constructor() {
this.port1 = { onmessage: null, postMessage: () => {} };
this.port2 = {
postMessage: (msg) => {
if (this.port1.onmessage) {
queueMicrotask(() => this.port1.onmessage({ data: msg }));
}
}
};
}
};
}
import React from "react"; import React from "react";
import { renderToReadableStream } from "react-dom/server"; import { renderToReadableStream } from "react-dom/server";