@taujs/react 0.1.4 → 0.1.6
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 +3 -5
- package/dist/index.js +8 -31
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ type HydrateAppOptions<T> = {
|
|
|
44
44
|
declare function hydrateApp<T>({ appComponent, rootElementId, enableDebug, logger, dataKey, onHydrationError, onStart, onSuccess, }: HydrateAppOptions<T>): void;
|
|
45
45
|
|
|
46
46
|
type RenderCallbacks<T> = {
|
|
47
|
-
onHead?: (head: string) =>
|
|
47
|
+
onHead?: (head: string) => void;
|
|
48
48
|
onShellReady?: () => void;
|
|
49
49
|
onAllReady?: (data: T) => void;
|
|
50
50
|
onFinish?: (data: T) => void;
|
|
@@ -53,8 +53,6 @@ type RenderCallbacks<T> = {
|
|
|
53
53
|
type StreamOptions = {
|
|
54
54
|
/** Timeout in ms for shell to be ready (default: 10000) */
|
|
55
55
|
shellTimeoutMs?: number;
|
|
56
|
-
/** Whether to use cork/uncork for batched writes (default: true) */
|
|
57
|
-
useCork?: boolean;
|
|
58
56
|
};
|
|
59
57
|
type HeadContext<T extends Record<string, unknown> = Record<string, unknown>, R = unknown> = {
|
|
60
58
|
data: T;
|
|
@@ -95,7 +93,7 @@ declare function createRenderer<T extends Record<string, unknown> = Record<strin
|
|
|
95
93
|
*
|
|
96
94
|
* Provides framework-agnostic primitives for accessing route data:
|
|
97
95
|
* - SSR hydration (window.__INITIAL_DATA__)
|
|
98
|
-
* - Client-side fetch (/__taujs/
|
|
96
|
+
* - Client-side fetch (/__taujs/route endpoint)
|
|
99
97
|
*
|
|
100
98
|
* This is a transport layer only. For data orchestration (caching, refetch, etc.),
|
|
101
99
|
* use TanStack Query or similar.
|
|
@@ -127,7 +125,7 @@ declare function readInitialDataOnce<T extends RouteData = RouteData>(): T | nul
|
|
|
127
125
|
/**
|
|
128
126
|
* Fetch route data from the τjs data endpoint.
|
|
129
127
|
*
|
|
130
|
-
* Calls: GET /__taujs/
|
|
128
|
+
* Calls: GET /__taujs/route?url=<pathname>
|
|
131
129
|
* Returns: { data: T }
|
|
132
130
|
*
|
|
133
131
|
* Throws RouteDataError on non-2xx responses with structured error info.
|
package/dist/index.js
CHANGED
|
@@ -364,7 +364,7 @@ function createRenderer({
|
|
|
364
364
|
logger,
|
|
365
365
|
enableDebug = false
|
|
366
366
|
}) {
|
|
367
|
-
const { shellTimeoutMs = 1e4
|
|
367
|
+
const { shellTimeoutMs = 1e4 } = streamOptions;
|
|
368
368
|
const renderSSR = async (initialData, location, meta = {}, signal, opts) => {
|
|
369
369
|
const { log, warn } = createUILogger(opts?.logger ?? logger, {
|
|
370
370
|
debugCategory: "ssr",
|
|
@@ -412,7 +412,6 @@ function createRenderer({
|
|
|
412
412
|
});
|
|
413
413
|
const routeContext = opts?.routeContext;
|
|
414
414
|
const effectiveShellTimeout = opts?.shellTimeoutMs ?? shellTimeoutMs;
|
|
415
|
-
const effectiveUseCork = opts?.useCork ?? useCork;
|
|
416
415
|
const controller = createStreamController(writable, { log, warn, error });
|
|
417
416
|
if (signal) {
|
|
418
417
|
const handleAbortSignal = () => controller.benignAbort(`AbortSignal triggered; aborting stream for location: ${location}`);
|
|
@@ -447,6 +446,7 @@ function createRenderer({
|
|
|
447
446
|
});
|
|
448
447
|
controller.setStopShellTimer(stopShellTimer);
|
|
449
448
|
log("Starting stream:", location);
|
|
449
|
+
let piped = false;
|
|
450
450
|
try {
|
|
451
451
|
const store = createSSRStore(initialData);
|
|
452
452
|
const appElement = /* @__PURE__ */ jsx3(SSRStoreProvider, { store, children: appComponent({ location, routeContext }) });
|
|
@@ -471,38 +471,15 @@ function createRenderer({
|
|
|
471
471
|
}
|
|
472
472
|
}
|
|
473
473
|
const head = headContent({ data: headData ?? {}, meta, routeContext });
|
|
474
|
-
const canCork = effectiveUseCork && typeof writable.cork === "function" && typeof writable.uncork === "function";
|
|
475
|
-
if (canCork)
|
|
476
|
-
try {
|
|
477
|
-
writable.cork();
|
|
478
|
-
} catch {
|
|
479
|
-
}
|
|
480
|
-
let wroteOk = true;
|
|
481
|
-
try {
|
|
482
|
-
const res = typeof writable.write === "function" ? writable.write(head) : true;
|
|
483
|
-
wroteOk = res !== false;
|
|
484
|
-
} finally {
|
|
485
|
-
if (canCork) {
|
|
486
|
-
try {
|
|
487
|
-
writable.uncork();
|
|
488
|
-
} catch {
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
let forceWait = false;
|
|
493
474
|
try {
|
|
494
|
-
|
|
475
|
+
cb.onHead(head);
|
|
495
476
|
} catch (cbErr) {
|
|
496
477
|
warn("onHead callback threw:", cbErr);
|
|
497
478
|
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
} else {
|
|
503
|
-
startPipe();
|
|
504
|
-
}
|
|
505
|
-
} else startPipe();
|
|
479
|
+
if (!piped) {
|
|
480
|
+
piped = true;
|
|
481
|
+
stream.pipe(writable);
|
|
482
|
+
}
|
|
506
483
|
try {
|
|
507
484
|
cb.onShellReady();
|
|
508
485
|
} catch (cbErr) {
|
|
@@ -601,7 +578,7 @@ async function fetchRouteData(pathname, init) {
|
|
|
601
578
|
if (!pathname) {
|
|
602
579
|
throw new Error("fetchRouteData: pathname is required");
|
|
603
580
|
}
|
|
604
|
-
const url = `/__taujs/
|
|
581
|
+
const url = `/__taujs/route?url=${encodeURIComponent(pathname)}`;
|
|
605
582
|
const res = await fetch(url, {
|
|
606
583
|
credentials: "include",
|
|
607
584
|
...init
|