akanjs 3.3.0-rc.58 → 3.3.0-rc.59

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/index.ts CHANGED
@@ -260,5 +260,6 @@ export {
260
260
  type RootLayoutProps,
261
261
  type UserMenuItem,
262
262
  } from "./types";
263
+ export { type PendingLocation, usePendingNavigation } from "./usePendingNavigation";
263
264
  export { type ThemeColorTag, ViewportMeta } from "./viewportMeta";
264
265
  export { getWebManifestBasePath, toManifestJson, webManifestHref } from "./webManifest";
@@ -0,0 +1,63 @@
1
+ "use client";
2
+ import { useSyncExternalStore } from "react";
3
+
4
+ export interface PendingNavigationEntry {
5
+ href: string;
6
+ }
7
+
8
+ interface PendingNavigationStore {
9
+ entry: PendingNavigationEntry | null;
10
+ listeners: Set<() => void>;
11
+ }
12
+
13
+ declare global {
14
+ var __AKAN_PENDING_NAVIGATION__: PendingNavigationStore | undefined;
15
+ }
16
+
17
+ export class PendingNavigation {
18
+
19
+ static #store(): PendingNavigationStore {
20
+ globalThis.__AKAN_PENDING_NAVIGATION__ ??= { entry: null, listeners: new Set() };
21
+ return globalThis.__AKAN_PENDING_NAVIGATION__;
22
+ }
23
+
24
+ static #set(entry: PendingNavigationEntry | null) {
25
+ const store = PendingNavigation.#store();
26
+ store.entry = entry;
27
+ for (const listener of [...store.listeners]) listener();
28
+ }
29
+
30
+ static begin(href: string): PendingNavigationEntry {
31
+ const entry = { href };
32
+ PendingNavigation.#set(entry);
33
+ return entry;
34
+ }
35
+
36
+ static end(entry: PendingNavigationEntry) {
37
+ if (PendingNavigation.#store().entry === entry) PendingNavigation.#set(null);
38
+ }
39
+
40
+ static clear() {
41
+ if (PendingNavigation.#store().entry) PendingNavigation.#set(null);
42
+ }
43
+
44
+ static get(): string | null {
45
+ return PendingNavigation.#store().entry?.href ?? null;
46
+ }
47
+
48
+ static subscribe(listener: () => void) {
49
+ const { listeners } = PendingNavigation.#store();
50
+ listeners.add(listener);
51
+ return () => {
52
+ listeners.delete(listener);
53
+ };
54
+ }
55
+
56
+ static use<Value extends string | boolean | null>(select: (href: string | null) => Value): Value {
57
+ return useSyncExternalStore(
58
+ PendingNavigation.subscribe,
59
+ () => select(PendingNavigation.get()),
60
+ () => select(null),
61
+ );
62
+ }
63
+ }
@@ -0,0 +1,36 @@
1
+ "use client";
2
+ import { getEnv } from "akanjs/base";
3
+ import { parseSearchParams } from "akanjs/common";
4
+ import { useMemo } from "react";
5
+ import { usePage } from "./clientRuntime";
6
+ import { usePathCtx } from "./csrTypes";
7
+ import { PendingNavigation } from "./pendingNavigation";
8
+ import { getPathInfo } from "./router";
9
+
10
+ export interface PendingLocation {
11
+ /** Path, query and fragment, as `router.push` takes them. */
12
+ href: string;
13
+ pathname: string;
14
+ /** Without the locale and the basePath, comparable with `usePage().path`. */
15
+ path: string;
16
+ searchParams: Record<string, string | string[]>;
17
+ }
18
+
19
+ /** The location a navigation is loading, from the press until its page is drawn; `null` with none in flight. */
20
+ export const usePendingNavigation = (): PendingLocation | null => {
21
+ const pending = PendingNavigation.use((href) => href);
22
+ const { lang } = usePage();
23
+ const prefix = usePathCtx().prefix ?? "";
24
+ return useMemo(() => {
25
+ if (!pending) return null;
26
+ const url = new URL(pending);
27
+ const href = `${url.pathname}${url.search}${url.hash}`;
28
+ const visiblePrefix = getEnv().operationMode === "local" ? prefix : "";
29
+ return {
30
+ href,
31
+ pathname: url.pathname,
32
+ path: getPathInfo(href, lang, visiblePrefix).path,
33
+ searchParams: parseSearchParams(url.search),
34
+ };
35
+ }, [pending, lang, prefix]);
36
+ };
package/index.ts CHANGED
@@ -23,12 +23,23 @@ 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
+ * `ENV` lines laid over the build's own, as the image's defaults. The config is tracked and the image shows them,
28
+ * so never a secret.
29
+ */
30
+ env: Record<string, string>;
26
31
  }
