@taujs/react 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +9 -5
- package/dist/index.js +6 -4
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -56,31 +56,35 @@ type StreamOptions = {
|
|
|
56
56
|
/** Whether to use cork/uncork for batched writes (default: true) */
|
|
57
57
|
useCork?: boolean;
|
|
58
58
|
};
|
|
59
|
-
type HeadContext<T extends Record<string, unknown> = Record<string, unknown
|
|
59
|
+
type HeadContext<T extends Record<string, unknown> = Record<string, unknown>, R = unknown> = {
|
|
60
60
|
data: T;
|
|
61
61
|
meta: Record<string, unknown>;
|
|
62
|
+
routeContext?: R;
|
|
62
63
|
};
|
|
63
64
|
type SSRResult = {
|
|
64
65
|
headContent: string;
|
|
65
66
|
appHtml: string;
|
|
66
67
|
aborted: boolean;
|
|
67
68
|
};
|
|
68
|
-
type StreamCallOptions = StreamOptions & {
|
|
69
|
+
type StreamCallOptions<R> = StreamOptions & {
|
|
69
70
|
logger?: LoggerLike;
|
|
71
|
+
routeContext?: R;
|
|
70
72
|
};
|
|
71
|
-
declare function createRenderer<T extends Record<string, unknown
|
|
73
|
+
declare function createRenderer<T extends Record<string, unknown> = Record<string, unknown>, R = unknown>({ appComponent, headContent, streamOptions, logger, enableDebug, }: {
|
|
72
74
|
appComponent: (props: {
|
|
73
75
|
location: string;
|
|
76
|
+
routeContext?: R;
|
|
74
77
|
}) => React.ReactElement;
|
|
75
|
-
headContent: (ctx: HeadContext<T>) => string;
|
|
78
|
+
headContent: (ctx: HeadContext<T, R>) => string;
|
|
76
79
|
enableDebug?: boolean;
|
|
77
80
|
logger?: LoggerLike;
|
|
78
81
|
streamOptions?: StreamOptions;
|
|
79
82
|
}): {
|
|
80
83
|
renderSSR: (initialData: T, location: string, meta?: Record<string, unknown>, signal?: AbortSignal, opts?: {
|
|
81
84
|
logger?: LoggerLike;
|
|
85
|
+
routeContext?: R;
|
|
82
86
|
}) => Promise<SSRResult>;
|
|
83
|
-
renderStream: (writable: Writable, callbacks: RenderCallbacks<T> | undefined, initialData: T | Promise<T> | (() => Promise<T>), location: string, bootstrapModules?: string, meta?: Record<string, unknown>, cspNonce?: string, signal?: AbortSignal, opts?: StreamCallOptions) => {
|
|
87
|
+
renderStream: (writable: Writable, callbacks: RenderCallbacks<T> | undefined, initialData: T | Promise<T> | (() => Promise<T>), location: string, bootstrapModules?: string, meta?: Record<string, unknown>, cspNonce?: string, signal?: AbortSignal, opts?: StreamCallOptions<R>) => {
|
|
84
88
|
abort: () => void;
|
|
85
89
|
done: Promise<void>;
|
|
86
90
|
};
|
package/dist/index.js
CHANGED
|
@@ -378,11 +378,12 @@ function createRenderer({
|
|
|
378
378
|
let aborted = false;
|
|
379
379
|
const onAbort = () => aborted = true;
|
|
380
380
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
381
|
+
const routeContext = opts?.routeContext;
|
|
381
382
|
try {
|
|
382
383
|
log("Starting SSR:", location);
|
|
383
|
-
const dynamicHead = headContent({ data: initialData, meta });
|
|
384
|
+
const dynamicHead = headContent({ data: initialData, meta, routeContext });
|
|
384
385
|
const store = createSSRStore(initialData);
|
|
385
|
-
const html = renderToString(/* @__PURE__ */ jsx3(SSRStoreProvider, { store, children: appComponent({ location }) }));
|
|
386
|
+
const html = renderToString(/* @__PURE__ */ jsx3(SSRStoreProvider, { store, children: appComponent({ location, routeContext }) }));
|
|
386
387
|
if (aborted) {
|
|
387
388
|
warn("SSR completed after client abort", { location });
|
|
388
389
|
return { headContent: "", appHtml: "", aborted: true };
|
|
@@ -409,6 +410,7 @@ function createRenderer({
|
|
|
409
410
|
context: { scope: "react-streaming" },
|
|
410
411
|
enableDebug
|
|
411
412
|
});
|
|
413
|
+
const routeContext = opts?.routeContext;
|
|
412
414
|
const effectiveShellTimeout = opts?.shellTimeoutMs ?? shellTimeoutMs;
|
|
413
415
|
const effectiveUseCork = opts?.useCork ?? useCork;
|
|
414
416
|
const controller = createStreamController(writable, { log, warn, error });
|
|
@@ -447,7 +449,7 @@ function createRenderer({
|
|
|
447
449
|
log("Starting stream:", location);
|
|
448
450
|
try {
|
|
449
451
|
const store = createSSRStore(initialData);
|
|
450
|
-
const appElement = /* @__PURE__ */ jsx3(SSRStoreProvider, { store, children: appComponent({ location }) });
|
|
452
|
+
const appElement = /* @__PURE__ */ jsx3(SSRStoreProvider, { store, children: appComponent({ location, routeContext }) });
|
|
451
453
|
const stream = renderToPipeableStream(appElement, {
|
|
452
454
|
nonce: cspNonce,
|
|
453
455
|
bootstrapModules: bootstrapModules ? [bootstrapModules] : void 0,
|
|
@@ -468,7 +470,7 @@ function createRenderer({
|
|
|
468
470
|
});
|
|
469
471
|
}
|
|
470
472
|
}
|
|
471
|
-
const head = headContent({ data: headData ?? {}, meta });
|
|
473
|
+
const head = headContent({ data: headData ?? {}, meta, routeContext });
|
|
472
474
|
const canCork = effectiveUseCork && typeof writable.cork === "function" && typeof writable.uncork === "function";
|
|
473
475
|
if (canCork)
|
|
474
476
|
try {
|