This commit is contained in:
Alistair Smith
2025-09-22 18:10:57 -07:00
parent c07150d5b1
commit cc84e271ff
3 changed files with 6 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
import type { ReactNode, SetStateAction } from "react";
import { createFromReadableStream } from "react-server-dom-bun/client.browser";
import { store, useStore, type Store } from "./simple-store.ts";
import { store, useStore, type Store } from "./store.ts";
export type NonNullishReactNode = Exclude<ReactNode, null | undefined>;
export type RenderableRscPayload = Promise<NonNullishReactNode> | NonNullishReactNode;

View File

@@ -121,21 +121,21 @@ const continueScriptTag = "<script>__bun_f.push(";
const enum HtmlState {
/** HTML is flowing, it is not an okay time to inject RSC data. */
Flowing,
Flowing = 1,
/** It is safe to inject RSC data. */
Boundary,
}
const enum RscState {
/** No RSC data has been written yet */
Waiting,
Waiting = 1,
/** Some but not all RSC data has been written */
Paused,
/** All RSC data has been written */
Done,
}
class RscInjectionStream extends EventEmitter implements NodeJS.WritableStream {
class RscInjectionStream extends EventEmitter {
controller: ReadableStreamDirectController;
html: HtmlState = HtmlState.Flowing;
@@ -151,7 +151,7 @@ class RscInjectionStream extends EventEmitter implements NodeJS.WritableStream {
/** Resolved when all data is written */
finished: Promise<void>;
finalize: () => void;
reject: (err: any) => void;
reject: (err: unknown) => void;
constructor(rscPayload: Readable, controller: ReadableStreamDirectController) {
super();
@@ -159,7 +159,7 @@ class RscInjectionStream extends EventEmitter implements NodeJS.WritableStream {
const { resolve, promise, reject } = Promise.withResolvers<void>();
this.finished = promise;
this.finalize = x => (controller.close(), resolve(x));
this.finalize = () => (controller.close(), resolve());
this.reject = reject;
rscPayload.on("data", this.writeRscData.bind(this));