@hadoku/ui-shell 0.1.144 → 0.1.146

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.
@@ -20,6 +20,16 @@
20
20
  * reloads. The edge answers that load with its sign-in wall, which gives a signed-out visitor an
21
21
  * account and sends them on. A second loss within {@link RELOAD_GUARD_MS} of one this tab already
22
22
  * reloaded for does not reload again: the page stays stopped rather than loop.
23
+ *
24
+ * A session the page changes ITSELF is not a lost one. Delete account, a sign-in with a key or a
25
+ * passkey: each is a write to the fleet's session service ({@link SESSION_SERVICE_PATHS}) that ends
26
+ * or replaces this browser's session, and the page goes somewhere of its own choosing once it
27
+ * answers. Until then the edge refuses everything under `scope`, and a reload would cut the write
28
+ * off and send the browser through the wall as a new guest (2026-11-27, Delete account on
29
+ * cardtable-ppe). So the same `fetch` wrapper watches for those writes (any caller's: the fleet
30
+ * header posts them with the page's own `fetch`), and while one is in flight, and for
31
+ * {@link SESSION_WRITE_HOLD_MS} after one succeeds, no suspicion is probed and no probe's 401
32
+ * stops the page. A write that fails holds nothing past its answer.
23
33
  */
24
34
  /** The least time between two probes. */
25
35
  export declare const PROBE_GAP_MS = 10000;
@@ -27,6 +37,10 @@ export declare const PROBE_GAP_MS = 10000;
27
37
  export declare const RELOAD_GUARD_MS = 60000;
28
38
  /** Where this tab notes when it last reloaded for a lost session. */
29
39
  export declare const RELOADED_KEY = "hadoku:session-lost-reload";
40
+ /** The fleet's session service on the page's origin: a write under one of these changes who this browser is. */
41
+ export declare const SESSION_SERVICE_PATHS: readonly ["/session/", "/auth/"];
42
+ /** How long after a session write succeeds the page is left to its own navigation. */
43
+ export declare const SESSION_WRITE_HOLD_MS = 10000;
30
44
  /** What the watch needs of a socket (socket.io's `Socket` is one): its connect errors and its end, and a way to end it. */
31
45
  export interface WatchedSocket {
32
46
  on(event: 'connect_error' | 'disconnect', listener: (reason?: unknown) => void): unknown;
@@ -20,6 +20,16 @@
20
20
  * reloads. The edge answers that load with its sign-in wall, which gives a signed-out visitor an
21
21
  * account and sends them on. A second loss within {@link RELOAD_GUARD_MS} of one this tab already
22
22
  * reloaded for does not reload again: the page stays stopped rather than loop.
23
+ *
24
+ * A session the page changes ITSELF is not a lost one. Delete account, a sign-in with a key or a
25
+ * passkey: each is a write to the fleet's session service ({@link SESSION_SERVICE_PATHS}) that ends
26
+ * or replaces this browser's session, and the page goes somewhere of its own choosing once it
27
+ * answers. Until then the edge refuses everything under `scope`, and a reload would cut the write
28
+ * off and send the browser through the wall as a new guest (2026-11-27, Delete account on
29
+ * cardtable-ppe). So the same `fetch` wrapper watches for those writes (any caller's: the fleet
30
+ * header posts them with the page's own `fetch`), and while one is in flight, and for
31
+ * {@link SESSION_WRITE_HOLD_MS} after one succeeds, no suspicion is probed and no probe's 401
32
+ * stops the page. A write that fails holds nothing past its answer.
23
33
  */
24
34
  /** The least time between two probes. */
25
35
  export const PROBE_GAP_MS = 10_000;
@@ -27,6 +37,10 @@ export const PROBE_GAP_MS = 10_000;
27
37
  export const RELOAD_GUARD_MS = 60_000;
28
38
  /** Where this tab notes when it last reloaded for a lost session. */
29
39
  export const RELOADED_KEY = 'hadoku:session-lost-reload';
40
+ /** The fleet's session service on the page's origin: a write under one of these changes who this browser is. */
41
+ export const SESSION_SERVICE_PATHS = ['/session/', '/auth/'];
42
+ /** How long after a session write succeeds the page is left to its own navigation. */
43
+ export const SESSION_WRITE_HOLD_MS = PROBE_GAP_MS;
30
44
  /** socket.io's reason when the page itself closed a socket: the watch lets go of it. */
31
45
  const CLOSED_BY_PAGE = 'io client disconnect';
32
46
  let current = null;
@@ -44,6 +58,9 @@ function urlOf(input) {
44
58
  return input.href;
45
59
  return input.url;
46
60
  }
61
+ function methodOf(input, init) {
62
+ return (init?.method ?? (typeof input === 'object' && 'method' in input ? input.method : 'GET')).toUpperCase();
63
+ }
47
64
  /** Start the page's one watch. A second start replaces the first. */
48
65
  export function startSessionWatch(options) {
49
66
  current?.stop();
@@ -64,13 +81,38 @@ export function startSessionWatch(options) {
64
81
  let isLost = false;
65
82
  let probing = false;
66
83
  let lastProbe = -Infinity;
67
- const inScope = (input) => {
84
+ /** Session writes in flight, and when the last one that succeeded stops holding the watch. */
85
+ let sessionWrites = 0;
86
+ let heldUntil = -Infinity;
87
+ const held = () => sessionWrites > 0 || now() < heldUntil;
88
+ const pathOf = (input) => {
68
89
  try {
69
90
  const url = new URL(urlOf(input), host.location.origin);
70
- return url.origin === scopeUrl.origin && url.pathname.startsWith(scopeUrl.pathname);
91
+ return url.origin === scopeUrl.origin ? url.pathname : null;
71
92
  }
72
93
  catch {
94
+ return null;
95
+ }
96
+ };
97
+ const inScope = (input) => pathOf(input)?.startsWith(scopeUrl.pathname) ?? false;
98
+ const isSessionWrite = (input, init) => {
99
+ const method = methodOf(input, init);
100
+ if (method === 'GET' || method === 'HEAD')
73
101
  return false;
102
+ const path = pathOf(input);
103
+ return path !== null && SESSION_SERVICE_PATHS.some((prefix) => path.startsWith(prefix));
104
+ };
105
+ /** The page's own write to its session: held while it is in flight, and a while after it succeeds. */
106
+ const sessionWrite = async (input, init) => {
107
+ sessionWrites += 1;
108
+ try {
109
+ const res = await pageFetch.call(undefined, input, init);
110
+ if (res.ok)
111
+ heldUntil = now() + SESSION_WRITE_HOLD_MS;
112
+ return res;
113
+ }
114
+ finally {
115
+ sessionWrites -= 1;
74
116
  }
75
117
  };
76
118
  /** When this tab last reloaded for a lost session, noting now as the next one's answer. */
@@ -93,7 +135,7 @@ export function startSessionWatch(options) {
93
135
  host.location.reload();
94
136
  };
95
137
  const lose = () => {
96
- if (isLost)
138
+ if (isLost || held())
97
139
  return;
98
140
  isLost = true;
99
141
  for (const socket of [...sockets.keys()]) {
@@ -119,11 +161,13 @@ export function startSessionWatch(options) {
119
161
  }
120
162
  };
121
163
  const suspect = () => {
122
- if (isLost || probing || now() - lastProbe < PROBE_GAP_MS)
164
+ if (isLost || probing || held() || now() - lastProbe < PROBE_GAP_MS)
123
165
  return;
124
166
  void probe();
125
167
  };
126
168
  const watched = async (input, init) => {
169
+ if (isSessionWrite(input, init))
170
+ return sessionWrite(input, init);
127
171
  if (!inScope(input))
128
172
  return pageFetch.call(undefined, input, init);
129
173
  if (isLost)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/ui-shell",
3
- "version": "0.1.144",
4
- "gitHead": "4410ed2bbf9358e331fa512e5f751be5bd378a0d",
3
+ "version": "0.1.146",
4
+ "gitHead": "f801fb0993e84eaed7c4472993a11b21276052c1",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "description": "The parts of a game's UI any game keeps: chrome, trim, room shell, embed mount, theme and settings frame, UI scale, usage counting, the sound mixer, motion and generic components. One appId parameterizes its storage keys, events and chat prefix. MIT; imports only react, react-dom, platform-wire and @wolffm/*.",
@@ -68,7 +68,7 @@
68
68
  "react-dom": "^19.2.8"
69
69
  },
70
70
  "dependencies": {
71
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.144",
71
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.146",
72
72
  "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.2",
73
73
  "@wolffm/themes": "npm:@hadoku/themes@^5.14.19",
74
74
  "zod": "4.5.4"