akanjs 3.3.0-rc.60 → 3.3.0-rc.62

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.
@@ -3,6 +3,8 @@ import { useSyncExternalStore } from "react";
3
3
 
4
4
  export interface PendingNavigationEntry {
5
5
  href: string;
6
+
7
+ waits: boolean;
6
8
  }
7
9
 
8
10
  interface PendingNavigationStore {
@@ -28,11 +30,17 @@ export class PendingNavigation {
28
30
  }
29
31
 
30
32
  static begin(href: string): PendingNavigationEntry {
31
- const entry = { href };
33
+ const entry = { href, waits: false };
32
34
  PendingNavigation.#set(entry);
33
35
  return entry;
34
36
  }
35
37
 
38
+ static wait(entry: PendingNavigationEntry) {
39
+ if (entry.waits || PendingNavigation.#store().entry !== entry) return;
40
+ entry.waits = true;
41
+ PendingNavigation.#set(entry);
42
+ }
43
+
36
44
  static end(entry: PendingNavigationEntry) {
37
45
  if (PendingNavigation.#store().entry === entry) PendingNavigation.#set(null);
38
46
  }
@@ -42,6 +50,11 @@ export class PendingNavigation {
42
50
  }
43
51
 
44
52
  static get(): string | null {
53
+ const { entry } = PendingNavigation.#store();
54
+ return entry?.waits ? entry.href : null;
55
+ }
56
+
57
+ static target(): string | null {
45
58
  return PendingNavigation.#store().entry?.href ?? null;
46
59
  }
47
60
 
@@ -16,7 +16,7 @@ export interface PendingLocation {
16
16
  searchParams: Record<string, string | string[]>;
17
17
  }
18
18
 
19
- /** The location a navigation is loading, from the press until its page is drawn; `null` with none in flight. */
19
+ /** The location a navigation is loading from the server, from the press until its page is drawn; else `null`. */
20
20
  export const usePendingNavigation = (): PendingLocation | null => {
21
21
  const pending = PendingNavigation.use((href) => href);
22
22
  const { lang } = usePage();
package/index.ts CHANGED
@@ -23,6 +23,11 @@ export interface DockerImageConfig {
23
23
  * for another architecture then never runs Bun emulated. A dependency's lifecycle script runs on the build machine.
24
24
  */
25
25
  crossBuild: boolean;
26
+ /**
27
+ * False when `image` was built with the base step already run (`DOCKER_BASE_RUNS` in `@akanjs/devkit/akanConfig`),
28
+ * so a builder with no layer cache does not repeat `apt-get` on every build.
29
+ */
30
+ baseSetup: boolean;
26
31
  /**
27
32
  * `ENV` lines laid over the build's own, as the image's defaults. The config is tracked and the image shows them,
28
33
  * so never a secret.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akanjs",
3
- "version": "3.3.0-rc.60",
3
+ "version": "3.3.0-rc.62",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -592,8 +592,10 @@ function installNavigate(
592
592
  commitRscPatchNavigation({ target, patch, fromCache, replace: options.replace, requestScroll });
593
593
  if (caches.replayPatch(target, navId, (patch) => commitPatch(patch, true))) return;
594
594
  const taken = caches.takePrefetch(target, signal);
595
+ if (!taken?.arrived) PendingNavigation.wait(pending);
595
596
  const prefetched = (await taken?.response) ?? undefined;
596
597
  if (signal.aborted) return;
598
+ if (!prefetched) PendingNavigation.wait(pending);
597
599
  servedFromCache = !!prefetched && !taken?.fresh;
598
600
  const fetched = await fetchRsc(target, {
599
601
  replaceOnRedirect,
@@ -611,6 +613,7 @@ function installNavigate(
611
613
  return;
612
614
  }
613
615
  caches.forgetPatch(target);
616
+ PendingNavigation.wait(pending);
614
617
  const fallback = await fetchRsc(target, {
615
618
  replaceOnRedirect,
616
619
  sendRouterState: false,
@@ -6,6 +6,7 @@ interface RscPrefetchEntry<B> {
6
6
  whole: boolean;
7
7
  optedOut: boolean;
8
8
  startedAt: number;
9
+ arrived: boolean;
9
10
  controller: AbortController;
10
11
  response: Promise<Response | null>;
11
12
  release: () => void;
@@ -19,6 +20,8 @@ interface RscPrefetchQueued {
19
20
  export interface RscPrefetched {
20
21
  response: Promise<Response | null>;
21
22
  fresh: boolean;
23
+
24
+ arrived: boolean;
22
25
  }
23
26
 
24
27
  export interface RscPrefetchCacheOptions<B = undefined> {
@@ -120,7 +123,11 @@ export class RscPrefetchCache<B = undefined> {
120
123
  return null;
121
124
  }
122
125
  signal?.addEventListener("abort", () => entry.controller.abort(), { once: true });
123
- return { response: entry.response, fresh: this.#now() - entry.startedAt <= this.#freshMs };
126
+ return {
127
+ response: entry.response,
128
+ fresh: this.#now() - entry.startedAt <= this.#freshMs,
129
+ arrived: entry.arrived,
130
+ };
124
131
  }
125
132
 
126
133
  prune(): void {
@@ -181,6 +188,7 @@ export class RscPrefetchCache<B = undefined> {
181
188
  whole: false,
182
189
  optedOut: false,
183
190
  startedAt: this.#now(),
191
+ arrived: false,
184
192
  controller,
185
193
  response: this.#fetchResponse(href, controller.signal).then(
186
194
  (response) => {
@@ -199,10 +207,16 @@ export class RscPrefetchCache<B = undefined> {
199
207
 
200
208
  const [drain, branch] = response.body.tee();
201
209
  kept = branch;
202
- void RscPrefetchCache.#readToEnd(drain, controller.signal).then(settle, () => {
203
- forget();
204
- settle();
205
- });
210
+ void RscPrefetchCache.#readToEnd(drain, controller.signal).then(
211
+ () => {
212
+ entry.arrived = true;
213
+ settle();
214
+ },
215
+ () => {
216
+ forget();
217
+ settle();
218
+ },
219
+ );
206
220
  return new Response(branch, {
207
221
  status: response.status,
208
222
  statusText: response.statusText,
@@ -1,5 +1,6 @@
1
1
  export interface PendingNavigationEntry {
2
2
  href: string;
3
+ waits: boolean;
3
4
  }
4
5
  interface PendingNavigationStore {
5
6
  entry: PendingNavigationEntry | null;
@@ -11,9 +12,11 @@ declare global {
11
12
  export declare class PendingNavigation {
12
13
  #private;
13
14
  static begin(href: string): PendingNavigationEntry;
15
+ static wait(entry: PendingNavigationEntry): void;
14
16
  static end(entry: PendingNavigationEntry): void;
15
17
  static clear(): void;
16
18
  static get(): string | null;
19
+ static target(): string | null;
17
20
  static subscribe(listener: () => void): () => void;
18
21
  static use<Value extends string | boolean | null>(select: (href: string | null) => Value): Value;
19
22
  }
@@ -6,5 +6,5 @@ export interface PendingLocation {
6
6
  path: string;
7
7
  searchParams: Record<string, string | string[]>;
8
8
  }
9
- /** The location a navigation is loading, from the press until its page is drawn; `null` with none in flight. */
9
+ /** The location a navigation is loading from the server, from the press until its page is drawn; else `null`. */
10
10
  export declare const usePendingNavigation: () => PendingLocation | null;
package/types/index.d.ts CHANGED
@@ -24,6 +24,11 @@ export interface DockerImageConfig {
24
24
  * for another architecture then never runs Bun emulated. A dependency's lifecycle script runs on the build machine.
25
25
  */
26
26
  crossBuild: boolean;
27
+ /**
28
+ * False when `image` was built with the base step already run (`DOCKER_BASE_RUNS` in `@akanjs/devkit/akanConfig`),
29
+ * so a builder with no layer cache does not repeat `apt-get` on every build.
30
+ */
31
+ baseSetup: boolean;
27
32
  /**
28
33
  * `ENV` lines laid over the build's own, as the image's defaults. The config is tracked and the image shows them,
29
34
  * so never a secret.
@@ -2,6 +2,7 @@ import type { PrefetchPriority } from "../client/rscNavigation.d.ts";
2
2
  export interface RscPrefetched {
3
3
  response: Promise<Response | null>;
4
4
  fresh: boolean;
5
+ arrived: boolean;
5
6
  }
6
7
  export interface RscPrefetchCacheOptions<B = undefined> {
7
8
  fetchResponse: (href: string, signal: AbortSignal) => Promise<Response>;
@@ -12,7 +12,7 @@ export type CommonLinkProps = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "hre
12
12
  activeExact?: boolean;
13
13
  /** More paths under which the link counts as active, as a tab does for its detail pages. */
14
14
  activeMatch?: string[];
15
- /** Applied, with `data-pending`, while a page this link would be active on is still loading. */
15
+ /** Applied, with `data-pending`, while a page this link would be active on loads from the server. */
16
16
  pendingClassName?: string;
17
17
  /** @deprecated Has no effect: neither renderer reads it. */
18
18
  noCache?: boolean;
@@ -29,7 +29,7 @@ export type CommonLinkProps = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "hre
29
29
  activeExact?: boolean;
30
30
  /** More paths under which the link counts as active, as a tab does for its detail pages. */
31
31
  activeMatch?: string[];
32
- /** Applied, with `data-pending`, while a page this link would be active on is still loading. */
32
+ /** Applied, with `data-pending`, while a page this link would be active on loads from the server. */
33
33
  pendingClassName?: string;
34
34
  /** @deprecated Has no effect: neither renderer reads it. */
35
35
  noCache?: boolean;
@@ -434,7 +434,7 @@ export const ClientSsrBridge = ({ lang, prefix = "", initialPageState }: ClientS
434
434
  };
435
435
 
436
436
  const followPending = PendingNavigation.subscribe(() => {
437
- const pending = PendingNavigation.get();
437
+ const pending = PendingNavigation.target();
438
438
  if (!pending) return;
439
439
  const { pathname, search } = new URL(pending);
440
440
  const shown = ShellState.get();