akanjs 3.2.0-rc.27 → 3.2.0-rc.28
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 +12 -0
- package/package.json +1 -1
- package/types/webkit/CsrGuards.d.ts +1 -0
- package/types/webkit/csrRefresh.d.ts +13 -0
- package/webkit/CsrGuards.ts +4 -0
- package/webkit/RenderLayer.tsx +48 -14
- package/webkit/csrRefresh.ts +33 -0
- package/webkit/useCsrValues.ts +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -505,6 +505,18 @@
|
|
|
505
505
|
|
|
506
506
|
`akan lint`'s `akan.service.call-in-loop` fix and the agent guidelines name `create<Model>Many` as the way to write a set once.
|
|
507
507
|
|
|
508
|
+
- ca67c2c: `router.refresh()` in a CSR bundle, which is what a native app runs, no longer reloads the document. It used to call `window.location.reload()`, so the screen went white and the store, scroll position, open modals, form drafts and the agent session were all lost.
|
|
509
|
+
|
|
510
|
+
Now it works the way the web's refresh does.
|
|
511
|
+
|
|
512
|
+
- The page on screen runs its async renders again: every layout and page level, and the root layouts, with fresh fetches.
|
|
513
|
+
- Each level keeps what it drew until its new render settles, so nothing blanks or falls back to `.loading()`. A component that stays in place keeps its state.
|
|
514
|
+
- The route's guards run again. A guard that now refuses moves the router, as it does on a navigation.
|
|
515
|
+
- A level whose new render fails shows the failure notice with a retry in its place. The document is not reloaded.
|
|
516
|
+
- Pages parked in the stack are left as they are.
|
|
517
|
+
|
|
518
|
+
Code that called `router.refresh()` in a CSR app to reset client state should reset that state itself.
|
|
519
|
+
|
|
508
520
|
- 73f8830: An error an endpoint declares in `errors` and throws with that status under 500 is now logged at debug, as a returned call is, rather than as an ERROR line. A public endpoint that answers a bad token with a declared 404 no longer sends every probe, token scan or mistyped webhook URL to real-error alerts. Undeclared errors, a declared key thrown with another status, and every 5xx still log as errors.
|
|
509
521
|
- 5691327: `setErrorConstructor` on `FetchClient`, `HttpClient` and `WsClient`, `HttpClientOptions.ErrorCls` and `FetchClient.build`'s `Err` option are deprecated. Every dictionary's `Err` is `akanjs/common`'s `Err`, which a restored error already is, so they change nothing. They keep working. A generated `lib/sig.ts` no longer calls `fetch.setErrorConstructor(Err)`, and a generated `lib/useClient.ts` no longer passes `{ Err: pageProto.Err }`; `akan sync` rewrites both. No upgrade step is needed.
|
|
510
522
|
- 14134d3: Under `akan start`, a backend replica that crashes while it waits on the builder no longer has that answer handed to the replica respawned in its place, where it could settle the new process's own request of the same id with its predecessor's route, CSR or graph result. The gateway now forgets a replica's open builder requests when it exits, and passes each answer only to the process that asked.
|
package/package.json
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Location } from "akanjs/client";
|
|
2
|
+
interface CsrRefreshRequest {
|
|
3
|
+
epoch: number;
|
|
4
|
+
locationId: string | null;
|
|
5
|
+
}
|
|
6
|
+
export declare class CsrRefresh {
|
|
7
|
+
#private;
|
|
8
|
+
static idOf({ entryId, href }: Pick<Location, "entryId" | "href">): string;
|
|
9
|
+
static request(location: Location): void;
|
|
10
|
+
static subscribe(listener: () => void): () => void;
|
|
11
|
+
static current(): CsrRefreshRequest;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
package/webkit/CsrGuards.ts
CHANGED
package/webkit/RenderLayer.tsx
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { debugFrame, RouteDefinition, type RouteRender, router, Translator, usePathCtx } from "akanjs/client";
|
|
3
3
|
import { isThenable, Logger } from "akanjs/common";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
createContext,
|
|
6
|
+
createElement,
|
|
7
|
+
memo,
|
|
8
|
+
type ReactNode,
|
|
9
|
+
useContext,
|
|
10
|
+
useEffect,
|
|
11
|
+
useRef,
|
|
12
|
+
useState,
|
|
13
|
+
useSyncExternalStore,
|
|
14
|
+
} from "react";
|
|
5
15
|
import { CsrGuards } from "./CsrGuards";
|
|
6
16
|
import { CsrFrameDump } from "./csrFrameDump";
|
|
17
|
+
import { CsrRefresh } from "./csrRefresh";
|
|
7
18
|
import { RenderFailure } from "./RenderFailure";
|
|
8
19
|
import { useFetch } from "./useFetch";
|
|
9
20
|
import { usePageActivity } from "./usePageActivity";
|
|
@@ -27,6 +38,7 @@ interface RenderedRoute {
|
|
|
27
38
|
failure: { error: unknown } | null;
|
|
28
39
|
/** Asked after the layer's last run was refused, so it draws nothing until its own answer arrives. */
|
|
29
40
|
afterRefusal: boolean;
|
|
41
|
+
refreshEpoch: number;
|
|
30
42
|
}
|
|
31
43
|
|
|
32
44
|
interface RenderLayerProps {
|
|
@@ -49,6 +61,7 @@ export const RenderLayer = memo((props: RenderLayerProps) => {
|
|
|
49
61
|
const renderedRef = useRef<RenderedRoute | null>(null);
|
|
50
62
|
const [, setFailures] = useState(0);
|
|
51
63
|
const activity = usePageActivity();
|
|
64
|
+
const refresh = useSyncExternalStore(CsrRefresh.subscribe, CsrRefresh.current, CsrRefresh.current);
|
|
52
65
|
|
|
53
66
|
const onScreenRef = useRef(activity === "current");
|
|
54
67
|
useEffect(() => {
|
|
@@ -65,7 +78,7 @@ export const RenderLayer = memo((props: RenderLayerProps) => {
|
|
|
65
78
|
|
|
66
79
|
const guarded = location && CsrGuards.declared(location) ? location : null;
|
|
67
80
|
const guardKey = guarded ? CsrGuards.keyOf(guarded) : null;
|
|
68
|
-
const locationId = location ?
|
|
81
|
+
const locationId = location ? CsrRefresh.idOf(location) : null;
|
|
69
82
|
|
|
70
83
|
const mayAsk = activity !== "hidden" && activity !== "prev";
|
|
71
84
|
useEffect(() => (guardKey ? CsrGuards.hold(guardKey) : undefined), [guardKey]);
|
|
@@ -110,20 +123,17 @@ export const RenderLayer = memo((props: RenderLayerProps) => {
|
|
|
110
123
|
)
|
|
111
124
|
: (guardKey ?? "");
|
|
112
125
|
const rendered = renderedRef.current;
|
|
113
|
-
|
|
114
126
|
const returned = activity === "current" && !onScreenRef.current;
|
|
115
|
-
|
|
116
|
-
const moved = !!rendered?.refusedAt && rendered.refusedAt !== locationId;
|
|
117
|
-
|
|
118
|
-
const lapsed = !isAsyncRender && rendered?.admittedKey === guardKey;
|
|
119
|
-
|
|
120
127
|
if (
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
128
|
+
mustRerun(rendered, {
|
|
129
|
+
render: routeRender.render,
|
|
130
|
+
argsKey,
|
|
131
|
+
returned,
|
|
132
|
+
locationId,
|
|
133
|
+
guardKey,
|
|
134
|
+
isAsyncRender,
|
|
135
|
+
refresh,
|
|
136
|
+
})
|
|
127
137
|
) {
|
|
128
138
|
const redirectsBefore = router.redirectCount();
|
|
129
139
|
const layer = `${routeRender.kind ?? "layout"} ${index} of ${path}`;
|
|
@@ -156,6 +166,7 @@ export const RenderLayer = memo((props: RenderLayerProps) => {
|
|
|
156
166
|
admittedKey: null,
|
|
157
167
|
failure: null,
|
|
158
168
|
afterRefusal: !!rendered?.refusedAt,
|
|
169
|
+
refreshEpoch: refresh.epoch,
|
|
159
170
|
};
|
|
160
171
|
if (isThenable(result))
|
|
161
172
|
(result as Promise<ReactNode>).then(
|
|
@@ -208,6 +219,29 @@ export const RenderLayer = memo((props: RenderLayerProps) => {
|
|
|
208
219
|
return <layerChildContext.Provider value={children}>{value}</layerChildContext.Provider>;
|
|
209
220
|
});
|
|
210
221
|
|
|
222
|
+
interface LayerRun {
|
|
223
|
+
render: RouteRender["render"];
|
|
224
|
+
argsKey: string;
|
|
225
|
+
returned: boolean;
|
|
226
|
+
locationId: string | null;
|
|
227
|
+
guardKey: string | null;
|
|
228
|
+
isAsyncRender: boolean;
|
|
229
|
+
refresh: ReturnType<typeof CsrRefresh.current>;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function mustRerun(rendered: RenderedRoute | null, run: LayerRun): boolean {
|
|
233
|
+
if (!rendered || rendered.render !== run.render || rendered.argsKey !== run.argsKey) return true;
|
|
234
|
+
|
|
235
|
+
if (run.returned && rendered.redirected) return true;
|
|
236
|
+
|
|
237
|
+
if (rendered.refusedAt && rendered.refusedAt !== run.locationId) return true;
|
|
238
|
+
|
|
239
|
+
if (!run.isAsyncRender && rendered.admittedKey === run.guardKey) return true;
|
|
240
|
+
|
|
241
|
+
if (rendered.refreshEpoch === run.refresh.epoch) return false;
|
|
242
|
+
return run.locationId === null || run.refresh.locationId === run.locationId;
|
|
243
|
+
}
|
|
244
|
+
|
|
211
245
|
function reportFailure(result: ReactNode | Promise<ReactNode>, layer: string): ReactNode | Promise<ReactNode> {
|
|
212
246
|
if (!isThenable(result)) return result;
|
|
213
247
|
debugFrame("layer.render", { layer });
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Location } from "akanjs/client";
|
|
2
|
+
import { CsrGuards } from "./CsrGuards";
|
|
3
|
+
|
|
4
|
+
interface CsrRefreshRequest {
|
|
5
|
+
epoch: number;
|
|
6
|
+
locationId: string | null;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class CsrRefresh {
|
|
10
|
+
static #request: CsrRefreshRequest = { epoch: 0, locationId: null };
|
|
11
|
+
static readonly #listeners = new Set<() => void>();
|
|
12
|
+
|
|
13
|
+
static idOf({ entryId, href }: Pick<Location, "entryId" | "href">): string {
|
|
14
|
+
return `${entryId ?? ""} ${href}`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static request(location: Location) {
|
|
18
|
+
if (CsrGuards.declared(location)) CsrGuards.expire(location);
|
|
19
|
+
CsrRefresh.#request = { epoch: CsrRefresh.#request.epoch + 1, locationId: CsrRefresh.idOf(location) };
|
|
20
|
+
for (const listener of CsrRefresh.#listeners) listener();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static subscribe(listener: () => void): () => void {
|
|
24
|
+
CsrRefresh.#listeners.add(listener);
|
|
25
|
+
return () => {
|
|
26
|
+
CsrRefresh.#listeners.delete(listener);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static current(): CsrRefreshRequest {
|
|
31
|
+
return CsrRefresh.#request;
|
|
32
|
+
}
|
|
33
|
+
}
|
package/webkit/useCsrValues.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
} from "akanjs/client";
|
|
18
18
|
import { isNativeApp, openExternalUrl } from "akanjs/client/native";
|
|
19
19
|
import { useCallback, useMemo, useState } from "react";
|
|
20
|
+
import { CsrRefresh } from "./csrRefresh";
|
|
20
21
|
import { useCsrKeyboard } from "./useCsrKeyboard";
|
|
21
22
|
import { type CsrLocationState, useCsrLocationState } from "./useCsrLocationState";
|
|
22
23
|
import { type CsrNavigation, useCsrNavigation } from "./useCsrNavigation";
|
|
@@ -75,7 +76,9 @@ const useCsrRouter = ({
|
|
|
75
76
|
push: forward("push"),
|
|
76
77
|
replace: forward("replace"),
|
|
77
78
|
refresh: () => {
|
|
78
|
-
|
|
79
|
+
const location = getCurrentLocation();
|
|
80
|
+
debugFrame("router.refresh", { href: location.href });
|
|
81
|
+
CsrRefresh.request(location);
|
|
79
82
|
},
|
|
80
83
|
back: async ({ scrollToTop }: RouteOptions = {}) => {
|
|
81
84
|
waitingNavigation.current = null;
|