akanjs 3.2.0-rc.28 → 3.2.0-rc.29
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/CHANGELOG.md
CHANGED
|
@@ -810,6 +810,14 @@
|
|
|
810
810
|
- **A refused head-safe patch runs each `.head()` once.** When a patch is refused after its head resolved, the full render reuses that head. Before, it ran every `.head()` a second time.
|
|
811
811
|
- **`@akanjs/devkit`: the SSR runtime manifest keeps every client export of the segment outlet module.** Before, it kept only one.
|
|
812
812
|
|
|
813
|
+
- 5cd3bc2: Some SSR navigations go to a page under a different layout, such as from an `(app)` group page to an `(auth)` group page. These no longer flash an empty area where the levels below that layout appear. Before, the navigation swapped the screen as soon as the response's first row arrived. A level mounted for the first time then showed its empty Suspense fallback, and React keeps a fallback on screen for at least 300ms, even when the level's content arrives a moment later.
|
|
814
|
+
|
|
815
|
+
Now such a navigation waits up to 150ms for the response to finish before it swaps the screen, and the previous page stays visible during the wait.
|
|
816
|
+
|
|
817
|
+
- If the response finishes in time, the new page appears complete.
|
|
818
|
+
- If it doesn't, the navigation commits at 150ms and the remaining levels fill in as they stream, as before.
|
|
819
|
+
- A navigation between pages under the same layouts doesn't wait, so a `.loading()` page there still shows its loading view right away. Under a different layout, that loading view can now appear up to 150ms later.
|
|
820
|
+
|
|
813
821
|
- 3537448: A navigation that a newer one overtakes before its page commits now cuts its `/__rsc` request once the response headers are in, so the server stops streaming it and the browser stops reading it. Before, it ran to the end and was only kept from committing. The cut waits for the headers because a session refresh may answer with a rotated single-use refresh token in `Set-Cookie`, and a request aborted before it lands leaves the browser holding the spent token. A refresh, a shallow push and a move back or forward overtake it the same way. A page that has already committed is never cut, so the Suspense content it still streams keeps arriving while the next navigation loads.
|
|
814
822
|
- a373d51: With partial RSC commit on (`AKAN_PUBLIC_RSC_PARTIAL_COMMIT=1`), a page reached by a patch is now replayed from the browser's cache on a revisit, even after a full navigation in between. Before, every full navigation dropped every cached patch, so a section change made every page of the section before it a network fetch again.
|
|
815
823
|
|
package/package.json
CHANGED
|
@@ -31,7 +31,10 @@ const isLineRowTag = (byte: number): boolean => (byte > 64 && byte < 91) || byte
|
|
|
31
31
|
|
|
32
32
|
const hexDigit = (byte: number): number => (byte > 96 ? byte - 87 : byte - 48);
|
|
33
33
|
|
|
34
|
-
export
|
|
34
|
+
export interface FlightLineRowHandler {
|
|
35
|
+
(row: Uint8Array, tag: string): Uint8Array | null;
|
|
36
|
+
end?: () => void;
|
|
37
|
+
}
|
|
35
38
|
|
|
36
39
|
interface FlightRowSink {
|
|
37
40
|
enqueue(row: Uint8Array, binary?: boolean): void;
|
|
@@ -201,11 +204,17 @@ export const mapFlightLineRows = (
|
|
|
201
204
|
reader.read(chunk, batch);
|
|
202
205
|
batch.flush();
|
|
203
206
|
},
|
|
204
|
-
flush: (controller) =>
|
|
207
|
+
flush: (controller) => {
|
|
208
|
+
reader.end(controller);
|
|
209
|
+
for (const onLineRow of onLineRows) onLineRow.end?.();
|
|
210
|
+
},
|
|
205
211
|
}),
|
|
206
212
|
);
|
|
207
213
|
};
|
|
208
214
|
|
|
215
|
+
export const flightRowsEndWatcher = (onEnd: () => void): FlightLineRowHandler =>
|
|
216
|
+
Object.assign((row: Uint8Array) => row, { end: onEnd });
|
|
217
|
+
|
|
209
218
|
export type FlightRowPass = (...onLineRows: FlightLineRowHandler[]) => ReadableStream<Uint8Array>;
|
|
210
219
|
|
|
211
220
|
export const flightRowPassOf =
|
package/server/rscClient.tsx
CHANGED
|
@@ -5,7 +5,12 @@ import { AkanError } from "../base/akanError";
|
|
|
5
5
|
import { csrLocation } from "../client/csrLocation";
|
|
6
6
|
import { DictionaryAsset } from "../client/dictionaryAsset";
|
|
7
7
|
import type {} from "../client/rscNavigation";
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
type FlightLineRowHandler,
|
|
10
|
+
type FlightRowPass,
|
|
11
|
+
flightRowPassOf,
|
|
12
|
+
flightRowsEndWatcher,
|
|
13
|
+
} from "./flightRowReader";
|
|
9
14
|
import {
|
|
10
15
|
AKAN_RSC_DICTIONARY_HEADER,
|
|
11
16
|
type AkanRouterStateV1,
|
|
@@ -37,8 +42,11 @@ import {
|
|
|
37
42
|
createAkanSegmentCacheTree,
|
|
38
43
|
createRscNavigationCacheNode,
|
|
39
44
|
deleteRscCacheEntryIfCurrent,
|
|
45
|
+
mountsNewRouteLevels,
|
|
46
|
+
NEW_ROUTE_LEVEL_WAIT_MS,
|
|
40
47
|
observeRscNavigationNode,
|
|
41
48
|
type RscNavigationCacheNode,
|
|
49
|
+
settledOrAfter,
|
|
42
50
|
} from "./rscNavigationState";
|
|
43
51
|
import { RscParkedRedirect } from "./rscParkedRedirect";
|
|
44
52
|
import { RscScrollRestoration } from "./rscScrollRestoration";
|
|
@@ -277,11 +285,18 @@ async function fetchRsc(
|
|
|
277
285
|
if (!applies && node && pendingRequest) parkedRedirect.park({ node, location, replace });
|
|
278
286
|
else navigateAfterRscRedirect(location, replace);
|
|
279
287
|
};
|
|
280
|
-
|
|
288
|
+
let endStream = () => {};
|
|
289
|
+
const streamed = new Promise<void>((resolve) => {
|
|
290
|
+
endStream = resolve;
|
|
291
|
+
});
|
|
292
|
+
const thenable = thenableOf(
|
|
293
|
+
flightRowPassOf(stream, rscRedirectRowGuard({ onRedirect: handleRedirect }), flightRowsEndWatcher(endStream)),
|
|
294
|
+
);
|
|
281
295
|
const node = createRscNavigationCacheNode({
|
|
282
296
|
href,
|
|
283
297
|
thenable,
|
|
284
298
|
routerState: responseResult.notFound ? null : readAkanRouterStateResponseHeader(res.headers),
|
|
299
|
+
streamed,
|
|
285
300
|
});
|
|
286
301
|
nodeRef.current = node;
|
|
287
302
|
await dictionaryReady;
|
|
@@ -597,6 +612,8 @@ function installNavigate(
|
|
|
597
612
|
});
|
|
598
613
|
|
|
599
614
|
await nextNode.thenable;
|
|
615
|
+
if (!notFound && mountsNewRouteLevels(currentRouterState, nextNode.routerState))
|
|
616
|
+
await settledOrAfter(nextNode.streamed, NEW_ROUTE_LEVEL_WAIT_MS);
|
|
600
617
|
|
|
601
618
|
const committed = commitLatestRscNavigation({
|
|
602
619
|
cache: notFound || replayed ? undefined : caches.pages,
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
type AkanRouterStateV1,
|
|
4
4
|
type AkanRouteSegmentState,
|
|
5
5
|
type AkanRscPatchMetadata,
|
|
6
|
+
countCommonRouteSegments,
|
|
6
7
|
createAkanSegmentOutletKey,
|
|
7
8
|
} from "./routeState";
|
|
8
9
|
|
|
@@ -18,6 +19,7 @@ export interface RscNavigationCacheNode<T> {
|
|
|
18
19
|
href: string;
|
|
19
20
|
thenable: T;
|
|
20
21
|
routerState: AkanRouterStateV1 | null;
|
|
22
|
+
streamed?: PromiseLike<void>;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
export interface RscPatchNavigationCacheNode<T> {
|
|
@@ -85,8 +87,29 @@ export function createRscNavigationCacheNode<T>({
|
|
|
85
87
|
href,
|
|
86
88
|
thenable,
|
|
87
89
|
routerState,
|
|
90
|
+
streamed,
|
|
88
91
|
}: RscNavigationCacheNode<T>): RscNavigationCacheNode<T> {
|
|
89
|
-
return { href, thenable, routerState };
|
|
92
|
+
return streamed ? { href, thenable, routerState, streamed } : { href, thenable, routerState };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export const NEW_ROUTE_LEVEL_WAIT_MS = 150;
|
|
96
|
+
|
|
97
|
+
export function mountsNewRouteLevels(current: AkanRouterStateV1 | null, next: AkanRouterStateV1 | null): boolean {
|
|
98
|
+
if (!next) return false;
|
|
99
|
+
const kept = current ? countCommonRouteSegments(current.segments, next.segments) : 0;
|
|
100
|
+
return kept < next.segments.length - 1;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function settledOrAfter(promise: PromiseLike<unknown> | undefined, ms: number): Promise<void> {
|
|
104
|
+
if (!promise) return Promise.resolve();
|
|
105
|
+
return new Promise((resolve) => {
|
|
106
|
+
const done = () => {
|
|
107
|
+
clearTimeout(timer);
|
|
108
|
+
resolve();
|
|
109
|
+
};
|
|
110
|
+
const timer = setTimeout(done, ms);
|
|
111
|
+
promise.then(done, done);
|
|
112
|
+
});
|
|
90
113
|
}
|
|
91
114
|
|
|
92
115
|
export function createRscPatchNavigationCacheNode<T>({
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export declare const FLIGHT_LENGTH_PREFIXED_TAGS = "TAOobUSsLlGgMmV";
|
|
2
|
-
export
|
|
2
|
+
export interface FlightLineRowHandler {
|
|
3
|
+
(row: Uint8Array, tag: string): Uint8Array | null;
|
|
4
|
+
end?: () => void;
|
|
5
|
+
}
|
|
3
6
|
export declare const mapFlightLineRows: (stream: ReadableStream<Uint8Array>, ...onLineRows: FlightLineRowHandler[]) => ReadableStream<Uint8Array>;
|
|
7
|
+
export declare const flightRowsEndWatcher: (onEnd: () => void) => FlightLineRowHandler;
|
|
4
8
|
export type FlightRowPass = (...onLineRows: FlightLineRowHandler[]) => ReadableStream<Uint8Array>;
|
|
5
9
|
export declare const flightRowPassOf: (stream: ReadableStream<Uint8Array>, ...firstOnLineRows: FlightLineRowHandler[]) => FlightRowPass;
|
|
@@ -10,6 +10,7 @@ export interface RscNavigationCacheNode<T> {
|
|
|
10
10
|
href: string;
|
|
11
11
|
thenable: T;
|
|
12
12
|
routerState: AkanRouterStateV1 | null;
|
|
13
|
+
streamed?: PromiseLike<void>;
|
|
13
14
|
}
|
|
14
15
|
export interface RscPatchNavigationCacheNode<T> {
|
|
15
16
|
href: string;
|
|
@@ -49,7 +50,10 @@ export type RscPatchNavigationCacheResult<T> = {
|
|
|
49
50
|
status: "rejected";
|
|
50
51
|
reason: AkanSegmentPatchFailureReason;
|
|
51
52
|
};
|
|
52
|
-
export declare function createRscNavigationCacheNode<T>({ href, thenable, routerState, }: RscNavigationCacheNode<T>): RscNavigationCacheNode<T>;
|
|
53
|
+
export declare function createRscNavigationCacheNode<T>({ href, thenable, routerState, streamed, }: RscNavigationCacheNode<T>): RscNavigationCacheNode<T>;
|
|
54
|
+
export declare const NEW_ROUTE_LEVEL_WAIT_MS = 150;
|
|
55
|
+
export declare function mountsNewRouteLevels(current: AkanRouterStateV1 | null, next: AkanRouterStateV1 | null): boolean;
|
|
56
|
+
export declare function settledOrAfter(promise: PromiseLike<unknown> | undefined, ms: number): Promise<void>;
|
|
53
57
|
export declare function createRscPatchNavigationCacheNode<T>({ href, patch, patchedNode, outletKey, headSnapshot, base, }: {
|
|
54
58
|
href: string;
|
|
55
59
|
patch: AkanRscPatchMetadata;
|