74
return activeDebugChannels.get(requestId);
75
}
76
77
-async function renderApp(
78
- res,
79
- returnValue,
80
- formState,
81
- noCache,
82
- promiseForDebugChannel
83
-) {
77
+async function renderApp(res, returnValue, formState, noCache, debugChannel) {
78
const {renderToPipeableStream} = await import(
79
'react-server-dom-webpack/server'
80
);
126
// For client-invoked server actions we refresh the tree and return a return value.
127
const payload = {root, returnValue, formState};
128
const {pipe} = renderToPipeableStream(payload, moduleMap, {
135
- debugChannel: await promiseForDebugChannel,
129
+ debugChannel,
130
filterStackFrame,
131
});
132
pipe(res);
379
if (process.env.NODE_ENV === 'development') {
380
// Open a websocket server for Debug information
381
const WebSocket = require('ws');
388
- const webSocketServer = new WebSocket.Server({noServer: true});
389
-
390
- httpServer.on('upgrade', (request, socket, head) => {
391
- const DEBUG_CHANNEL_PATH = '/debug-channel?';
392
- if (request.url.startsWith(DEBUG_CHANNEL_PATH)) {
393
- const requestId = request.url.slice(DEBUG_CHANNEL_PATH.length);
394
- const promiseForWs = new Promise(resolve => {
395
- webSocketServer.handleUpgrade(request, socket, head, ws => {
396
- ws.on('close', () => {
397
- activeDebugChannels.delete(requestId);
398
- });
399
- resolve(ws);
400
- });
401
- });
402
- activeDebugChannels.set(requestId, promiseForWs);
403
- } else {
404
- socket.destroy();
405
- }
382
+
383
+ const webSocketServer = new WebSocket.Server({
384
+ server: httpServer,
385
+ path: '/debug-channel',
386
+ });
387
+
388
+ webSocketServer.on('connection', (ws, req) => {
389
+ const url = new URL(req.url, `http://${req.headers.host}`);
390
+ const requestId = url.searchParams.get('id');
391
+
392
+ activeDebugChannels.set(requestId, ws);
393
+
394
+ ws.on('close', (code, reason) => {
395
+ activeDebugChannels.delete(requestId);
396
+ });
397
});
398
}