akanjs 3.2.0-rc.26 → 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 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akanjs",
3
- "version": "3.2.0-rc.26",
3
+ "version": "3.2.0-rc.28",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -23,5 +23,6 @@ export declare class CsrGuards {
23
23
  /** Whether a verdict for `key` is held or on its way. */
24
24
  static asked(key: string): boolean;
25
25
  static hold(key: string): () => void;
26
+ static expire(location: GuardedLocation): void;
26
27
  }
27
28
  export {};
@@ -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 {};
@@ -9,6 +9,14 @@
9
9
 
10
10
  ### Patch Changes
11
11
 
12
+ - fb564fd: An Akan Android app no longer crashes on launch on Android 12 and 12L (API 31-32). Every launch there closed at once with a `NullPointerException` from `PhoneWindow.getInsetsController`, and the old-WebView screen crashed the same way.
13
+
14
+ - On API 30-32 the window's insets controller reads a decor view the window has not created yet. The activity set the bar icon colors through it before `setContentView`, so it threw.
15
+ - The runtime now creates the decor view first, and the bar settings apply once the view is attached. Showing or hiding the bars goes through the same path.
16
+ - Android 11 and earlier set the bar icon colors through the older flags, and the same call does not throw on Android 13 and later, so neither crashed.
17
+
18
+ Rebuild the Android app on this version to pick up the fix.
19
+
12
20
  - 66e6074: `app.relaunch()` and the desktop recovery's relaunch now start an AppImage again from its own file (`$APPIMAGE`) instead of the mount it ran from, which is gone once the app exits, so the app no longer quits without coming back. The relaunched app no longer inherits the old mount's `APPDIR`, `APPIMAGE`, `ARGV0` and `OWD`; its AppImage runtime sets them anew. An app that another AppImage started (an AppImage editor or launcher, say) inherits that AppImage's `APPIMAGE`; relaunch, the deep-link handler and the autostart entry now use `$APPIMAGE` only when the app runs from that AppImage's own mount, so such an app no longer registers the other AppImage in its place.
13
21
  - f5c6f07: `externalView.evaluate` on Linux now goes through WebKitGTK's own JavaScript call, as macOS goes through WKWebView's. A script evaluated before the view's first navigation committed used to be rejected with `CANCELLED` and then run anyway at the commit, so a retry ran it twice: it now runs once and is answered once. A result with no JSON form (undefined, an exception, a function, a cycle) used to come back as `""` and is now `null`, as the typings say. An evaluate its web process ended under answers `INTERNAL`, and one a close or a rebuild of the view cut off answers `CANCELLED`.
14
22
  - e3de9ef: Native and desktop builds now ship tighter defaults for page content, external links, temporary files and installed updates.
@@ -922,15 +922,18 @@ class AkanNativeActivity : Activity(), AkanNativePluginContext.Host {
922
922
  @Suppress("DEPRECATION") // deprecated in 35, where edge-to-edge is enforced and this is a no-op
923
923
  fun decorFitsSystemWindows(window: Window, fits: Boolean) = window.setDecorFitsSystemWindows(fits)
924
924
 
925
+ // API 30-32's PhoneWindow.getInsetsController reads a decor it never creates, so it threw before setContentView.
926
+ private fun controller(window: Window): WindowInsetsController? = window.decorView.let { window.insetsController }
927
+
925
928
  fun lightBars(window: Window, status: Boolean, navigation: Boolean) {
926
929
  val bits = WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS or WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS
927
930
  val light = (if (status) WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS else 0) or
928
931
  (if (navigation) WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS else 0)
929
- window.insetsController?.setSystemBarsAppearance(light, bits)
932
+ controller(window)?.setSystemBarsAppearance(light, bits)
930
933
  }
931
934
 
932
935
  fun systemBars(window: Window, visible: Boolean) {
933
- val controller = window.insetsController ?: return
936
+ val controller = controller(window) ?: return
934
937
  if (visible) return controller.show(WindowInsets.Type.systemBars())
935
938
  controller.hide(WindowInsets.Type.systemBars())
936
939
  controller.systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
@@ -84,6 +84,10 @@ export class CsrGuards {
84
84
  };
85
85
  }
86
86
 
87
+ static expire(location: GuardedLocation) {
88
+ CsrGuards.#forget(CsrGuards.keyOf(location));
89
+ }
90
+
87
91
  static #forget(key: string) {
88
92
  CsrGuards.#runs.delete(key);
89
93
  CsrGuards.#admitted.delete(key);
@@ -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 { createContext, createElement, memo, type ReactNode, useContext, useEffect, useRef, useState } from "react";
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 ? `${location.entryId ?? ""} ${location.href}` : null;
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
- !rendered ||
122
- rendered.render !== routeRender.render ||
123
- rendered.argsKey !== argsKey ||
124
- (returned && rendered.redirected) ||
125
- moved ||
126
- lapsed
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
+ }
@@ -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
- csrLocation.reload();
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;