diff --git a/packages/vite/src/rsc/rscStudioHandlers.ts b/packages/vite/src/rsc/rscStudioHandlers.ts index d3156e249a55..0b0002e05427 100644 --- a/packages/vite/src/rsc/rscStudioHandlers.ts +++ b/packages/vite/src/rsc/rscStudioHandlers.ts @@ -52,64 +52,63 @@ const processRenderRscStream = async ( } const postFlightToStudio = (payload: string, metadata: Record) => { - if (shouldSendToStudio()) { - const base64Payload = Buffer.from(payload).toString('base64') - const encodedMetadata = Buffer.from(JSON.stringify(metadata)).toString( - 'base64', - ) - const jsonBody = JSON.stringify({ - flight: { - encodedPayload: base64Payload, - encoding: 'base64', - encodedMetadata, - }, - }) + if (!shouldSendToStudio()) { + return + } - // Options to configure the HTTP POST request - // TODO (RSC): Get these from the toml and Studio config - const options = { - hostname: 'localhost', - port: getStudioPort(), - path: '/.redwood/functions/rsc-flight', - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Content-Length': Buffer.byteLength(jsonBody), - }, - } + const base64Payload = Buffer.from(payload).toString('base64') + const encodedMetadata = Buffer.from(JSON.stringify(metadata)).toString( + 'base64', + ) + const jsonBody = JSON.stringify({ + flight: { + encodedPayload: base64Payload, + encoding: 'base64', + encodedMetadata, + }, + }) - const req = http.request(options, (res) => { - res.setEncoding('utf8') - }) + // Options to configure the HTTP POST request + // TODO (RSC): Get these from the toml and Studio config + const options = { + hostname: 'localhost', + port: getStudioPort(), + path: '/.redwood/functions/rsc-flight', + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Content-Length': Buffer.byteLength(jsonBody), + }, + } - req.on('error', (e: Error) => { - console.error( - `An error occurred sending the Flight Payload to Studio: ${e.message}`, - ) - }) + const req = http.request(options, (res) => { + res.setEncoding('utf8') + }) - req.write(jsonBody) - req.end() - } + req.on('error', (e: Error) => { + console.error('An error occurred sending the Flight Payload to Studio') + console.error(e) + }) + + req.write(jsonBody) + req.end() } const createStudioFlightHandler = ( readable: ReadableStream, metadata: Record, ) => { - if (shouldSendToStudio()) { - processRenderRscStream(readable) - .then((payload) => { - console.debug('Sending RSC Rendered stream to Studio') - postFlightToStudio(payload, metadata) - console.debug('Sent RSC Rendered stream to Studio', payload, metadata) - }) - .catch((error) => { - console.error('An error occurred getting RSC Rendered steam:', error) - }) - } else { - console.debug('Studio is not enabled') - } + processRenderRscStream(readable) + .then((payload) => { + console.debug('Sending RSC Rendered stream to Studio') + postFlightToStudio(payload, metadata) + console.debug('Sent RSC Rendered stream to Studio') + console.debug('payload to Studio:', payload) + console.debug('metadata to Studio:', metadata) + }) + .catch((error) => { + console.error('An error occurred getting RSC Rendered steam:', error) + }) } interface StudioRenderInput extends Omit { @@ -123,6 +122,7 @@ export const sendRscFlightToStudio = async (input: StudioRenderInput) => { console.debug('Studio is not enabled') return } + const { rscId, rsaId, args, basePath, req, handleError } = input try { diff --git a/packages/vite/src/runFeServer.ts b/packages/vite/src/runFeServer.ts index f4baabb1e8c2..509ed5954d0d 100644 --- a/packages/vite/src/runFeServer.ts +++ b/packages/vite/src/runFeServer.ts @@ -212,7 +212,8 @@ function createWebSocketServer() { // Event listener for incoming messages. The `data` is a Buffer ws.on('message', (data) => { const message = data.toString() - console.log('Received message:', message) + console.log('runFeServer.ts: Received message:') + console.log(message.slice(0, 120) + '...') // Broadcast the message to all connected clients wsServer.clients.forEach((client) => {