silverwolf-x/project / packages /next /src /server /dev /serialized-errors.ts
silverwolf-x's picture
download
raw
1.62 kB
import {
HMR_MESSAGE_SENT_TO_BROWSER,
type HmrMessageSentToBrowser,
} from './hot-reloader-types'
import type { AnyStream } from '../app-render/stream-ops'
import { streamToUint8Array } from '../stream-utils/node-web-streams-helper'
const errorsRscStreamsByHtmlRequestId = new Map<string, AnyStream>()
export function sendSerializedErrorsToClient(
errorsRscStream: AnyStream,
sendToClient: (message: HmrMessageSentToBrowser) => void
) {
streamToUint8Array(errorsRscStream).then(
(serializedErrors) => {
sendToClient({
type: HMR_MESSAGE_SENT_TO_BROWSER.ERRORS_TO_SHOW_IN_BROWSER,
serializedErrors,
})
},
(err) => {
console.error(new Error('Failed to serialize errors.', { cause: err }))
}
)
}
export function sendSerializedErrorsToClientForHtmlRequest(
htmlRequestId: string,
sendToClient: (message: HmrMessageSentToBrowser) => void
) {
const errorsRscStream = errorsRscStreamsByHtmlRequestId.get(htmlRequestId)
if (!errorsRscStream) {
return
}
errorsRscStreamsByHtmlRequestId.delete(htmlRequestId)
sendSerializedErrorsToClient(errorsRscStream, sendToClient)
}
export function setErrorsRscStreamForHtmlRequest(
htmlRequestId: string,
errorsRscStream: AnyStream
) {
// TODO: Clean up after a timeout, in case the client never connects, e.g.
// when CURL'ing the page, or loading the page with JavaScript disabled etc.
errorsRscStreamsByHtmlRequestId.set(htmlRequestId, errorsRscStream)
}
export function deleteErrorsRscStreamForHtmlRequest(htmlRequestId: string) {
errorsRscStreamsByHtmlRequestId.delete(htmlRequestId)
}

Xet Storage Details

Size:
1.62 kB
·
Xet hash:
387d8218a8a3b0d13a2c49e8d9879aa73ac2549651d15553396591b45b1f68f9

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.