akanjs 3.3.0-rc.54 → 3.3.0-rc.56
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/client/csrLocation.ts +22 -2
- package/client/router.ts +11 -5
- package/package.json +1 -1
- package/server/htmlResultCache.ts +17 -11
- package/server/routeCacheTally.ts +1 -0
- package/server/routeElementComposer.tsx +4 -0
- package/server/rscRouteDocument.tsx +2 -2
- package/types/client/csrLocation.d.ts +4 -0
- package/types/server/routeCacheTally.d.ts +1 -1
- package/types/server/routeElementComposer.d.ts +1 -0
- package/ui/System/CSR.tsx +4 -2
package/client/csrLocation.ts
CHANGED
|
@@ -10,6 +10,8 @@ export class CsrLocation {
|
|
|
10
10
|
#view: URL | null = null;
|
|
11
11
|
#entry: { idx: number | undefined; href: string; from: string | undefined } | null = null;
|
|
12
12
|
#onBack: ((idx: number) => void) | null = null;
|
|
13
|
+
#backAsked: object | null = null;
|
|
14
|
+
#backSent: object | null = null;
|
|
13
15
|
|
|
14
16
|
/** Reads `href`, a path on the app's origin, as this document's location from now on; a view never moves. */
|
|
15
17
|
view(href: string) {
|
|
@@ -99,9 +101,27 @@ export class CsrLocation {
|
|
|
99
101
|
this.#onBack = listener;
|
|
100
102
|
}
|
|
101
103
|
|
|
104
|
+
/** Holds the entry on screen as left until `moving`, a shell's back, settles; `back()` holds it until the pop lands. */
|
|
105
|
+
leaving(moving: unknown) {
|
|
106
|
+
const entry = this.entry();
|
|
107
|
+
this.#backAsked = entry;
|
|
108
|
+
const release = () => {
|
|
109
|
+
if (this.#backAsked === entry) this.#backAsked = null;
|
|
110
|
+
};
|
|
111
|
+
void Promise.resolve(moving).then(release, release);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Whether a back has left the entry on screen and not landed yet. */
|
|
115
|
+
isLeaving() {
|
|
116
|
+
const entry = this.entry();
|
|
117
|
+
return entry === this.#backAsked || entry === this.#backSent;
|
|
118
|
+
}
|
|
119
|
+
|
|
102
120
|
back() {
|
|
103
|
-
const
|
|
104
|
-
if (idx !== undefined) this.#onBack?.(idx - 1);
|
|
121
|
+
const entry = this.entry();
|
|
122
|
+
if (entry.idx !== undefined) this.#onBack?.(entry.idx - 1);
|
|
123
|
+
|
|
124
|
+
if (entry.idx !== undefined && entry.idx > 0) this.#backSent = entry;
|
|
105
125
|
window.history.back();
|
|
106
126
|
}
|
|
107
127
|
|
package/client/router.ts
CHANGED
|
@@ -287,7 +287,7 @@ class Router {
|
|
|
287
287
|
prefetch: (href, priority) => options.router.prefetch?.(this.#getNavigationPathInfo(href).href, priority),
|
|
288
288
|
back: () => {
|
|
289
289
|
this.#postPathAfterBack();
|
|
290
|
-
options.router.back();
|
|
290
|
+
return options.router.back();
|
|
291
291
|
},
|
|
292
292
|
refresh: () => {
|
|
293
293
|
const router = options.router;
|
|
@@ -315,7 +315,7 @@ class Router {
|
|
|
315
315
|
},
|
|
316
316
|
back: (routeOptions) => {
|
|
317
317
|
this.#postPathAfterBack();
|
|
318
|
-
options.router.back(routeOptions);
|
|
318
|
+
return options.router.back(routeOptions);
|
|
319
319
|
},
|
|
320
320
|
refresh: () => {
|
|
321
321
|
const { path, pathname, hash } = this.#getPathInfo(csrLocation.pathname);
|
|
@@ -654,11 +654,17 @@ class Router {
|
|
|
654
654
|
backTo(href: string, routeOptions?: RouteOptions) {
|
|
655
655
|
if (getEnv().side === "server") throw new Error("backTo is only available in client side");
|
|
656
656
|
this.#checkInitialized();
|
|
657
|
+
|
|
658
|
+
if (csrLocation.isLeaving()) return undefined as never;
|
|
657
659
|
const { from } = csrLocation.entry();
|
|
660
|
+
const target = this.#getPathInfo(href);
|
|
661
|
+
|
|
662
|
+
const under =
|
|
663
|
+
from === undefined ? null : { ...this.#getVisiblePathInfo(from), ...(target.hash ? {} : { hash: "" }) };
|
|
658
664
|
const isUnder =
|
|
659
|
-
|
|
665
|
+
under !== null &&
|
|
660
666
|
this.canGoBack() &&
|
|
661
|
-
CsrRuntimeParams.sameRoute(
|
|
667
|
+
CsrRuntimeParams.sameRoute(Router.#routeHref(under), Router.#routeHref(target));
|
|
662
668
|
if (isUnder) this.back(routeOptions);
|
|
663
669
|
else this.replace(href, { scrollToTop: false, ...routeOptions });
|
|
664
670
|
return undefined as never;
|
|
@@ -668,7 +674,7 @@ class Router {
|
|
|
668
674
|
this.#checkInitialized();
|
|
669
675
|
this.#guarded("back", null, () => {
|
|
670
676
|
this.#navigations += 1;
|
|
671
|
-
this.#instance.back(routeOptions);
|
|
677
|
+
csrLocation.leaving(this.#instance.back(routeOptions));
|
|
672
678
|
});
|
|
673
679
|
return undefined as never;
|
|
674
680
|
}
|
package/package.json
CHANGED
|
@@ -26,7 +26,13 @@ const ROUTE_CACHE_SWEEP_INTERVAL_MS = 60_000;
|
|
|
26
26
|
|
|
27
27
|
const HTML_STORE_SKIP_MAX_ENTRIES = 1000;
|
|
28
28
|
|
|
29
|
-
const HELD_SKIP_REASONS = [
|
|
29
|
+
const HELD_SKIP_REASONS = [
|
|
30
|
+
"dynamic-request-api",
|
|
31
|
+
"render-not-found",
|
|
32
|
+
"render-redirect",
|
|
33
|
+
"late-redirect",
|
|
34
|
+
"body-too-large",
|
|
35
|
+
];
|
|
30
36
|
|
|
31
37
|
interface HtmlCacheStreamOptions {
|
|
32
38
|
shouldCache?: () => boolean | Promise<boolean>;
|
|
@@ -58,21 +64,21 @@ export function cacheHtmlWhileStreaming(
|
|
|
58
64
|
controller.enqueue(chunk);
|
|
59
65
|
},
|
|
60
66
|
async flush() {
|
|
61
|
-
if (exceededMaxBodyBytes) {
|
|
62
|
-
options.onSkip?.("body-too-large");
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const body = new Uint8Array(byteLength);
|
|
66
|
-
let offset = 0;
|
|
67
|
-
for (const chunk of chunks) {
|
|
68
|
-
body.set(chunk, offset);
|
|
69
|
-
offset += chunk.byteLength;
|
|
70
|
-
}
|
|
71
67
|
try {
|
|
72
68
|
if (options.shouldCache && !(await options.shouldCache())) {
|
|
73
69
|
options.onSkip?.("store-skip");
|
|
74
70
|
return;
|
|
75
71
|
}
|
|
72
|
+
if (exceededMaxBodyBytes) {
|
|
73
|
+
options.onSkip?.("body-too-large");
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const body = new Uint8Array(byteLength);
|
|
77
|
+
let offset = 0;
|
|
78
|
+
for (const chunk of chunks) {
|
|
79
|
+
body.set(chunk, offset);
|
|
80
|
+
offset += chunk.byteLength;
|
|
81
|
+
}
|
|
76
82
|
onComplete(body);
|
|
77
83
|
} catch {
|
|
78
84
|
}
|
|
@@ -178,7 +178,7 @@ export class RscRouteDocument {
|
|
|
178
178
|
pathRoute,
|
|
179
179
|
params: match.params,
|
|
180
180
|
searchParams,
|
|
181
|
-
navKey:
|
|
181
|
+
navKey: RouteElementComposer.navKeyOf(url),
|
|
182
182
|
notFound: { ...notFound, head: fallbackHead },
|
|
183
183
|
gate,
|
|
184
184
|
});
|
|
@@ -251,7 +251,7 @@ export class RscRouteDocument {
|
|
|
251
251
|
params: match.params,
|
|
252
252
|
searchParams,
|
|
253
253
|
patchStartIndex,
|
|
254
|
-
navKey:
|
|
254
|
+
navKey: RouteElementComposer.navKeyOf(url),
|
|
255
255
|
notFound,
|
|
256
256
|
});
|
|
257
257
|
}
|
|
@@ -39,6 +39,10 @@ export declare class CsrLocation {
|
|
|
39
39
|
static idxOf(state: unknown): number | undefined;
|
|
40
40
|
/** Hears each `back()` as it moves, with the index of the entry it lands on; one listener, the router's. */
|
|
41
41
|
onBack(listener: (idx: number) => void): void;
|
|
42
|
+
/** Holds the entry on screen as left until `moving`, a shell's back, settles; `back()` holds it until the pop lands. */
|
|
43
|
+
leaving(moving: unknown): void;
|
|
44
|
+
/** Whether a back has left the entry on screen and not landed yet. */
|
|
45
|
+
isLeaving(): boolean;
|
|
42
46
|
back(): void;
|
|
43
47
|
assign(href: string): void;
|
|
44
48
|
reload(): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AkanMetricFamily } from "akanjs/service";
|
|
2
2
|
declare const lookupReasons: readonly ["requested-query", "rewritten-query"];
|
|
3
|
-
declare const bypassReasons: readonly ["env-opt-out", "dev-default-off", "ttl-disabled", "path-excluded", "request-not-public", "dev-registry", "no-route", "script-hashes", "dynamic-request-api", "render-not-found", "render-redirect", "late-redirect", "other"];
|
|
3
|
+
declare const bypassReasons: readonly ["env-opt-out", "dev-default-off", "ttl-disabled", "path-excluded", "request-not-public", "dev-registry", "no-route", "script-hashes", "dynamic-request-api", "render-not-found", "render-redirect", "late-redirect", "body-too-large", "other"];
|
|
4
4
|
export type RouteCacheName = "rsc" | "html";
|
|
5
5
|
export type RouteCacheLookupReason = (typeof lookupReasons)[number];
|
|
6
6
|
export type RouteCacheBypassReason = (typeof bypassReasons)[number];
|
|
@@ -42,6 +42,7 @@ export declare class RouteElementComposer {
|
|
|
42
42
|
route: PathRoute | LayoutFallbackRoute;
|
|
43
43
|
basePath?: string | null;
|
|
44
44
|
}): Promise<import("akanjs/client").PageState>;
|
|
45
|
+
static navKeyOf(url: URL): string;
|
|
45
46
|
static compose({ pathRoute, params, searchParams, navKey, notFound, gate, }: {
|
|
46
47
|
pathRoute: SsrPathRoute;
|
|
47
48
|
params: Record<string, string>;
|
package/ui/System/CSR.tsx
CHANGED
|
@@ -333,7 +333,9 @@ const KeyboardLayer = ({
|
|
|
333
333
|
type FrameSlotTarget = "topInset" | "topLeftAction" | "bottomInset" | "keyboardInset";
|
|
334
334
|
|
|
335
335
|
const CSRFrameSlotTargets = ({ slot }: { slot: FrameSlotTarget }) => {
|
|
336
|
-
const { stackEntries, topInset, topLeftAction, bottomInset } = useCsr();
|
|
336
|
+
const { stackEntries, topInset, topLeftAction, bottomInset, location: shownLocation } = useCsr();
|
|
337
|
+
|
|
338
|
+
const isLayerClear = shownLocation?.pathRoute?.pageState?.navbarMotion === "page";
|
|
337
339
|
return (
|
|
338
340
|
<>
|
|
339
341
|
{stackEntries.map(({ key, location, pageType, zIndex }) => {
|
|
@@ -348,7 +350,7 @@ const CSRFrameSlotTargets = ({ slot }: { slot: FrameSlotTarget }) => {
|
|
|
348
350
|
const { topInset: topHeight, bottomInset: bottomHeight, navbarMotion, overlay } = location.pathRoute.pageState;
|
|
349
351
|
const collapsed = slot !== "keyboardInset" && (slot === "bottomInset" ? bottomHeight : topHeight) <= 0;
|
|
350
352
|
const hidden = pageType !== "current" || collapsed;
|
|
351
|
-
const ownBar = navbarMotion === "page" && (slot === "topInset" || slot === "topLeftAction");
|
|
353
|
+
const ownBar = (navbarMotion === "page" || isLayerClear) && (slot === "topInset" || slot === "topLeftAction");
|
|
352
354
|
return (
|
|
353
355
|
<animated.div
|
|
354
356
|
key={id}
|