akanjs 3.3.0-rc.78 → 3.3.0-rc.79
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 +19 -2
- package/client/router.ts +5 -2
- package/package.json +1 -1
- package/store/agent/ScreenSettle.ts +27 -0
- package/store/agent/StoreSurfaceSource.ts +8 -3
- package/types/client/csrLocation.d.ts +2 -1
- package/types/client/router.d.ts +2 -1
- package/types/store/agent/ScreenSettle.d.ts +5 -0
- package/types/ui/Load/LoadingMark.d.ts +4 -0
- package/types/ui/Load/Stream.d.ts +1 -1
- package/ui/Load/LoadingMark.tsx +8 -0
- package/ui/Load/PageCSR.tsx +3 -1
- package/ui/Load/Stream.tsx +3 -1
- package/ui/Load/Units.tsx +3 -2
- package/ui/System/Client.tsx +1 -3
- package/webkit/RenderLayer.tsx +7 -1
- package/webkit/useCsrValues.ts +1 -1
package/client/csrLocation.ts
CHANGED
|
@@ -4,6 +4,8 @@ declare global {
|
|
|
4
4
|
var __AKAN_EMBED__: { kind: "mcp-app"; origin?: string; account?: Record<string, unknown> | null } | undefined;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
+
const popWaitMs = 1000;
|
|
8
|
+
|
|
7
9
|
/** The document's location and history, as the routers read and move them. */
|
|
8
10
|
export class CsrLocation {
|
|
9
11
|
|
|
@@ -117,12 +119,27 @@ export class CsrLocation {
|
|
|
117
119
|
return entry === this.#backAsked || entry === this.#backSent;
|
|
118
120
|
}
|
|
119
121
|
|
|
120
|
-
back
|
|
122
|
+
/** Settles once the back's pop has moved the address, or at once when no entry of this document is under it. */
|
|
123
|
+
back(): Promise<void> {
|
|
121
124
|
const entry = this.entry();
|
|
122
125
|
if (entry.idx !== undefined) this.#onBack?.(entry.idx - 1);
|
|
123
126
|
|
|
124
|
-
|
|
127
|
+
const pops = entry.idx !== undefined && entry.idx > 0;
|
|
128
|
+
if (pops) this.#backSent = entry;
|
|
129
|
+
const landed = pops ? CsrLocation.#nextPop() : Promise.resolve();
|
|
125
130
|
window.history.back();
|
|
131
|
+
return landed;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
static #nextPop() {
|
|
135
|
+
return new Promise<void>((resolve) => {
|
|
136
|
+
const land = () => {
|
|
137
|
+
clearTimeout(cap);
|
|
138
|
+
resolve();
|
|
139
|
+
};
|
|
140
|
+
const cap = setTimeout(land, popWaitMs);
|
|
141
|
+
window.addEventListener("popstate", land, { once: true });
|
|
142
|
+
});
|
|
126
143
|
}
|
|
127
144
|
|
|
128
145
|
assign(href: string) {
|
package/client/router.ts
CHANGED
|
@@ -43,7 +43,8 @@ export interface RouterInstance {
|
|
|
43
43
|
/** May answer a promise that rejects when the route refused to move — see `Router.navigation`. */
|
|
44
44
|
push: (href: string, routeOptions?: RouteOptions) => void | Promise<void>;
|
|
45
45
|
replace: (href: string, routeOptions?: RouteOptions) => void | Promise<void>;
|
|
46
|
-
back
|
|
46
|
+
/** May answer a promise that settles once the back has landed. */
|
|
47
|
+
back: (routeOptions?: RouteOptions) => void | Promise<void>;
|
|
47
48
|
refresh: () => void;
|
|
48
49
|
/** Whether `back` has a page to return to; left out, the router reads the index stamped on the history entry. */
|
|
49
50
|
canGoBack?: () => boolean;
|
|
@@ -675,7 +676,9 @@ class Router {
|
|
|
675
676
|
this.#checkInitialized();
|
|
676
677
|
this.#guarded("back", null, () => {
|
|
677
678
|
this.#navigations += 1;
|
|
678
|
-
|
|
679
|
+
const moving = this.#instance.back(routeOptions);
|
|
680
|
+
csrLocation.leaving(moving);
|
|
681
|
+
return moving;
|
|
679
682
|
});
|
|
680
683
|
return undefined as never;
|
|
681
684
|
}
|
package/package.json
CHANGED
|
@@ -30,4 +30,31 @@ export class ScreenSettle {
|
|
|
30
30
|
else rearm();
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
|
+
|
|
34
|
+
/** Resolves once no load on a page in view is pending, each `Load.*` fallback marking itself; `false` when none was. */
|
|
35
|
+
static loaded({ timeoutMs = 5000 }: { timeoutMs?: number } = {}): Promise<boolean> {
|
|
36
|
+
const body = typeof document === "undefined" ? null : (document.body ?? document.documentElement);
|
|
37
|
+
if (!body || typeof MutationObserver === "undefined" || !ScreenSettle.#loading(body)) return Promise.resolve(false);
|
|
38
|
+
return new Promise((resolve) => {
|
|
39
|
+
const done = () => {
|
|
40
|
+
clearTimeout(deadline);
|
|
41
|
+
observer.disconnect();
|
|
42
|
+
resolve(true);
|
|
43
|
+
};
|
|
44
|
+
const observer = new MutationObserver(() => {
|
|
45
|
+
if (!ScreenSettle.#loading(body)) done();
|
|
46
|
+
});
|
|
47
|
+
const deadline = setTimeout(done, timeoutMs);
|
|
48
|
+
observer.observe(body, { attributes: true, childList: true, subtree: true });
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static #loading(body: HTMLElement) {
|
|
53
|
+
for (const mark of body.querySelectorAll("template[data-akan-loading]")) {
|
|
54
|
+
const holder = mark.parentElement;
|
|
55
|
+
if (!holder || holder.closest('[hidden], [aria-hidden="true"], [inert]')) continue;
|
|
56
|
+
if (typeof holder.checkVisibility !== "function" || holder.checkVisibility()) return true;
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
33
60
|
}
|
|
@@ -66,7 +66,7 @@ export class StoreSurfaceSource implements SurfaceSource {
|
|
|
66
66
|
throw new Error(`There is no route at ${path}, so the page did not move. ${StoreSurfaceSource.#linked()}`);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
await
|
|
69
|
+
await StoreSurfaceSource.#settled();
|
|
70
70
|
if (isNotFoundView()) {
|
|
71
71
|
const left = await StoreSurfaceSource.#leaveNotFound();
|
|
72
72
|
throw new Error(
|
|
@@ -79,6 +79,11 @@ export class StoreSurfaceSource implements SurfaceSource {
|
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
static async #settled() {
|
|
83
|
+
await ScreenSettle.wait({ appearMs: 800, timeoutMs: 5000 });
|
|
84
|
+
if (await ScreenSettle.loaded({ timeoutMs: 5000 })) await ScreenSettle.wait({ timeoutMs: 2000 });
|
|
85
|
+
}
|
|
86
|
+
|
|
82
87
|
static async #leaveNotFound(): Promise<boolean> {
|
|
83
88
|
if (!router.canGoBack()) return false;
|
|
84
89
|
router.back();
|
|
@@ -86,7 +91,7 @@ export class StoreSurfaceSource implements SurfaceSource {
|
|
|
86
91
|
() => true,
|
|
87
92
|
() => false,
|
|
88
93
|
);
|
|
89
|
-
await
|
|
94
|
+
await StoreSurfaceSource.#settled();
|
|
90
95
|
return left;
|
|
91
96
|
}
|
|
92
97
|
|
|
@@ -132,7 +137,7 @@ export class StoreSurfaceSource implements SurfaceSource {
|
|
|
132
137
|
await router.navigation().catch((error: unknown) => {
|
|
133
138
|
if (StoreSurfaceSource.#isKept(error)) throw new Error(StoreSurfaceSource.#kept);
|
|
134
139
|
});
|
|
135
|
-
await
|
|
140
|
+
await StoreSurfaceSource.#settled();
|
|
136
141
|
return `Back on ${router.getPath()}. ${StoreSurfaceSource.#arrived}`;
|
|
137
142
|
},
|
|
138
143
|
};
|
|
@@ -43,7 +43,8 @@ export declare class CsrLocation {
|
|
|
43
43
|
leaving(moving: unknown): void;
|
|
44
44
|
/** Whether a back has left the entry on screen and not landed yet. */
|
|
45
45
|
isLeaving(): boolean;
|
|
46
|
-
back
|
|
46
|
+
/** Settles once the back's pop has moved the address, or at once when no entry of this document is under it. */
|
|
47
|
+
back(): Promise<void>;
|
|
47
48
|
assign(href: string): void;
|
|
48
49
|
reload(): void;
|
|
49
50
|
}
|
package/types/client/router.d.ts
CHANGED
|
@@ -23,7 +23,8 @@ export interface RouterInstance {
|
|
|
23
23
|
/** May answer a promise that rejects when the route refused to move — see `Router.navigation`. */
|
|
24
24
|
push: (href: string, routeOptions?: RouteOptions) => void | Promise<void>;
|
|
25
25
|
replace: (href: string, routeOptions?: RouteOptions) => void | Promise<void>;
|
|
26
|
-
back
|
|
26
|
+
/** May answer a promise that settles once the back has landed. */
|
|
27
|
+
back: (routeOptions?: RouteOptions) => void | Promise<void>;
|
|
27
28
|
refresh: () => void;
|
|
28
29
|
/** Whether `back` has a page to return to; left out, the router reads the index stamped on the history entry. */
|
|
29
30
|
canGoBack?: () => boolean;
|
|
@@ -7,5 +7,10 @@ export interface ScreenSettleOptions {
|
|
|
7
7
|
}
|
|
8
8
|
/** Resolves once the DOM stops mutating, always bounded; no single router or store signal says "settled". */
|
|
9
9
|
export declare class ScreenSettle {
|
|
10
|
+
#private;
|
|
10
11
|
static wait({ quietMs, appearMs, timeoutMs }?: ScreenSettleOptions): Promise<void>;
|
|
12
|
+
/** Resolves once no load on a page in view is pending, each `Load.*` fallback marking itself; `false` when none was. */
|
|
13
|
+
static loaded({ timeoutMs }?: {
|
|
14
|
+
timeoutMs?: number;
|
|
15
|
+
}): Promise<boolean>;
|
|
11
16
|
}
|
|
@@ -12,5 +12,5 @@ interface StreamProps<Value> {
|
|
|
12
12
|
error?: StreamError;
|
|
13
13
|
children: (value: Value) => ReactNode;
|
|
14
14
|
}
|
|
15
|
-
export default function Stream<Value>({ of, fallback, error, children }: StreamProps<Value>): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react").JSX.Element | null | undefined;
|
|
15
|
+
export default function Stream<Value>({ of, fallback: shown, error, children }: StreamProps<Value>): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react").JSX.Element | null | undefined;
|
|
16
16
|
export {};
|
package/ui/Load/PageCSR.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { type ReactNode, useEffect, useMemo, useState } from "react";
|
|
3
3
|
|
|
4
|
+
import { LoadingMark } from "./LoadingMark";
|
|
4
5
|
import type { PageProps } from "./Page";
|
|
5
6
|
|
|
6
7
|
const CacheMap = new WeakMap<object, Record<string, unknown>>();
|
|
@@ -34,6 +35,7 @@ export const PageCSR = <Return,>({ of, loader, render, loading, noCache = false
|
|
|
34
35
|
}
|
|
35
36
|
})();
|
|
36
37
|
}, []);
|
|
37
|
-
if (!fetchState.fulfilled
|
|
38
|
+
if (!fetchState.fulfilled) return <LoadingMark>{loading?.()}</LoadingMark>;
|
|
39
|
+
if (!fetchState.value) return loading ? loading() : null;
|
|
38
40
|
else return <>{render(fetchState.value)}</>;
|
|
39
41
|
};
|
package/ui/Load/Stream.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { PromiseOrObject } from "akanjs/base";
|
|
2
2
|
import { isThenable } from "akanjs/common";
|
|
3
3
|
import { type ReactNode, Suspense, type Usable, use } from "react";
|
|
4
|
+
import { LoadingMark } from "./LoadingMark";
|
|
4
5
|
import { StreamBoundary, type StreamError } from "./StreamBoundary";
|
|
5
6
|
import { StreamDeferred } from "./StreamDeferred";
|
|
6
7
|
|
|
@@ -28,7 +29,8 @@ const resetKeyOf = (thenable: object) => {
|
|
|
28
29
|
return key;
|
|
29
30
|
};
|
|
30
31
|
|
|
31
|
-
export default function Stream<Value>({ of, fallback = null, error, children }: StreamProps<Value>) {
|
|
32
|
+
export default function Stream<Value>({ of, fallback: shown = null, error, children }: StreamProps<Value>) {
|
|
33
|
+
const fallback = <LoadingMark>{shown}</LoadingMark>;
|
|
32
34
|
|
|
33
35
|
if (isThenable(of) && process.env.AKAN_PUBLIC_RENDER_ENV === "csr")
|
|
34
36
|
return (
|
package/ui/Load/Units.tsx
CHANGED
|
@@ -13,6 +13,7 @@ import { Empty } from "../Empty";
|
|
|
13
13
|
import { Loading } from "../Loading";
|
|
14
14
|
import { More } from "../More";
|
|
15
15
|
import { sliceNamesOf } from "../sliceNamesOf";
|
|
16
|
+
import { LoadingMark } from "./LoadingMark";
|
|
16
17
|
import Stream from "./Stream";
|
|
17
18
|
import type { StreamError } from "./StreamBoundary";
|
|
18
19
|
import { SliceClaim } from "./sliceClaim";
|
|
@@ -229,7 +230,7 @@ function Render<RefName extends string, Light extends { id: string }>({
|
|
|
229
230
|
) : typeof renderEmpty === "function" ? (
|
|
230
231
|
renderEmpty()
|
|
231
232
|
) : null}
|
|
232
|
-
{showLoading ? loading : null}
|
|
233
|
+
{showLoading ? <LoadingMark>{loading}</LoadingMark> : null}
|
|
233
234
|
</>
|
|
234
235
|
);
|
|
235
236
|
else if (!renderItem) throw new Error("renderItem is required");
|
|
@@ -256,7 +257,7 @@ function Render<RefName extends string, Light extends { id: string }>({
|
|
|
256
257
|
? renderEmpty()
|
|
257
258
|
: null}
|
|
258
259
|
</ContainerWrapper>
|
|
259
|
-
{showLoading ? loading : null}
|
|
260
|
+
{showLoading ? <LoadingMark>{loading}</LoadingMark> : null}
|
|
260
261
|
</>
|
|
261
262
|
);
|
|
262
263
|
}
|
package/ui/System/Client.tsx
CHANGED
|
@@ -457,9 +457,7 @@ export const ClientSsrBridge = ({ lang, prefix = "", initialPageState }: ClientS
|
|
|
457
457
|
syncHref(href);
|
|
458
458
|
return navigateRscWithFallback(href, { ...routeOptions, replace: true }, () => window.location.replace(href));
|
|
459
459
|
},
|
|
460
|
-
back: () =>
|
|
461
|
-
csrLocation.back();
|
|
462
|
-
},
|
|
460
|
+
back: () => csrLocation.back(),
|
|
463
461
|
refresh: () => {
|
|
464
462
|
syncHref(window.location.href);
|
|
465
463
|
void refreshRsc();
|
package/webkit/RenderLayer.tsx
CHANGED
|
@@ -184,7 +184,13 @@ export const RenderLayer = memo((props: RenderLayerProps) => {
|
|
|
184
184
|
);
|
|
185
185
|
if (drawn) return createElement(routeRender.render as never, { children, ...drawn } as never);
|
|
186
186
|
if (!value || !isAsyncRender || isRefused)
|
|
187
|
-
return
|
|
187
|
+
return (
|
|
188
|
+
<>
|
|
189
|
+
{Translator.renderAt(renderPath, () => composeLoadingFallback(renders.slice(index), params))}
|
|
190
|
+
{/* The mark a `Load.*` fallback draws too, which the in-page agent's navigate waits out. */}
|
|
191
|
+
{isLoading ? <template data-akan-loading="" /> : null}
|
|
192
|
+
</>
|
|
193
|
+
);
|
|
188
194
|
return <layerChildContext.Provider value={children}>{value}</layerChildContext.Provider>;
|
|
189
195
|
});
|
|
190
196
|
|
package/webkit/useCsrValues.ts
CHANGED
|
@@ -114,7 +114,7 @@ const useCsrRouter = ({
|
|
|
114
114
|
const scrollTop = pageContentRef.current?.scrollTop ?? 0;
|
|
115
115
|
setHistoryBack({ type: "back", location, scrollTop, scrollToTop });
|
|
116
116
|
settle(getPrevLocation());
|
|
117
|
-
csrLocation.back();
|
|
117
|
+
await csrLocation.back();
|
|
118
118
|
},
|
|
119
119
|
};
|
|
120
120
|
window.onpopstate = async (event) => {
|