27
32
 
28
33
  /** The string form is taken verbatim: nothing is merged into it, not even a lib's `docker` steps. */
29
34
  export type DockerConfig = string | DockerImageConfig;
30
35
 
31
- export type DockerOption = string | Partial<DockerImageConfig>;
36
+ /**
37
+ * The app's `docker` with the fields it names replaced and its `env` laid over the app's key by key, written beside
38
+ * the Dockerfile as `Dockerfile.<name>`.
39
+ */
40
+ export type DockerVariantOption = Partial<DockerImageConfig>;
41
+
42
+ export type DockerOption = string | (Partial<DockerImageConfig> & { variants?: Record<string, DockerVariantOption> });
32
43
 
33
44
  /** Steps every app mounting the lib inherits; a lib never picks the base image or the command. */
34
45
  export interface LibDockerConfig {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akanjs",
3
- "version": "3.3.0-rc.58",
3
+ "version": "3.3.0-rc.59",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -5,6 +5,7 @@ import { AkanError } from "../base/akanError";
5
5
  import { csrLocation } from "../client/csrLocation";
6
6
  import { DictionaryAsset } from "../client/dictionaryAsset";
7
7
  import { DictionaryGroups } from "../client/dictionaryGroups";
8
+ import { PendingNavigation, type PendingNavigationEntry } from "../client/pendingNavigation";
8
9
  import type {} from "../client/rscNavigation";
9
10
  import {
10
11
  type FlightLineRowHandler,
@@ -122,7 +123,9 @@ function createRscThenable(rows: FlightRowPass, ...onLineRows: FlightLineRowHand
122
123
  }
123
124
 
124
125
  window.addEventListener("pageshow", (event) => {
125
- if (event.persisted) documentNavigationFallbackInFlight = false;
126
+ if (!event.persisted) return;
127
+ documentNavigationFallbackInFlight = false;
128
+ PendingNavigation.clear();
126
129
  });
127
130
 
128
131
  function hardNavigateAfterRscFailure(target: string, replace = false, error?: unknown): void {
@@ -446,10 +449,25 @@ function forgetPagesOfAnotherAccount(): void {
446
449
 
447
450
  globalThis.__AKAN_RSC_PREFETCH__ = (href, priority) => caches.prefetch(href, priority);
448
451
 
452
+ let drawnThenable: RscThenable = initialThenable;
453
+ let awaitedDraw: { pending: PendingNavigationEntry; thenable: RscThenable } | null = null;
454
+
455
+ function endPendingOnceDrawn(pending: PendingNavigationEntry, thenable: RscThenable): void {
456
+ if (thenable === drawnThenable) PendingNavigation.end(pending);
457
+ else awaitedDraw = { pending, thenable };
458
+ }
459
+
449
460
  function Root(): ReactNode {
450
461
  const [thenable, setThenable] = useState<RscThenable>(initialThenable);
451
462
  const [scrollRequest, setScrollRequest] = useState<ScrollRequest | null>(null);
452
463
 
464
+ useLayoutEffect(() => {
465
+ drawnThenable = thenable;
466
+ if (awaitedDraw?.thenable !== thenable) return;
467
+ PendingNavigation.end(awaitedDraw.pending);
468
+ awaitedDraw = null;
469
+ }, [thenable]);
470
+
453
471
  useLayoutEffect(() => {
454
472
  if (scrollRequest?.hash) scrollRestoration.scrollToHash(scrollRequest.hash, scrollRequest.scrollY);
455
473
  else if (scrollRequest) scrollRestoration.scrollTo(scrollRequest.scrollY);
@@ -555,6 +573,9 @@ function installNavigate(
555
573
  const navId = supersedeForPageNavigation();
556
574
  const target = normalizeHref(href);
557
575
  const signal = requestSignalOf(navId, target);
576
+ const pending = PendingNavigation.begin(target);
577
+
578
+ let endsPending = true;
558
579
 
559
580
  let ownsEntry = !!options.replace;
560
581
  const replaceOnRedirect = () => ownsEntry;
@@ -630,6 +651,8 @@ function installNavigate(
630
651
  currentCommitFromCache = servedFromCache;
631
652
  resetAkanSegmentOutletPatches();
632
653
  setThenable(node.thenable);
654
+ endsPending = false;
655
+ endPendingOnceDrawn(pending, node.thenable);
633
656
  },
634
657
  updateHistory: () => {
635
658
  commitHistory(target, options.replace);
@@ -646,9 +669,12 @@ function installNavigate(
646
669
  if (error instanceof RscRedirectNavigationStarted) return;
647
670
 
648
671
  if (error instanceof RscRouteNotFound) throw error;
649
- if (navId === navigationSeq) hardNavigateAfterRscFailure(target, options.replace, error);
672
+ if (navId !== navigationSeq) return;
673
+ endsPending = false;
674
+ hardNavigateAfterRscFailure(target, options.replace, error);
650
675
  } finally {
651
676
  settleRequestOf(navId);
677
+ if (endsPending) PendingNavigation.end(pending);
652
678
  }
653
679
  };
654
680
  }
@@ -23,5 +23,6 @@ export { secretStorage, storage } from "./storage.d.ts";
23
23
  export { type TransitionType, transitionTypes } from "./transitionTypes.d.ts";
24
24
  export { type AllDictionary, type Dictionary, Translator } from "./translator.d.ts";
25
25
  export { type DataAction, type DataColumn, type DataMenu, type DataMenuItem, type DataTool, type Font, getFontFaces, getFontFallbackName, getFontStyles, getFontVariableName, getOptimizedFontSrc, isFontOptimizationEnabled, isFontPreloadEnabled, loadFonts, type MenuItem, type ModelDashboardProps, type ModelEditProps, type ModelInsightProps, type ModelProps, type ModelsProps, type ModelViewProps, type ReactFont, type ReactFontCategory, type ReactFontDeclaration, type ReactFontDisplay, type ReactFontFace, type ReactFontPath, type ReactFontStyle, type ReactFontSubset, type RootLayoutProps, type UserMenuItem, } from "./types.d.ts";
26
+ export { type PendingLocation, usePendingNavigation } from "./usePendingNavigation.d.ts";
26
27
  export { type ThemeColorTag, ViewportMeta } from "./viewportMeta.d.ts";
27
28
  export { getWebManifestBasePath, toManifestJson, webManifestHref } from "./webManifest.d.ts";
@@ -0,0 +1,20 @@
1
+ export interface PendingNavigationEntry {
2
+ href: string;
3
+ }
4
+ interface PendingNavigationStore {
5
+ entry: PendingNavigationEntry | null;
6
+ listeners: Set<() => void>;
7
+ }
8
+ declare global {
9
+ var __AKAN_PENDING_NAVIGATION__: PendingNavigationStore | undefined;
10
+ }
11
+ export declare class PendingNavigation {
12
+ #private;
13
+ static begin(href: string): PendingNavigationEntry;
14
+ static end(entry: PendingNavigationEntry): void;
15
+ static clear(): void;
16
+ static get(): string | null;
17
+ static subscribe(listener: () => void): () => void;
18
+ static use<Value extends string | boolean | null>(select: (href: string | null) => Value): Value;
19
+ }
20
+ export {};
@@ -0,0 +1,10 @@
1
+ export interface PendingLocation {
2
+ /** Path, query and fragment, as `router.push` takes them. */
3
+ href: string;
4
+ pathname: string;
5
+ /** Without the locale and the basePath, comparable with `usePage().path`. */
6
+ path: string;
7
+ searchParams: Record<string, string | string[]>;
8
+ }
9
+ /** The location a navigation is loading, from the press until its page is drawn; `null` with none in flight. */
10
+ export declare const usePendingNavigation: () => PendingLocation | null;
package/types/index.d.ts CHANGED
@@ -24,10 +24,22 @@ 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
+ * `ENV` lines laid over the build's own, as the image's defaults. The config is tracked and the image shows them,
29
+ * so never a secret.
30
+ */
31
+ env: Record<string, string>;
27
32
  }
28
33
  /** The string form is taken verbatim: nothing is merged into it, not even a lib's `docker` steps. */
29
34
  export type DockerConfig = string | DockerImageConfig;
30
- export type DockerOption = string | Partial<DockerImageConfig>;
35
+ /**
36
+ * The app's `docker` with the fields it names replaced and its `env` laid over the app's key by key, written beside
37
+ * the Dockerfile as `Dockerfile.<name>`.
38
+ */
39
+ export type DockerVariantOption = Partial<DockerImageConfig>;
40
+ export type DockerOption = string | (Partial<DockerImageConfig> & {
41
+ variants?: Record<string, DockerVariantOption>;
42
+ });
31
43
  /** Steps every app mounting the lib inherits; a lib never picks the base image or the command. */
32
44
  export interface LibDockerConfig {
33
45
  preRuns: DockerRun[];
@@ -12,6 +12,8 @@ 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. */
16
+ pendingClassName?: string;
15
17
  /** @deprecated Has no effect: neither renderer reads it. */
16
18
  noCache?: boolean;
17
19
  /** `"hover"` (the default, or `true`) loads the page on hover or keyboard focus, `"viewport"` also once it shows. */
@@ -20,6 +22,6 @@ export type CommonLinkProps = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "hre
20
22
  type AnchorProps = Omit<CommonLinkProps, "href" | "disabled"> & {
21
23
  href: string;
22
24
  };
23
- export declare const CsrLink: ({ className, children, href, replace, activeClassName, scrollToTop, activeExact, activeMatch, noCache, prefetch, ...props }: AnchorProps) => import("react").JSX.Element;
24
- export declare const SsrLink: ({ className, children, href, scrollToTop, replace, activeClassName, activeExact, activeMatch, noCache, prefetch, ...props }: AnchorProps) => import("react").JSX.Element;
25
+ export declare const CsrLink: ({ className, children, href, replace, activeClassName, scrollToTop, activeExact, activeMatch, pendingClassName, noCache, prefetch, ...props }: AnchorProps) => import("react").JSX.Element;
26
+ export declare const SsrLink: ({ className, children, href, scrollToTop, replace, activeClassName, activeExact, activeMatch, pendingClassName, noCache, prefetch, ...props }: AnchorProps) => import("react").JSX.Element;
25
27
  export {};
@@ -13,6 +13,7 @@ import {
13
13
  } from "akanjs/client";
14
14
  import { Logger } from "akanjs/common";
15
15
  import type { AnchorHTMLAttributes } from "react";
16
+ import { PendingNavigation } from "../../client/pendingNavigation";
16
17
  import { isActiveHref, useCurrentPathname } from "./activePath";
17
18
  import { type LinkPrefetch, usePrefetchIntent } from "./prefetchIntent";
18
19
 
@@ -28,6 +29,8 @@ export type CommonLinkProps = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "hre
28
29
  activeExact?: boolean;
29
30
  /** More paths under which the link counts as active, as a tab does for its detail pages. */
30
31
  activeMatch?: string[];
32
+ /** Applied, with `data-pending`, while a page this link would be active on is still loading. */
33
+ pendingClassName?: string;
31
34
  /** @deprecated Has no effect: neither renderer reads it. */
32
35
  noCache?: boolean;
33
36
  /** `"hover"` (the default, or `true`) loads the page on hover or keyboard focus, `"viewport"` also once it shows. */
@@ -44,6 +47,7 @@ export const CsrLink = ({
44
47
  scrollToTop,
45
48
  activeExact,
46
49
  activeMatch,
50
+ pendingClassName,
47
51
  noCache,
48
52
  prefetch,
49
53
  ...props
@@ -88,6 +92,7 @@ export const SsrLink = ({
88
92
  activeClassName,
89
93
  activeExact,
90
94
  activeMatch,
95
+ pendingClassName,
91
96
  noCache,
92
97
  prefetch = "hover",
93
98
  ...props
@@ -98,6 +103,20 @@ export const SsrLink = ({
98
103
  const prefetchIntent = usePrefetchIntent(href, prefetch, props);
99
104
  const currentPath = getPathInfo(pathname, lang, prefix).path;
100
105
  const isExternal = Href.isExternal(href);
106
+ const pending = PendingNavigation.use(
107
+ (pendingHref) =>
108
+ !!pendingHref &&
109
+ !isExternal &&
110
+ !href.startsWith("#") &&
111
+ isActiveHref({
112
+ pathname: new URL(pendingHref).pathname,
113
+ href,
114
+ lang,
115
+ prefix,
116
+ exact: activeExact,
117
+ match: activeMatch,
118
+ }),
119
+ );
101
120
  const internalPathInfo = getPathInfo(href, lang, prefix);
102
121
  const requestHref = getEnv().operationMode === "local" ? internalPathInfo.href : getPathInfo(href, lang, "").href;
103
122
  const path = internalPathInfo.path;
@@ -114,8 +133,10 @@ export const SsrLink = ({
114
133
  !!activeClassName &&
115
134
  isActiveHref({ pathname, href, lang, prefix, exact: activeExact, match: activeMatch }) &&
116
135
  activeClassName,
136
+ pending && pendingClassName,
117
137
  )}
118
138
  href={isExternal ? href : requestHref}
139
+ data-pending={pending ? "" : undefined}
119
140
  {...props}
120
141
  {...prefetchIntent}
121
142
  onClick={(event) => {
package/ui/Link/index.tsx CHANGED
@@ -6,7 +6,17 @@ import { type CommonLinkProps, CsrLink, SsrLink } from "./Anchor";
6
6
 
7
7
  export const Link = ({ className, href, disabled = false, children, ...props }: CommonLinkProps) => {
8
8
  if (disabled || !href) {
9
- const { scrollToTop, replace, activeClassName, activeExact, activeMatch, noCache, prefetch, ...divProps } = props;
9
+ const {
10
+ scrollToTop,
11
+ replace,
12
+ activeClassName,
13
+ activeExact,
14
+ activeMatch,
15
+ pendingClassName,
16
+ noCache,
17
+ prefetch,
18
+ ...divProps
19
+ } = props;
10
20
  return (
11
21
  <div className={className} {...(divProps as unknown as HTMLAttributes<HTMLDivElement>)}>
12
22
  {children}
@@ -50,6 +50,7 @@ import {
50
50
  useState,
51
51
  } from "react";
52
52
  import { NativeThemeColor } from "../../client/nativeThemeColor";
53
+ import { PendingNavigation } from "../../client/pendingNavigation";
53
54
  import { readRscRoutePatch, subscribeRscRoutePatch } from "../../client/rscRoutePatch";
54
55
  import { CsrSlide } from "../../webkit/csrSlide";
55
56
  import { FrameRootVars } from "../../webkit/FrameRootVars";
@@ -431,6 +432,15 @@ export const ClientSsrBridge = ({ lang, prefix = "", initialPageState }: ClientS
431
432
  ...(initialPageState ? { pageState: initialPageState } : {}),
432
433
  });
433
434
  };
435
+
436
+ const followPending = PendingNavigation.subscribe(() => {
437
+ const pending = PendingNavigation.get();
438
+ if (!pending) return;
439
+ const { pathname, search } = new URL(pending);
440
+ const shown = ShellState.get();
441
+ const sameSearch = JSON.stringify(parseSearchParams(search)) === JSON.stringify(shown.searchParams);
442
+ if (pathname !== shown.pathname || !sameSearch) syncHref(pending);
443
+ });
434
444
  router.init({
435
445
  type: "ssr",
436
446
  side: "client",
@@ -459,6 +469,7 @@ export const ClientSsrBridge = ({ lang, prefix = "", initialPageState }: ClientS
459
469
  });
460
470
  void Device.load({ lang });
461
471
  return () => {
472
+ followPending();
462
473
  if (globalThis.__AKAN_GET_SYNC_ROUTE_HREF__) globalThis.__AKAN_GET_SYNC_ROUTE_HREF__ = undefined;
463
474
  };
464
475
  }, [lang, prefix, initialPageState]);