| Server IP : 159.203.156.69 / Your IP : 216.73.217.172 Web Server : nginx/1.24.0 System : Linux main-ubuntu 6.8.0-71-generic #71-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 22 16:52:38 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/tanviranik.com/node_modules/vinext/dist/server/ |
Upload File : |
//#region src/server/app-browser-stream.ts
function getVinextBrowserGlobal() {
return globalThis;
}
function createUnexpectedRscStreamCloseError() {
return /* @__PURE__ */ new Error("The connection to the page was unexpectedly closed, possibly due to the stop button being clicked, loss of Wi-Fi, or an unstable internet connection.");
}
/**
* Convert embedded text chunks back to a ReadableStream of Uint8Array chunks.
*/
function chunksToReadableStream(chunks) {
const encoder = new TextEncoder();
return new ReadableStream({ start(controller) {
for (const chunk of chunks) controller.enqueue(encoder.encode(chunk));
controller.close();
} });
}
/**
* Create a ReadableStream from progressively-embedded RSC chunks.
*
* The server pushes chunks into `__VINEXT_RSC_CHUNKS__` via inline <script>
* tags. We monkey-patch `push()` so new chunks stream to React immediately
* instead of polling with setTimeout.
*/
function createProgressiveRscStream() {
const encoder = new TextEncoder();
return new ReadableStream({ start(controller) {
const vinext = getVinextBrowserGlobal();
const initialChunks = vinext.__VINEXT_RSC_CHUNKS__ ?? [];
for (const chunk of initialChunks) controller.enqueue(encoder.encode(chunk));
if (vinext.__VINEXT_RSC_DONE__) {
controller.close();
return;
}
let closed = false;
let cancelDocumentCompletionCheck;
const cancelPendingDocumentCompletionCheck = () => {
const cancel = cancelDocumentCompletionCheck;
cancelDocumentCompletionCheck = void 0;
cancel?.();
};
const closeOnce = () => {
if (!closed) {
closed = true;
cancelPendingDocumentCompletionCheck();
controller.close();
}
};
const errorOnce = () => {
if (!closed) {
closed = true;
cancelPendingDocumentCompletionCheck();
controller.error(createUnexpectedRscStreamCloseError());
}
};
const arr = vinext.__VINEXT_RSC_CHUNKS__ ??= [];
arr.push = function(...chunks) {
const length = Array.prototype.push.apply(this, chunks);
if (closed) return length;
for (const chunk of chunks) controller.enqueue(encoder.encode(chunk));
if (vinext.__VINEXT_RSC_DONE__) closeOnce();
return length;
};
if (typeof document !== "undefined") if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", errorOnce);
cancelDocumentCompletionCheck = () => document.removeEventListener("DOMContentLoaded", errorOnce);
} else {
const timeoutId = setTimeout(errorOnce);
cancelDocumentCompletionCheck = () => clearTimeout(timeoutId);
}
} });
}
//#endregion
export { chunksToReadableStream, createProgressiveRscStream, getVinextBrowserGlobal };
//# sourceMappingURL=app-browser-stream.js.map