akanjs 3.3.0-rc.62 → 3.3.0-rc.64
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/csrTypes.ts +8 -2
- package/client/index.ts +2 -0
- package/client/pendingNavigation.ts +29 -2
- package/client/pressLoading.ts +29 -0
- package/client/route/RouteDefinition.ts +33 -7
- package/client/rscNavigation.ts +8 -1
- package/index.ts +19 -0
- package/package.json +1 -1
- package/server/routeElementComposer.tsx +15 -1
- package/server/routeState.ts +1 -1
- package/server/routeTreeBuilder.ts +30 -1
- package/server/rscClient.tsx +2 -2
- package/server/rscPatchPlanner.ts +35 -9
- package/server/rscPressLoading.tsx +40 -0
- package/server/rscSegmentOutlet.tsx +2 -0
- package/server/rscSegmentOutletReference.ts +2 -1
- package/server/rscWorkerCache.ts +1 -1
- package/types/client/csrTypes.d.ts +8 -2
- package/types/client/index.d.ts +1 -1
- package/types/client/pendingNavigation.d.ts +13 -1
- package/types/client/pressLoading.d.ts +4 -0
- package/types/client/route/RouteDefinition.d.ts +12 -1
- package/types/client/rscNavigation.d.ts +2 -0
- package/types/index.d.ts +17 -0
- package/types/server/routeElementComposer.d.ts +3 -1
- package/types/server/rscPatchPlanner.d.ts +1 -1
- package/types/server/rscPressLoading.d.ts +5 -0
- package/types/server/rscSegmentOutlet.d.ts +1 -1
- package/types/server/rscSegmentOutletReference.d.ts +2 -1
- package/types/server/rscWorkerCache.d.ts +1 -1
- package/types/ui/recipe/badgeRecipe.d.ts +2 -2
- package/types/ui/recipe/buttonRecipe.d.ts +2 -2
- package/types/ui/recipe/inputRecipe.d.ts +2 -2
- package/types/webkit/csrSlide.d.ts +1 -1
- package/types/webkit/useCsrRefs.d.ts +1 -1
- package/types/webkit/useFrameRuntime.d.ts +1 -0
- package/types/webkit/useResolvedFrame.d.ts +1 -0
package/client/csrTypes.ts
CHANGED
|
@@ -58,8 +58,10 @@ export interface PageConfig {
|
|
|
58
58
|
ssr?: SsrRenderMode;
|
|
59
59
|
/**
|
|
60
60
|
* Opt-in suffix-only RSC commits under `AKAN_PUBLIC_RSC_PARTIAL_COMMIT=1`: the page's `.head()` is plain `title`,
|
|
61
|
-
* `meta` and `link` tags, and the layouts above it
|
|
62
|
-
*
|
|
61
|
+
* `meta` and `link` tags, and the layouts above it draw on the server only from the args they declare. A move to a
|
|
62
|
+
* sibling page, or to another param or query of this page that no layout above declares with `.param()` or
|
|
63
|
+
* `.search()`, then renders the page alone and keeps those layouts as drawn; what follows the path in them is read
|
|
64
|
+
* on the client (`usePathCtx()`, `Link`'s `activeClassName`).
|
|
63
65
|
*/
|
|
64
66
|
rscPatchHeadSafe?: boolean;
|
|
65
67
|
/** `false` answers a `Link` prefetch of the page (on a layout, of every page under it) without rendering it, for a
|
|
@@ -180,6 +182,8 @@ export interface RouteRender {
|
|
|
180
182
|
getRouteDefinition?: () => PromiseOrObject<RouteDefinition | undefined>;
|
|
181
183
|
/** The query names the level reads; `undefined` for a legacy module, which receives every one. */
|
|
182
184
|
getSearchNames?: () => PromiseOrObject<string[] | undefined>;
|
|
185
|
+
/** The params the level reads beyond `lang`; `undefined` for a legacy module, which receives every one. */
|
|
186
|
+
getParamNames?: () => PromiseOrObject<string[] | undefined>;
|
|
183
187
|
}
|
|
184
188
|
export interface RouteViewport {
|
|
185
189
|
/** `viewport-fit=cover`: the page runs under the notch and home indicator, and `env(safe-area-inset-*)` measures them. */
|
|
@@ -428,6 +432,8 @@ export const pageActivityContext = sharedContext<PageActivityState>("pageActivit
|
|
|
428
432
|
export interface PathRoute {
|
|
429
433
|
path: string;
|
|
430
434
|
pathSegments: string[];
|
|
435
|
+
/** The pages matched ahead of this one that take some of its paths, as `/:lang/chat/new` does of `/:lang/chat/:id`. */
|
|
436
|
+
shadowedBy?: string[];
|
|
431
437
|
renderPage: RouteRender;
|
|
432
438
|
pageState: PageState;
|
|
433
439
|
pageConfigChain?: PageConfig[];
|
package/client/index.ts
CHANGED
|
@@ -189,6 +189,7 @@ export {
|
|
|
189
189
|
RouteGuards,
|
|
190
190
|
RouteHead,
|
|
191
191
|
type RouteKind,
|
|
192
|
+
type RouteLoadingOption,
|
|
192
193
|
type RouteModuleSource,
|
|
193
194
|
type RoutePromptArgument,
|
|
194
195
|
type RoutePromptMeta,
|
|
@@ -197,6 +198,7 @@ export {
|
|
|
197
198
|
rootLayout,
|
|
198
199
|
routeArgsMarker,
|
|
199
200
|
routeDefinitionMarker,
|
|
201
|
+
routeLoadingAtPressMarker,
|
|
200
202
|
} from "./route";
|
|
201
203
|
export {
|
|
202
204
|
AkanNotFoundError,
|
|
@@ -4,7 +4,12 @@ import { useSyncExternalStore } from "react";
|
|
|
4
4
|
export interface PendingNavigationEntry {
|
|
5
5
|
href: string;
|
|
6
6
|
|
|
7
|
+
from: string | null;
|
|
8
|
+
|
|
9
|
+
traversal: boolean;
|
|
10
|
+
|
|
7
11
|
waits: boolean;
|
|
12
|
+
left?: { promise: Promise<void>; resolve: () => void };
|
|
8
13
|
}
|
|
9
14
|
|
|
10
15
|
interface PendingNavigationStore {
|
|
@@ -25,12 +30,17 @@ export class PendingNavigation {
|
|
|
25
30
|
|
|
26
31
|
static #set(entry: PendingNavigationEntry | null) {
|
|
27
32
|
const store = PendingNavigation.#store();
|
|
33
|
+
const previous = store.entry;
|
|
28
34
|
store.entry = entry;
|
|
35
|
+
if (previous !== entry) previous?.left?.resolve();
|
|
29
36
|
for (const listener of [...store.listeners]) listener();
|
|
30
37
|
}
|
|
31
38
|
|
|
32
|
-
static begin(
|
|
33
|
-
|
|
39
|
+
static begin(
|
|
40
|
+
href: string,
|
|
41
|
+
{ from = null, traversal = false }: { from?: string | null; traversal?: boolean } = {},
|
|
42
|
+
): PendingNavigationEntry {
|
|
43
|
+
const entry: PendingNavigationEntry = { href, from, traversal, waits: false };
|
|
34
44
|
PendingNavigation.#set(entry);
|
|
35
45
|
return entry;
|
|
36
46
|
}
|
|
@@ -58,6 +68,23 @@ export class PendingNavigation {
|
|
|
58
68
|
return PendingNavigation.#store().entry?.href ?? null;
|
|
59
69
|
}
|
|
60
70
|
|
|
71
|
+
static entry(): PendingNavigationEntry | null {
|
|
72
|
+
return PendingNavigation.#store().entry;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Settles once `entry` is no longer the navigation in flight: it was drawn, it failed, or another began. */
|
|
76
|
+
static left(entry: PendingNavigationEntry): Promise<void> {
|
|
77
|
+
if (!entry.left) {
|
|
78
|
+
let resolve = () => {};
|
|
79
|
+
const promise = new Promise<void>((done) => {
|
|
80
|
+
resolve = done;
|
|
81
|
+
});
|
|
82
|
+
entry.left = { promise, resolve };
|
|
83
|
+
if (PendingNavigation.#store().entry !== entry) resolve();
|
|
84
|
+
}
|
|
85
|
+
return entry.left.promise;
|
|
86
|
+
}
|
|
87
|
+
|
|
61
88
|
static subscribe(listener: () => void) {
|
|
62
89
|
const { listeners } = PendingNavigation.#store();
|
|
63
90
|
listeners.add(listener);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const partsOf = (path: string) => path.split("/").filter(Boolean);
|
|
2
|
+
|
|
3
|
+
export class PressLoading {
|
|
4
|
+
|
|
5
|
+
static readonly defaultDelayMs = 150;
|
|
6
|
+
|
|
7
|
+
static staysOnPage(pattern: string, shadowedBy: string[], from: string, to: string): boolean {
|
|
8
|
+
const fromParts = partsOf(new URL(from).pathname);
|
|
9
|
+
const toParts = partsOf(new URL(to).pathname);
|
|
10
|
+
if (fromParts.length !== toParts.length) return false;
|
|
11
|
+
const patternParts = partsOf(pattern);
|
|
12
|
+
const offset = patternParts.length - toParts.length;
|
|
13
|
+
let moved = false;
|
|
14
|
+
for (let index = 0; index < toParts.length; index++) {
|
|
15
|
+
if (fromParts[index] === toParts[index]) continue;
|
|
16
|
+
const part = patternParts[index + offset];
|
|
17
|
+
if (!part?.startsWith(":") || part === ":lang") return false;
|
|
18
|
+
moved = true;
|
|
19
|
+
}
|
|
20
|
+
if (!moved) return false;
|
|
21
|
+
return !shadowedBy.some((shadow) => {
|
|
22
|
+
const shadowParts = partsOf(shadow);
|
|
23
|
+
return toParts.every((value, index) => {
|
|
24
|
+
const part = shadowParts[index + offset];
|
|
25
|
+
return part === undefined || part.startsWith(":") || part === value;
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -11,6 +11,7 @@ import { deserialize } from "akanjs/constant";
|
|
|
11
11
|
import { RenderScope } from "akanjs/fetch";
|
|
12
12
|
import type { ReactNode } from "react";
|
|
13
13
|
import type { Head, LayoutModule, PageConfig, PageModule, RouteGuardProps } from "../csrTypes";
|
|
14
|
+
import { PressLoading } from "../pressLoading";
|
|
14
15
|
import { AkanNotFoundError, getRequestRoutePath } from "../router";
|
|
15
16
|
import { Translator } from "../translator";
|
|
16
17
|
import {
|
|
@@ -28,6 +29,16 @@ export type RouteKind = "page" | "layout" | "rootLayout";
|
|
|
28
29
|
export const routeDefinitionMarker = Symbol.for("akan.routeDefinition");
|
|
29
30
|
/** Interned like the marker: the declared args ride on the module's render function, read by the CSR render cache. */
|
|
30
31
|
export const routeArgsMarker = Symbol.for("akan.routeArgs");
|
|
32
|
+
/** Interned like the marker: the delay of `.loading(…, { atPress })` rides on the module's `Loading`. */
|
|
33
|
+
export const routeLoadingAtPressMarker = Symbol.for("akan.routeLoadingAtPress");
|
|
34
|
+
|
|
35
|
+
export interface RouteLoadingOption {
|
|
36
|
+
/**
|
|
37
|
+
* Shows the fallback once a press to another path of this page (`/chat/a` to `/chat/b`) waits on the server, in
|
|
38
|
+
* place of the page being left. `true` waits 150 ms first. The fallback drawn is the one of the path being left.
|
|
39
|
+
*/
|
|
40
|
+
atPress?: boolean | { delayMs: number };
|
|
41
|
+
}
|
|
31
42
|
|
|
32
43
|
type HeadStage<Args> = Head | ((args: Args) => PromiseOrObject<Head | null | undefined>);
|
|
33
44
|
type GuardStage<Args> = (args: Args, request: RouteGuardRequest) => void | Promise<void>;
|
|
@@ -56,6 +67,7 @@ export abstract class RouteDefinition<
|
|
|
56
67
|
#head?: HeadStage<never>;
|
|
57
68
|
#guard?: GuardStage<never>;
|
|
58
69
|
#loading?: (args: never) => PromiseOrObject<ReactNode>;
|
|
70
|
+
#loadingAtPressMs?: number;
|
|
59
71
|
#render?: (args: never) => PromiseOrObject<ReactNode>;
|
|
60
72
|
#renderRoute?: {
|
|
61
73
|
render: (args: never) => PromiseOrObject<ReactNode>;
|
|
@@ -78,8 +90,19 @@ export abstract class RouteDefinition<
|
|
|
78
90
|
this.#guard = guard as GuardStage<never>;
|
|
79
91
|
return this;
|
|
80
92
|
}
|
|
81
|
-
loading(
|
|
93
|
+
loading(
|
|
94
|
+
render: (args: RouteBaseArgs & Args & Extra) => PromiseOrObject<ReactNode>,
|
|
95
|
+
{ atPress = false }: RouteLoadingOption = {},
|
|
96
|
+
) {
|
|
97
|
+
const delayMs = atPress === true ? PressLoading.defaultDelayMs : atPress ? atPress.delayMs : undefined;
|
|
98
|
+
if (delayMs !== undefined && this.kind !== "page")
|
|
99
|
+
throw new Error(
|
|
100
|
+
`[route-convention] ${this.kind}() takes no .loading(…, { atPress }); a press replaces the page under its layouts`,
|
|
101
|
+
);
|
|
102
|
+
if (delayMs !== undefined && !(Number.isFinite(delayMs) && delayMs >= 0))
|
|
103
|
+
throw new Error(`[route-convention] .loading(…, { atPress }) takes a delayMs of 0 or more, not ${delayMs}`);
|
|
82
104
|
this.#loading = render as (args: never) => PromiseOrObject<ReactNode>;
|
|
105
|
+
this.#loadingAtPressMs = delayMs;
|
|
83
106
|
return this;
|
|
84
107
|
}
|
|
85
108
|
render(render: (args: RouteBaseArgs & Args & Extra) => PromiseOrObject<ReactNode>) {
|
|
@@ -159,12 +182,7 @@ export abstract class RouteDefinition<
|
|
|
159
182
|
await RenderScope.run(() => head(this.#argsOf(props) as never)),
|
|
160
183
|
}
|
|
161
184
|
: { head }),
|
|
162
|
-
...(loading
|
|
163
|
-
? {
|
|
164
|
-
Loading: ((props: RouteRenderProps) =>
|
|
165
|
-
RenderScope.run(() => loading(this.#argsOf({ ...props, searchParams: {} }) as never))) as never,
|
|
166
|
-
}
|
|
167
|
-
: {}),
|
|
185
|
+
...(loading ? { Loading: this.#loadingRouteOf(loading) as never } : {}),
|
|
168
186
|
};
|
|
169
187
|
return this.extendModule(module);
|
|
170
188
|
}
|
|
@@ -178,6 +196,14 @@ export abstract class RouteDefinition<
|
|
|
178
196
|
return args;
|
|
179
197
|
}
|
|
180
198
|
|
|
199
|
+
#loadingRouteOf(loading: (args: never) => PromiseOrObject<ReactNode>) {
|
|
200
|
+
const route = (props: RouteRenderProps) =>
|
|
201
|
+
RenderScope.run(() => loading(this.#argsOf({ ...props, searchParams: {} }) as never));
|
|
202
|
+
if (this.#loadingAtPressMs !== undefined)
|
|
203
|
+
Object.defineProperty(route, routeLoadingAtPressMarker, { value: this.#loadingAtPressMs });
|
|
204
|
+
return route;
|
|
205
|
+
}
|
|
206
|
+
|
|
181
207
|
#guardRouteOf(guard: GuardStage<never>) {
|
|
182
208
|
const route = async (props: RouteGuardProps) =>
|
|
183
209
|
await RenderScope.run(() => {
|
package/client/rscNavigation.ts
CHANGED
|
@@ -9,7 +9,14 @@ declare global {
|
|
|
9
9
|
var __AKAN_RSC_NAVIGATE__:
|
|
10
10
|
| ((
|
|
11
11
|
href: string,
|
|
12
|
-
options?: {
|
|
12
|
+
options?: {
|
|
13
|
+
replace?: boolean;
|
|
14
|
+
scrollToTop?: boolean;
|
|
15
|
+
scrollY?: number;
|
|
16
|
+
shallow?: boolean;
|
|
17
|
+
/** Back or Forward: the history entry is already the target's. */
|
|
18
|
+
traversal?: boolean;
|
|
19
|
+
},
|
|
13
20
|
) => Promise<void>)
|
|
14
21
|
| undefined;
|
|
15
22
|
var __AKAN_DEV_SYNC_NAVIGATION__: ((href: string, kind: "push" | "replace" | "back" | "pop") => void) | undefined;
|
package/index.ts
CHANGED
|
@@ -465,6 +465,24 @@ export interface AkanPlugin {
|
|
|
465
465
|
syncAssets?: (ctx: AkanSyncContext) => Promise<void>;
|
|
466
466
|
}
|
|
467
467
|
|
|
468
|
+
export interface AkanPreviewSignIn {
|
|
469
|
+
/** The dev server the preview opens its pages on. */
|
|
470
|
+
origin: string;
|
|
471
|
+
/** What `akan preview --as <name>` named, for an app with more than one kind of account. */
|
|
472
|
+
as: string | null;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/** Read live by `akan preview`; it carries a function, so it stays out of the serializable config results. */
|
|
476
|
+
export interface AkanPreviewConfig {
|
|
477
|
+
/**
|
|
478
|
+
* Signs in the pages a preview opens: the sign-in answer, whose `Set-Cookie` pairs become their cookies, or the
|
|
479
|
+
* cookies by name. Credentials are read from the environment here, never written in this file.
|
|
480
|
+
*/
|
|
481
|
+
signIn?: (signIn: AkanPreviewSignIn) => Promise<Response | Record<string, string>>;
|
|
482
|
+
/** One concrete path per `[param]` route, without the locale, for `akan preview --changed` to open. */
|
|
483
|
+
examples?: string[];
|
|
484
|
+
}
|
|
485
|
+
|
|
468
486
|
export interface AkanApiConfig {
|
|
469
487
|
/** Where signal endpoints are mounted. Defaults to `/api`. */
|
|
470
488
|
prefix: string;
|
|
@@ -549,6 +567,7 @@ export type AppConfigInput = Omit<DeepPartial<AppConfigResult>, "docker" | "web"
|
|
|
549
567
|
native?: AkanNativeAppConfig;
|
|
550
568
|
plugins?: AkanPlugin[];
|
|
551
569
|
pipeline?: AppPipelineConfig;
|
|
570
|
+
preview?: AkanPreviewConfig;
|
|
552
571
|
};
|
|
553
572
|
export type LibConfigInput = Omit<DeepPartial<LibConfigResult>, "bin"> & {
|
|
554
573
|
bin?: AkanBinConfig;
|
package/package.json
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
Suspense,
|
|
21
21
|
} from "react";
|
|
22
22
|
import { getExplicitPageConfigKeys, mergePageConfigs, resolvePageState } from "../client/frameConfig";
|
|
23
|
+
import { routeLoadingAtPressMarker } from "../client/route/RouteDefinition";
|
|
23
24
|
import { RouteGuards } from "../client/route/RouteGuards";
|
|
24
25
|
import { RouteHead } from "../client/route/RouteHead";
|
|
25
26
|
import type { FallbackHead } from "./fallbackHead";
|
|
@@ -33,7 +34,7 @@ import {
|
|
|
33
34
|
isAkanRscPartialCommitEnabled,
|
|
34
35
|
} from "./routeState";
|
|
35
36
|
import { RscRenderLevels } from "./rscRenderLevels";
|
|
36
|
-
import { AkanSegmentOutletReference } from "./rscSegmentOutletReference";
|
|
37
|
+
import { AkanPressLoadingReference, AkanSegmentOutletReference } from "./rscSegmentOutletReference";
|
|
37
38
|
|
|
38
39
|
/** How a render reached after the layouts streamed answers `router.notFound()` — in place, since its parents are out. */
|
|
39
40
|
export interface RouteNotFoundInPlace {
|
|
@@ -140,6 +141,7 @@ export class RouteElementComposer {
|
|
|
140
141
|
renders: RouteElementComposer.#getRenderStack(pathRoute),
|
|
141
142
|
segments: isAkanRscPartialCommitEnabled() ? createAkanRouteSegments(pathRoute) : undefined,
|
|
142
143
|
levelBoundary: pathRoute.levelBoundary,
|
|
144
|
+
page: pathRoute,
|
|
143
145
|
params,
|
|
144
146
|
searchParams,
|
|
145
147
|
navKey,
|
|
@@ -262,6 +264,7 @@ export class RouteElementComposer {
|
|
|
262
264
|
renders: renders.slice(patchStartIndex),
|
|
263
265
|
owners: renders.slice(0, patchStartIndex),
|
|
264
266
|
levelBoundary: pathRoute.levelBoundary,
|
|
267
|
+
page: pathRoute,
|
|
265
268
|
params,
|
|
266
269
|
searchParams,
|
|
267
270
|
navKey,
|
|
@@ -370,6 +373,7 @@ export class RouteElementComposer {
|
|
|
370
373
|
owners = [],
|
|
371
374
|
segments,
|
|
372
375
|
levelBoundary,
|
|
376
|
+
page,
|
|
373
377
|
params,
|
|
374
378
|
searchParams,
|
|
375
379
|
navKey,
|
|
@@ -383,6 +387,8 @@ export class RouteElementComposer {
|
|
|
383
387
|
/** Around each level below its owner: the Flight server only references it and React's server renderer runs no
|
|
384
388
|
* error boundary, so a level failing before the first byte still takes its `.error()`. */
|
|
385
389
|
levelBoundary?: OwnedLevelBoundary;
|
|
390
|
+
/** The route whose page is the last of `renders`, named so `.loading(…, { atPress })` knows its other paths. */
|
|
391
|
+
page?: Pick<PathRoute, "path" | "shadowedBy">;
|
|
386
392
|
params: Record<string, string>;
|
|
387
393
|
searchParams: Record<string, string | string[]>;
|
|
388
394
|
navKey?: string;
|
|
@@ -399,6 +405,7 @@ export class RouteElementComposer {
|
|
|
399
405
|
const loadingFallback = RouteElementComposer.#composeLoadingFallback(renders.slice(i), params);
|
|
400
406
|
const suspenseKey =
|
|
401
407
|
navKey && loadingFallback != null && i === renders.length - 1 ? `akan-loading:${navKey}` : undefined;
|
|
408
|
+
const pressDelayMs = suspenseKey && page ? RouteElementComposer.#loadingAtPressMsOf(routeRender) : undefined;
|
|
402
409
|
const levelGate = levelGates[i];
|
|
403
410
|
|
|
404
411
|
const Boundary = i > ownerIndex ? levelBoundary?.Boundary : undefined;
|
|
@@ -417,6 +424,9 @@ export class RouteElementComposer {
|
|
|
417
424
|
element = (
|
|
418
425
|
<Suspense key={suspenseKey} fallback={loadingFallback}>
|
|
419
426
|
{Boundary ? <Boundary>{level}</Boundary> : level}
|
|
427
|
+
{page && pressDelayMs !== undefined ? (
|
|
428
|
+
<AkanPressLoadingReference pattern={page.path} shadowedBy={page.shadowedBy ?? []} delayMs={pressDelayMs} />
|
|
429
|
+
) : null}
|
|
420
430
|
{routeRender.Loading && levelGate ? <RouteShellGate.Wait until={levelGate.opened} /> : null}
|
|
421
431
|
</Suspense>
|
|
422
432
|
);
|
|
@@ -571,6 +581,10 @@ export class RouteElementComposer {
|
|
|
571
581
|
return gates;
|
|
572
582
|
}
|
|
573
583
|
|
|
584
|
+
static #loadingAtPressMsOf(routeRender: RouteRender): number | undefined {
|
|
585
|
+
return (routeRender.Loading as { [routeLoadingAtPressMarker]?: number } | undefined)?.[routeLoadingAtPressMarker];
|
|
586
|
+
}
|
|
587
|
+
|
|
574
588
|
static #composeLoadingFallback(renders: RouteRender[], params: Record<string, string>): ReactNode {
|
|
575
589
|
let element: ReactNode = null;
|
|
576
590
|
for (let i = renders.length - 1; i >= 0; i--) {
|
package/server/routeState.ts
CHANGED
|
@@ -77,7 +77,30 @@ export class RouteTreeBuilder {
|
|
|
77
77
|
|
|
78
78
|
const rootRoute = this.#routeMap.get("/");
|
|
79
79
|
if (!rootRoute) throw new AkanError("invalidRoute", "No root route");
|
|
80
|
-
return
|
|
80
|
+
return RouteTreeBuilder.#withShadows(
|
|
81
|
+
this.#getPathRoutes(rootRoute).sort((a, b) => compareRouteSpecificity(a.path, b.path)),
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static #withShadows(sorted: PathRoute[]): PathRoute[] {
|
|
86
|
+
const parts = sorted.map((pathRoute) => pathRoute.path.split("/").filter(Boolean));
|
|
87
|
+
const isParam = (part: string | undefined) => part?.startsWith(":") === true;
|
|
88
|
+
sorted.forEach((pathRoute, index) => {
|
|
89
|
+
const own = parts[index] ?? [];
|
|
90
|
+
if (!own.some((part) => isParam(part) && part !== ":lang")) return;
|
|
91
|
+
const shadowedBy = sorted
|
|
92
|
+
.slice(0, index)
|
|
93
|
+
.filter((_, ahead) => {
|
|
94
|
+
const other = parts[ahead] ?? [];
|
|
95
|
+
return (
|
|
96
|
+
other.length === own.length &&
|
|
97
|
+
other.every((part, at) => part === own[at] || isParam(part) || isParam(own[at]))
|
|
98
|
+
);
|
|
99
|
+
})
|
|
100
|
+
.map((ahead) => ahead.path);
|
|
101
|
+
if (shadowedBy.length) pathRoute.shadowedBy = shadowedBy;
|
|
102
|
+
});
|
|
103
|
+
return sorted;
|
|
81
104
|
}
|
|
82
105
|
|
|
83
106
|
getFallbackRoutes(): LayoutFallbackRoute[] {
|
|
@@ -312,6 +335,11 @@ export class RouteTreeBuilder {
|
|
|
312
335
|
if (definition) return definition.args.filter((arg) => arg.kind === "search").map((arg) => arg.name);
|
|
313
336
|
return parseRouteModuleKey(key).isInternalRootLayout ? [] : undefined;
|
|
314
337
|
},
|
|
338
|
+
getParamNames: async () => {
|
|
339
|
+
const { definition } = await loadModule();
|
|
340
|
+
if (definition) return definition.args.filter((arg) => arg.kind === "param").map((arg) => arg.name);
|
|
341
|
+
return parseRouteModuleKey(key).isInternalRootLayout ? [] : undefined;
|
|
342
|
+
},
|
|
315
343
|
};
|
|
316
344
|
if (kind === "page") {
|
|
317
345
|
routeRender.getPageConfig = pageConfigOf;
|
|
@@ -345,6 +373,7 @@ export class RouteTreeBuilder {
|
|
|
345
373
|
return createElement(mod.default as never, { children } as never);
|
|
346
374
|
}) as RouteRender["render"],
|
|
347
375
|
getSearchNames: () => [],
|
|
376
|
+
getParamNames: () => [],
|
|
348
377
|
};
|
|
349
378
|
}
|
|
350
379
|
|
package/server/rscClient.tsx
CHANGED
|
@@ -573,7 +573,7 @@ function installNavigate(
|
|
|
573
573
|
const navId = supersedeForPageNavigation();
|
|
574
574
|
const target = normalizeHref(href);
|
|
575
575
|
const signal = requestSignalOf(navId, target);
|
|
576
|
-
const pending = PendingNavigation.begin(target);
|
|
576
|
+
const pending = PendingNavigation.begin(target, { from: renderedHref, traversal: options.traversal });
|
|
577
577
|
|
|
578
578
|
let endsPending = true;
|
|
579
579
|
|
|
@@ -691,7 +691,7 @@ window.addEventListener("popstate", (event) => {
|
|
|
691
691
|
|
|
692
692
|
if (!keepsPage)
|
|
693
693
|
void globalThis
|
|
694
|
-
.__AKAN_RSC_NAVIGATE__?.(window.location.href, { replace: true, scrollToTop: false, scrollY })
|
|
694
|
+
.__AKAN_RSC_NAVIGATE__?.(window.location.href, { replace: true, scrollToTop: false, scrollY, traversal: true })
|
|
695
695
|
?.catch((error: unknown) => hardNavigateAfterRscFailure(window.location.href, true, error));
|
|
696
696
|
else {
|
|
697
697
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PageState, PathRoute } from "akanjs/client";
|
|
2
|
-
import type
|
|
1
|
+
import type { PageState, PathRoute, RouteRender } from "akanjs/client";
|
|
2
|
+
import { type Logger, parseSearchParams } from "akanjs/common";
|
|
3
3
|
import type { ReactNode } from "react";
|
|
4
4
|
import { RouteHead } from "../client/route/RouteHead";
|
|
5
5
|
import { akanHeadSnapshotKey, createAkanLocaleAlternateHeadSnapshot, mergeAkanHeadSnapshots } from "./head";
|
|
@@ -21,7 +21,8 @@ import { resolveAkanRscHeadSafePatchDecision } from "./rscWorkerCache";
|
|
|
21
21
|
type RouteHeadLayers = Awaited<ReturnType<typeof RouteElementComposer.resolveHeadLayers>>;
|
|
22
22
|
type RouteMatch = { pathRoute: PathRoute; params: Record<string, string> };
|
|
23
23
|
type SearchParams = Record<string, string | string[]>;
|
|
24
|
-
type
|
|
24
|
+
type RouteRead = { params: Record<string, string>; searchParams: SearchParams };
|
|
25
|
+
type FrameChange = "params-changed" | "search-changed" | "layouts-changed" | "page-state-changed" | "frame-unknown";
|
|
25
26
|
|
|
26
27
|
export interface RouteHeadSnapshots {
|
|
27
28
|
layouts: AkanHeadSnapshotV1;
|
|
@@ -135,7 +136,7 @@ export class RscPatchPlanner {
|
|
|
135
136
|
const routeHeadMounted = routeHeadKey !== undefined;
|
|
136
137
|
const frameChange =
|
|
137
138
|
pageConfig?.rscPatchHeadSafe === true && routeHeadMounted
|
|
138
|
-
? await this.#frameChangeOf(url, match, current, patchDecision.patch.patchStartIndex)
|
|
139
|
+
? await this.#frameChangeOf(url, match, searchParams, current, patchDecision.patch.patchStartIndex)
|
|
139
140
|
: undefined;
|
|
140
141
|
let admittedHead: ResolvedRouteHead | undefined;
|
|
141
142
|
if (pageConfig?.rscPatchHeadSafe === true && routeHeadMounted && !frameChange) {
|
|
@@ -183,20 +184,27 @@ export class RscPatchPlanner {
|
|
|
183
184
|
async #frameChangeOf(
|
|
184
185
|
url: URL,
|
|
185
186
|
match: RouteMatch,
|
|
187
|
+
searchParams: SearchParams,
|
|
186
188
|
current: AkanRouterStateV1 | null,
|
|
187
189
|
patchStartIndex: number,
|
|
188
190
|
): Promise<FrameChange | undefined> {
|
|
189
191
|
const currentUrl = current && URL.canParse(current.href) ? new URL(current.href) : null;
|
|
190
192
|
const currentMatch = currentUrl ? RouteTreeBuilder.match(currentUrl.pathname, this.#props.routes()) : null;
|
|
191
|
-
if (!currentMatch) return "frame-unknown";
|
|
192
|
-
const paramNames = new Set([...Object.keys(currentMatch.params), ...Object.keys(match.params)]);
|
|
193
|
-
if ([...paramNames].some((name) => currentMatch.params[name] !== match.params[name])) return "params-changed";
|
|
193
|
+
if (!currentUrl || !currentMatch) return "frame-unknown";
|
|
194
194
|
const keptLayouts = (route: PathRoute) =>
|
|
195
195
|
[...route.renderRootLayouts, ...route.renderLayouts].slice(0, patchStartIndex);
|
|
196
196
|
const [fromLayouts, toLayouts] = [keptLayouts(currentMatch.pathRoute), keptLayouts(match.pathRoute)];
|
|
197
|
-
|
|
198
|
-
|
|
197
|
+
const sameLayouts =
|
|
198
|
+
fromLayouts.length === toLayouts.length && fromLayouts.every((layout, index) => layout === toLayouts[index]);
|
|
199
|
+
if (currentMatch.params.lang !== match.params.lang) return "params-changed";
|
|
200
|
+
if (!sameLayouts) return "layouts-changed";
|
|
199
201
|
try {
|
|
202
|
+
const readChange = await RscPatchPlanner.#readChangeOf(
|
|
203
|
+
toLayouts,
|
|
204
|
+
{ params: currentMatch.params, searchParams: parseSearchParams(currentUrl.search) },
|
|
205
|
+
{ params: match.params, searchParams },
|
|
206
|
+
);
|
|
207
|
+
if (readChange) return readChange;
|
|
200
208
|
const basePath = this.#props.basePathOf(url);
|
|
201
209
|
const [from, to] = await Promise.all([
|
|
202
210
|
RouteElementComposer.resolveSsrFramePathRoute({ pathRoute: currentMatch.pathRoute, basePath }),
|
|
@@ -214,6 +222,24 @@ export class RscPatchPlanner {
|
|
|
214
222
|
}
|
|
215
223
|
}
|
|
216
224
|
|
|
225
|
+
static async #readChangeOf(
|
|
226
|
+
layouts: RouteRender[],
|
|
227
|
+
from: RouteRead,
|
|
228
|
+
to: RouteRead,
|
|
229
|
+
): Promise<"params-changed" | "search-changed" | undefined> {
|
|
230
|
+
const reads = await Promise.all(
|
|
231
|
+
layouts.map(async (layout) => ({
|
|
232
|
+
params: await layout.getParamNames?.(),
|
|
233
|
+
search: (await layout.getSearchNames?.()) ?? [],
|
|
234
|
+
})),
|
|
235
|
+
);
|
|
236
|
+
const everyParam = [...new Set([...Object.keys(from.params), ...Object.keys(to.params)])];
|
|
237
|
+
if (reads.some(({ params }) => (params ?? everyParam).some((name) => from.params[name] !== to.params[name])))
|
|
238
|
+
return "params-changed";
|
|
239
|
+
const moved = (name: string) => JSON.stringify(from.searchParams[name]) !== JSON.stringify(to.searchParams[name]);
|
|
240
|
+
return reads.some(({ search }) => search.some(moved)) ? "search-changed" : undefined;
|
|
241
|
+
}
|
|
242
|
+
|
|
217
243
|
static #keptFrameOf({ cache: _cache, ssr: _ssr, ...frame }: PageState) {
|
|
218
244
|
return frame;
|
|
219
245
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { use, useEffect, useState, useSyncExternalStore } from "react";
|
|
4
|
+
import { PendingNavigation, type PendingNavigationEntry } from "../client/pendingNavigation";
|
|
5
|
+
import { PressLoading } from "../client/pressLoading";
|
|
6
|
+
|
|
7
|
+
const none = () => null;
|
|
8
|
+
|
|
9
|
+
const pressOf = (born: PendingNavigationEntry | null) => {
|
|
10
|
+
const entry = PendingNavigation.entry();
|
|
11
|
+
|
|
12
|
+
return entry && entry !== born && entry.waits && !entry.traversal ? entry : null;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export function AkanPressLoading({
|
|
16
|
+
pattern,
|
|
17
|
+
shadowedBy,
|
|
18
|
+
delayMs,
|
|
19
|
+
}: {
|
|
20
|
+
pattern: string;
|
|
21
|
+
shadowedBy: string[];
|
|
22
|
+
delayMs: number;
|
|
23
|
+
}): null {
|
|
24
|
+
const [born] = useState(() => PendingNavigation.entry());
|
|
25
|
+
const press = useSyncExternalStore(PendingNavigation.subscribe, () => pressOf(born), none);
|
|
26
|
+
const [late, setLate] = useState(false);
|
|
27
|
+
|
|
28
|
+
const waiting =
|
|
29
|
+
!!press && (late || (!!press.from && PressLoading.staysOnPage(pattern, shadowedBy, press.from, press.href)));
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!waiting) {
|
|
32
|
+
setLate(false);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const timer = setTimeout(() => setLate(true), delayMs);
|
|
36
|
+
return () => clearTimeout(timer);
|
|
37
|
+
}, [waiting, delayMs]);
|
|
38
|
+
if (press && late) use(PendingNavigation.left(press));
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
@@ -6,6 +6,8 @@ import { readRscRoutePatch, subscribeRscRoutePatch, writeRscRoutePatch } from ".
|
|
|
6
6
|
import { useTransitionStore } from "../webkit/useTransitionStore";
|
|
7
7
|
import type { AkanHeadSnapshotV1 } from "./routeState";
|
|
8
8
|
|
|
9
|
+
export { AkanPressLoading } from "./rscPressLoading";
|
|
10
|
+
|
|
9
11
|
type RscSegmentThenable = PromiseLike<ReactNode>;
|
|
10
12
|
|
|
11
13
|
interface RscSegmentOutletStore {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AkanError } from "akanjs/base";
|
|
2
|
-
import type { AkanRouteHead, AkanSegmentOutlet } from "./rscSegmentOutlet";
|
|
2
|
+
import type { AkanPressLoading, AkanRouteHead, AkanSegmentOutlet } from "./rscSegmentOutlet";
|
|
3
3
|
|
|
4
4
|
const AKAN_SEGMENT_OUTLET_REFERENCE_ID = "pkgs/akanjs/server/rscSegmentOutlet.tsx";
|
|
5
5
|
|
|
@@ -24,3 +24,4 @@ function resolveAkanSegmentOutletReference<T>(exportName: string): T {
|
|
|
24
24
|
export const AkanSegmentOutletReference =
|
|
25
25
|
resolveAkanSegmentOutletReference<typeof AkanSegmentOutlet>("AkanSegmentOutlet");
|
|
26
26
|
export const AkanRouteHeadReference = resolveAkanSegmentOutletReference<typeof AkanRouteHead>("AkanRouteHead");
|
|
27
|
+
export const AkanPressLoadingReference = resolveAkanSegmentOutletReference<typeof AkanPressLoading>("AkanPressLoading");
|
package/server/rscWorkerCache.ts
CHANGED
|
@@ -281,7 +281,7 @@ export function resolveAkanRscHeadSafePatchDecision({
|
|
|
281
281
|
pageConfig?: PageConfig;
|
|
282
282
|
/** Whether the page the patch leaves from shows its head through `AkanRouteHead`, the only head a patch can swap. */
|
|
283
283
|
routeHeadMounted?: boolean;
|
|
284
|
-
frameChange?: "params-changed" | "layouts-changed" | "page-state-changed" | "frame-unknown";
|
|
284
|
+
frameChange?: "params-changed" | "search-changed" | "layouts-changed" | "page-state-changed" | "frame-unknown";
|
|
285
285
|
headSnapshot?: AkanHeadSnapshotV1;
|
|
286
286
|
/** Whether the target's layouts head differs from the one the page left from shows, which a patch would keep. */
|
|
287
287
|
layoutsHeadChanged?: boolean;
|
|
@@ -51,8 +51,10 @@ export interface PageConfig {
|
|
|
51
51
|
ssr?: SsrRenderMode;
|
|
52
52
|
/**
|
|
53
53
|
* Opt-in suffix-only RSC commits under `AKAN_PUBLIC_RSC_PARTIAL_COMMIT=1`: the page's `.head()` is plain `title`,
|
|
54
|
-
* `meta` and `link` tags, and the layouts above it
|
|
55
|
-
*
|
|
54
|
+
* `meta` and `link` tags, and the layouts above it draw on the server only from the args they declare. A move to a
|
|
55
|
+
* sibling page, or to another param or query of this page that no layout above declares with `.param()` or
|
|
56
|
+
* `.search()`, then renders the page alone and keeps those layouts as drawn; what follows the path in them is read
|
|
57
|
+
* on the client (`usePathCtx()`, `Link`'s `activeClassName`).
|
|
56
58
|
*/
|
|
57
59
|
rscPatchHeadSafe?: boolean;
|
|
58
60
|
/** `false` answers a `Link` prefetch of the page (on a layout, of every page under it) without rendering it, for a
|
|
@@ -187,6 +189,8 @@ export interface RouteRender {
|
|
|
187
189
|
getRouteDefinition?: () => PromiseOrObject<RouteDefinition | undefined>;
|
|
188
190
|
/** The query names the level reads; `undefined` for a legacy module, which receives every one. */
|
|
189
191
|
getSearchNames?: () => PromiseOrObject<string[] | undefined>;
|
|
192
|
+
/** The params the level reads beyond `lang`; `undefined` for a legacy module, which receives every one. */
|
|
193
|
+
getParamNames?: () => PromiseOrObject<string[] | undefined>;
|
|
190
194
|
}
|
|
191
195
|
export interface RouteViewport {
|
|
192
196
|
/** `viewport-fit=cover`: the page runs under the notch and home indicator, and `env(safe-area-inset-*)` measures them. */
|
|
@@ -415,6 +419,8 @@ export declare const pageActivityContext: import("react").Context<PageActivitySt
|
|
|
415
419
|
export interface PathRoute {
|
|
416
420
|
path: string;
|
|
417
421
|
pathSegments: string[];
|
|
422
|
+
/** The pages matched ahead of this one that take some of its paths, as `/:lang/chat/new` does of `/:lang/chat/:id`. */
|
|
423
|
+
shadowedBy?: string[];
|
|
418
424
|
renderPage: RouteRender;
|
|
419
425
|
pageState: PageState;
|
|
420
426
|
pageConfigChain?: PageConfig[];
|
package/types/client/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export { isMcpView } from "./mcpView.d.ts";
|
|
|
13
13
|
export { desktopPlatform, isNativeApp, isNativeShell, nativePlatform, openExternalUrl } from "./nativeHost.d.ts";
|
|
14
14
|
export { type NavigationAttempt, type NavigationGuard, type NavigationKind, NavigationRefused, } from "./navigationGuards.d.ts";
|
|
15
15
|
export { resolveServerUrl } from "./resolveServerUrl.d.ts";
|
|
16
|
-
export { assertGuardOnChain, isRouteDefinition, LayoutDefinition, type LayoutExtra, layout, PageDefinition, page, type ResolvedRouteModule, type ResolveRouteModuleOption, RootLayoutDefinition, RouteArgError, type RouteArgInfo, type RouteArgInput, type RouteArgOption, RouteArgPending, type RouteArgResolveOption, type RouteArgsShape, type RouteArgType, type RouteArgValue, type RouteBaseArgs, RouteDefinition, type RouteGuardRequest, RouteGuards, RouteHead, type RouteKind, type RouteModuleSource, type RoutePromptArgument, type RoutePromptMeta, type RouteSearchType, resolveRouteModule, rootLayout, routeArgsMarker, routeDefinitionMarker, } from "./route.d.ts";
|
|
16
|
+
export { assertGuardOnChain, isRouteDefinition, LayoutDefinition, type LayoutExtra, layout, PageDefinition, page, type ResolvedRouteModule, type ResolveRouteModuleOption, RootLayoutDefinition, RouteArgError, type RouteArgInfo, type RouteArgInput, type RouteArgOption, RouteArgPending, type RouteArgResolveOption, type RouteArgsShape, type RouteArgType, type RouteArgValue, type RouteBaseArgs, RouteDefinition, type RouteGuardRequest, RouteGuards, RouteHead, type RouteKind, type RouteLoadingOption, type RouteModuleSource, type RoutePromptArgument, type RoutePromptMeta, type RouteSearchType, resolveRouteModule, rootLayout, routeArgsMarker, routeDefinitionMarker, routeLoadingAtPressMarker, } from "./route.d.ts";
|
|
17
17
|
export { AkanNotFoundError, AkanRedirectError, type DeepLinkOptions, getPathInfo, isRouteControl, normalizeDeepLinkHref, type RedirectMethod, type RedirectOptions, type RedirectStatus, type RouteManifest, type RouteOptions, type RouterInstance, router, } from "./router.d.ts";
|
|
18
18
|
export { clearRscNavigationCache, isRscNavigationFromCache, navigateRsc, type PrefetchPriority, prefetchRsc, refreshRsc, } from "./rscNavigation.d.ts";
|
|
19
19
|
export { scriptHashes, scriptNonce } from "./scriptPolicy.d.ts";
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
export interface PendingNavigationEntry {
|
|
2
2
|
href: string;
|
|
3
|
+
from: string | null;
|
|
4
|
+
traversal: boolean;
|
|
3
5
|
waits: boolean;
|
|
6
|
+
left?: {
|
|
7
|
+
promise: Promise<void>;
|
|
8
|
+
resolve: () => void;
|
|
9
|
+
};
|
|
4
10
|
}
|
|
5
11
|
interface PendingNavigationStore {
|
|
6
12
|
entry: PendingNavigationEntry | null;
|
|
@@ -11,12 +17,18 @@ declare global {
|
|
|
11
17
|
}
|
|
12
18
|
export declare class PendingNavigation {
|
|
13
19
|
#private;
|
|
14
|
-
static begin(href: string
|
|
20
|
+
static begin(href: string, { from, traversal }?: {
|
|
21
|
+
from?: string | null;
|
|
22
|
+
traversal?: boolean;
|
|
23
|
+
}): PendingNavigationEntry;
|
|
15
24
|
static wait(entry: PendingNavigationEntry): void;
|
|
16
25
|
static end(entry: PendingNavigationEntry): void;
|
|
17
26
|
static clear(): void;
|
|
18
27
|
static get(): string | null;
|
|
19
28
|
static target(): string | null;
|
|
29
|
+
static entry(): PendingNavigationEntry | null;
|
|
30
|
+
/** Settles once `entry` is no longer the navigation in flight: it was drawn, it failed, or another began. */
|
|
31
|
+
static left(entry: PendingNavigationEntry): Promise<void>;
|
|
20
32
|
static subscribe(listener: () => void): () => void;
|
|
21
33
|
static use<Value extends string | boolean | null>(select: (href: string | null) => Value): Value;
|
|
22
34
|
}
|
|
@@ -8,6 +8,17 @@ export type RouteKind = "page" | "layout" | "rootLayout";
|
|
|
8
8
|
export declare const routeDefinitionMarker: unique symbol;
|
|
9
9
|
/** Interned like the marker: the declared args ride on the module's render function, read by the CSR render cache. */
|
|
10
10
|
export declare const routeArgsMarker: unique symbol;
|
|
11
|
+
/** Interned like the marker: the delay of `.loading(…, { atPress })` rides on the module's `Loading`. */
|
|
12
|
+
export declare const routeLoadingAtPressMarker: unique symbol;
|
|
13
|
+
export interface RouteLoadingOption {
|
|
14
|
+
/**
|
|
15
|
+
* Shows the fallback once a press to another path of this page (`/chat/a` to `/chat/b`) waits on the server, in
|
|
16
|
+
* place of the page being left. `true` waits 150 ms first. The fallback drawn is the one of the path being left.
|
|
17
|
+
*/
|
|
18
|
+
atPress?: boolean | {
|
|
19
|
+
delayMs: number;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
11
22
|
type HeadStage<Args> = Head | ((args: Args) => PromiseOrObject<Head | null | undefined>);
|
|
12
23
|
export interface RouteArgResolveOption {
|
|
13
24
|
/** A prompt's arguments are strings a person typed: a list is comma-separated and a bad value is refused. */
|
|
@@ -23,7 +34,7 @@ export declare abstract class RouteDefinition<Args extends RouteArgsShape = Reco
|
|
|
23
34
|
head(head: HeadStage<RouteBaseArgs & Args>): this;
|
|
24
35
|
/** Runs before any layout body; refuses with `router.redirect()` or `router.notFound()`. */
|
|
25
36
|
guard(guard: (args: RouteBaseArgs & Args, request: RouteGuardRequest) => void | Promise<void>): this;
|
|
26
|
-
loading(render: (args: RouteBaseArgs & Args & Extra) => PromiseOrObject<ReactNode
|
|
37
|
+
loading(render: (args: RouteBaseArgs & Args & Extra) => PromiseOrObject<ReactNode>, { atPress }?: RouteLoadingOption): this;
|
|
27
38
|
render(render: (args: RouteBaseArgs & Args & Extra) => PromiseOrObject<ReactNode>): this;
|
|
28
39
|
get pageConfig(): PageConfig | undefined;
|
|
29
40
|
protected declare(arg: RouteArgInfo): void;
|
|
@@ -12,6 +12,8 @@ declare global {
|
|
|
12
12
|
scrollToTop?: boolean;
|
|
13
13
|
scrollY?: number;
|
|
14
14
|
shallow?: boolean;
|
|
15
|
+
/** Back or Forward: the history entry is already the target's. */
|
|
16
|
+
traversal?: boolean;
|
|
15
17
|
}) => Promise<void>) | undefined;
|
|
16
18
|
var __AKAN_DEV_SYNC_NAVIGATION__: ((href: string, kind: "push" | "replace" | "back" | "pop") => void) | undefined;
|
|
17
19
|
var __AKAN_DEV_SYNC_NAVIGATION_APPLYING__: boolean | undefined;
|
package/types/index.d.ts
CHANGED
|
@@ -476,6 +476,22 @@ export interface AkanPlugin {
|
|
|
476
476
|
/** Build-time asset generation (e.g. `public/firebase-messaging-sw.js`). */
|
|
477
477
|
syncAssets?: (ctx: AkanSyncContext) => Promise<void>;
|
|
478
478
|
}
|
|
479
|
+
export interface AkanPreviewSignIn {
|
|
480
|
+
/** The dev server the preview opens its pages on. */
|
|
481
|
+
origin: string;
|
|
482
|
+
/** What `akan preview --as <name>` named, for an app with more than one kind of account. */
|
|
483
|
+
as: string | null;
|
|
484
|
+
}
|
|
485
|
+
/** Read live by `akan preview`; it carries a function, so it stays out of the serializable config results. */
|
|
486
|
+
export interface AkanPreviewConfig {
|
|
487
|
+
/**
|
|
488
|
+
* Signs in the pages a preview opens: the sign-in answer, whose `Set-Cookie` pairs become their cookies, or the
|
|
489
|
+
* cookies by name. Credentials are read from the environment here, never written in this file.
|
|
490
|
+
*/
|
|
491
|
+
signIn?: (signIn: AkanPreviewSignIn) => Promise<Response | Record<string, string>>;
|
|
492
|
+
/** One concrete path per `[param]` route, without the locale, for `akan preview --changed` to open. */
|
|
493
|
+
examples?: string[];
|
|
494
|
+
}
|
|
479
495
|
export interface AkanApiConfig {
|
|
480
496
|
/** Where signal endpoints are mounted. Defaults to `/api`. */
|
|
481
497
|
prefix: string;
|
|
@@ -552,6 +568,7 @@ export type AppConfigInput = Omit<DeepPartial<AppConfigResult>, "docker" | "web"
|
|
|
552
568
|
native?: AkanNativeAppConfig;
|
|
553
569
|
plugins?: AkanPlugin[];
|
|
554
570
|
pipeline?: AppPipelineConfig;
|
|
571
|
+
preview?: AkanPreviewConfig;
|
|
555
572
|
};
|
|
556
573
|
export type LibConfigInput = Omit<DeepPartial<LibConfigResult>, "bin"> & {
|
|
557
574
|
bin?: AkanBinConfig;
|
|
@@ -113,7 +113,7 @@ export declare class RouteElementComposer {
|
|
|
113
113
|
gate?: RouteShellGate;
|
|
114
114
|
head?: FallbackHead;
|
|
115
115
|
}): Promise<ReactNode | null>;
|
|
116
|
-
static composeRenders({ renders, owners, segments, levelBoundary, params, searchParams, navKey, notFound, gate, }: {
|
|
116
|
+
static composeRenders({ renders, owners, segments, levelBoundary, page, params, searchParams, navKey, notFound, gate, }: {
|
|
117
117
|
renders: RouteRender[];
|
|
118
118
|
/** Layouts above `renders` that this element leaves out (a patch) but whose `.notFound()` still applies. */
|
|
119
119
|
owners?: RouteRender[];
|
|
@@ -121,6 +121,8 @@ export declare class RouteElementComposer {
|
|
|
121
121
|
/** Around each level below its owner: the Flight server only references it and React's server renderer runs no
|
|
122
122
|
* error boundary, so a level failing before the first byte still takes its `.error()`. */
|
|
123
123
|
levelBoundary?: OwnedLevelBoundary;
|
|
124
|
+
/** The route whose page is the last of `renders`, named so `.loading(…, { atPress })` knows its other paths. */
|
|
125
|
+
page?: Pick<PathRoute, "path" | "shadowedBy">;
|
|
124
126
|
params: Record<string, string>;
|
|
125
127
|
searchParams: Record<string, string | string[]>;
|
|
126
128
|
navKey?: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PathRoute } from "akanjs/client";
|
|
2
|
-
import type
|
|
2
|
+
import { type Logger } from "akanjs/common";
|
|
3
3
|
import type { ReactNode } from "react";
|
|
4
4
|
import { RouteElementComposer } from "./routeElementComposer.d.ts";
|
|
5
5
|
import { type AkanHeadSnapshotV1, type AkanRouterStateV1, type AkanRscPatchDecision, readAkanRouterStateRequest } from "./routeState.d.ts";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
import type { AkanHeadSnapshotV1 } from "./routeState.d.ts";
|
|
3
|
+
export { AkanPressLoading } from "./rscPressLoading.d.ts";
|
|
3
4
|
type RscSegmentThenable = PromiseLike<ReactNode>;
|
|
4
5
|
interface RscSegmentOutletStore {
|
|
5
6
|
entries: Map<string, RscSegmentThenable>;
|
|
@@ -19,4 +20,3 @@ export declare function AkanRouteHead({ layouts, page }: {
|
|
|
19
20
|
layouts: AkanHeadSnapshotV1;
|
|
20
21
|
page: AkanHeadSnapshotV1;
|
|
21
22
|
}): ReactNode;
|
|
22
|
-
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type { AkanRouteHead, AkanSegmentOutlet } from "./rscSegmentOutlet.d.ts";
|
|
1
|
+
import type { AkanPressLoading, AkanRouteHead, AkanSegmentOutlet } from "./rscSegmentOutlet.d.ts";
|
|
2
2
|
export declare const AkanSegmentOutletReference: typeof AkanSegmentOutlet;
|
|
3
3
|
export declare const AkanRouteHeadReference: typeof AkanRouteHead;
|
|
4
|
+
export declare const AkanPressLoadingReference: typeof AkanPressLoading;
|
|
@@ -129,7 +129,7 @@ export declare function resolveAkanRscHeadSafePatchDecision({ partialCommitEnabl
|
|
|
129
129
|
pageConfig?: PageConfig;
|
|
130
130
|
/** Whether the page the patch leaves from shows its head through `AkanRouteHead`, the only head a patch can swap. */
|
|
131
131
|
routeHeadMounted?: boolean;
|
|
132
|
-
frameChange?: "params-changed" | "layouts-changed" | "page-state-changed" | "frame-unknown";
|
|
132
|
+
frameChange?: "params-changed" | "search-changed" | "layouts-changed" | "page-state-changed" | "frame-unknown";
|
|
133
133
|
headSnapshot?: AkanHeadSnapshotV1;
|
|
134
134
|
/** Whether the target's layouts head differs from the one the page left from shows, which a patch would keep. */
|
|
135
135
|
layoutsHeadChanged?: boolean;
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
export declare const badgeRecipe: (variants?: Omit<({
|
|
3
3
|
size?: "lg" | "md" | "sm" | "xs" | undefined;
|
|
4
4
|
outline?: boolean | undefined;
|
|
5
|
-
variant?: "
|
|
5
|
+
variant?: "error" | "default" | "info" | "warning" | "success" | "primary" | "outline" | "secondary" | "accent" | "neutral" | undefined;
|
|
6
6
|
} & {
|
|
7
7
|
class?: import("tailwind-variants/lite").ClassValue;
|
|
8
8
|
className?: never;
|
|
9
9
|
}) | ({
|
|
10
10
|
size?: "lg" | "md" | "sm" | "xs" | undefined;
|
|
11
11
|
outline?: boolean | undefined;
|
|
12
|
-
variant?: "
|
|
12
|
+
variant?: "error" | "default" | "info" | "warning" | "success" | "primary" | "outline" | "secondary" | "accent" | "neutral" | undefined;
|
|
13
13
|
} & {
|
|
14
14
|
class?: never;
|
|
15
15
|
className?: import("tailwind-variants/lite").ClassValue;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export declare const buttonRecipe: (variants?: Omit<({
|
|
3
3
|
size?: "xl" | "lg" | "md" | "sm" | "xs" | "icon" | undefined;
|
|
4
4
|
outline?: boolean | undefined;
|
|
5
|
-
variant?: "
|
|
5
|
+
variant?: "link" | "default" | "info" | "warning" | "success" | "destructive" | "primary" | "outline" | "secondary" | "accent" | "neutral" | "ghost" | undefined;
|
|
6
6
|
shape?: "default" | "circle" | "square" | undefined;
|
|
7
7
|
} & {
|
|
8
8
|
class?: import("tailwind-variants/lite").ClassValue;
|
|
@@ -10,7 +10,7 @@ export declare const buttonRecipe: (variants?: Omit<({
|
|
|
10
10
|
}) | ({
|
|
11
11
|
size?: "xl" | "lg" | "md" | "sm" | "xs" | "icon" | undefined;
|
|
12
12
|
outline?: boolean | undefined;
|
|
13
|
-
variant?: "
|
|
13
|
+
variant?: "link" | "default" | "info" | "warning" | "success" | "destructive" | "primary" | "outline" | "secondary" | "accent" | "neutral" | "ghost" | undefined;
|
|
14
14
|
shape?: "default" | "circle" | "square" | undefined;
|
|
15
15
|
} & {
|
|
16
16
|
class?: never;
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
export declare const inputRecipe: (variants?: Omit<({
|
|
3
3
|
kind?: "field" | "select" | "area" | undefined;
|
|
4
4
|
size?: "xl" | "lg" | "md" | "sm" | "xs" | undefined;
|
|
5
|
-
tone?: "
|
|
5
|
+
tone?: "error" | "default" | "primary" | undefined;
|
|
6
6
|
} & {
|
|
7
7
|
class?: import("tailwind-variants/lite").ClassValue;
|
|
8
8
|
className?: never;
|
|
9
9
|
}) | ({
|
|
10
10
|
kind?: "field" | "select" | "area" | undefined;
|
|
11
11
|
size?: "xl" | "lg" | "md" | "sm" | "xs" | undefined;
|
|
12
|
-
tone?: "
|
|
12
|
+
tone?: "error" | "default" | "primary" | undefined;
|
|
13
13
|
} & {
|
|
14
14
|
class?: never;
|
|
15
15
|
className?: import("tailwind-variants/lite").ClassValue;
|
|
@@ -21,7 +21,7 @@ export declare class CsrSlide {
|
|
|
21
21
|
static get isCalm(): boolean;
|
|
22
22
|
static settleMove(kind: "push" | "replace", from: Location, to: Location): boolean;
|
|
23
23
|
/** How an entry moves: its own page's transition, or that of the page it took the place of. */
|
|
24
|
-
static motionOf(location: Location): "
|
|
24
|
+
static motionOf(location: Location): "stack" | "none" | "fade" | "bottomUp" | "scaleOut";
|
|
25
25
|
/** Whether an entry swipes back: its own page's `gesture`, or that of the page it took the place of. */
|
|
26
26
|
static swipesBack(location: Location): boolean;
|
|
27
27
|
static isStill(entryId: string | undefined): boolean;
|
|
@@ -17,8 +17,8 @@ export declare const useCsrRefs: () => {
|
|
|
17
17
|
pageContentRef: import("react").RefObject<HTMLDivElement | null>;
|
|
18
18
|
prevPageContentRef: import("react").RefObject<HTMLDivElement | null>;
|
|
19
19
|
onBack: import("react").RefObject<{
|
|
20
|
-
none?: (() => Promise<void>) | undefined;
|
|
21
20
|
stack?: (() => Promise<void>) | undefined;
|
|
21
|
+
none?: (() => Promise<void>) | undefined;
|
|
22
22
|
fade?: (() => Promise<void>) | undefined;
|
|
23
23
|
bottomUp?: (() => Promise<void>) | undefined;
|
|
24
24
|
scaleOut?: (() => Promise<void>) | undefined;
|
|
@@ -84,6 +84,7 @@ export declare function resolvePathRoutesWithFrameState(pathRoutes: PathRoute[],
|
|
|
84
84
|
pageState: PageState;
|
|
85
85
|
path: string;
|
|
86
86
|
pathSegments: string[];
|
|
87
|
+
shadowedBy?: string[];
|
|
87
88
|
renderPage: import("akanjs/client").RouteRender;
|
|
88
89
|
pageConfigChain?: import("akanjs/client").PageConfig[];
|
|
89
90
|
explicitPageConfigKeys?: Partial<Record<keyof import("akanjs/client").PageConfig, boolean>>;
|
|
@@ -17,6 +17,7 @@ export declare const useResolvedFrame: ({ pathRoutes, slots: { frameSlots, pendi
|
|
|
17
17
|
pageState: PageState;
|
|
18
18
|
path: string;
|
|
19
19
|
pathSegments: string[];
|
|
20
|
+
shadowedBy?: string[];
|
|
20
21
|
renderPage: import("akanjs/client").RouteRender;
|
|
21
22
|
pageConfigChain?: import("akanjs/client").PageConfig[];
|
|
22
23
|
explicitPageConfigKeys?: Partial<Record<keyof import("akanjs/client").PageConfig, boolean>>;
|