akanjs 3.3.0-rc.54 → 3.3.0-rc.55

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.
@@ -10,6 +10,8 @@ export class CsrLocation {
10
10
  #view: URL | null = null;
11
11
  #entry: { idx: number | undefined; href: string; from: string | undefined } | null = null;
12
12
  #onBack: ((idx: number) => void) | null = null;
13
+ #backAsked: object | null = null;
14
+ #backSent: object | null = null;
13
15
 
14
16
  /** Reads `href`, a path on the app's origin, as this document's location from now on; a view never moves. */
15
17
  view(href: string) {
@@ -99,9 +101,27 @@ export class CsrLocation {
99
101
  this.#onBack = listener;
100
102
  }
101
103
 
104
+ /** Holds the entry on screen as left until `moving`, a shell's back, settles; `back()` holds it until the pop lands. */
105
+ leaving(moving: unknown) {
106
+ const entry = this.entry();
107
+ this.#backAsked = entry;
108
+ const release = () => {
109
+ if (this.#backAsked === entry) this.#backAsked = null;
110
+ };
111
+ void Promise.resolve(moving).then(release, release);
112
+ }
113
+
114
+ /** Whether a back has left the entry on screen and not landed yet. */
115
+ isLeaving() {
116
+ const entry = this.entry();
117
+ return entry === this.#backAsked || entry === this.#backSent;
118
+ }
119
+
102
120
  back() {
103
- const idx = this.entry().idx;
104
- if (idx !== undefined) this.#onBack?.(idx - 1);
121
+ const entry = this.entry();
122
+ if (entry.idx !== undefined) this.#onBack?.(entry.idx - 1);
123
+
124
+ if (entry.idx !== undefined && entry.idx > 0) this.#backSent = entry;
105
125
  window.history.back();
106
126
  }
107
127
 
package/client/router.ts CHANGED
@@ -287,7 +287,7 @@ class Router {
287
287
  prefetch: (href, priority) => options.router.prefetch?.(this.#getNavigationPathInfo(href).href, priority),
288
288
  back: () => {
289
289
  this.#postPathAfterBack();
290
- options.router.back();
290
+ return options.router.back();
291
291
  },
292
292
  refresh: () => {
293
293
  const router = options.router;
@@ -315,7 +315,7 @@ class Router {
315
315
  },
316
316
  back: (routeOptions) => {
317
317
  this.#postPathAfterBack();
318
- options.router.back(routeOptions);
318
+ return options.router.back(routeOptions);
319
319
  },
320
320
  refresh: () => {
321
321
  const { path, pathname, hash } = this.#getPathInfo(csrLocation.pathname);
@@ -654,11 +654,17 @@ class Router {
654
654
  backTo(href: string, routeOptions?: RouteOptions) {
655
655
  if (getEnv().side === "server") throw new Error("backTo is only available in client side");
656
656
  this.#checkInitialized();
657
+
658
+ if (csrLocation.isLeaving()) return undefined as never;
657
659
  const { from } = csrLocation.entry();
660
+ const target = this.#getPathInfo(href);
661
+
662
+ const under =
663
+ from === undefined ? null : { ...this.#getVisiblePathInfo(from), ...(target.hash ? {} : { hash: "" }) };
658
664
  const isUnder =
659
- from !== undefined &&
665
+ under !== null &&
660
666
  this.canGoBack() &&
661
- CsrRuntimeParams.sameRoute(this.#routeShown(from), Router.#routeHref(this.#getPathInfo(href)));
667
+ CsrRuntimeParams.sameRoute(Router.#routeHref(under), Router.#routeHref(target));
662
668
  if (isUnder) this.back(routeOptions);
663
669
  else this.replace(href, { scrollToTop: false, ...routeOptions });
664
670
  return undefined as never;
@@ -668,7 +674,7 @@ class Router {
668
674
  this.#checkInitialized();
669
675
  this.#guarded("back", null, () => {
670
676
  this.#navigations += 1;
671
- this.#instance.back(routeOptions);
677
+ csrLocation.leaving(this.#instance.back(routeOptions));
672
678
  });
673
679
  return undefined as never;
674
680
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akanjs",
3
- "version": "3.3.0-rc.54",
3
+ "version": "3.3.0-rc.55",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -26,7 +26,13 @@ const ROUTE_CACHE_SWEEP_INTERVAL_MS = 60_000;
26
26
 
27
27
  const HTML_STORE_SKIP_MAX_ENTRIES = 1000;
28
28
 
29
- const HELD_SKIP_REASONS = ["dynamic-request-api", "render-not-found", "render-redirect", "late-redirect"];
29
+ const HELD_SKIP_REASONS = [
30
+ "dynamic-request-api",
31
+ "render-not-found",
32
+ "render-redirect",
33
+ "late-redirect",
34
+ "body-too-large",
35
+ ];
30
36
 
31
37
  interface HtmlCacheStreamOptions {
32
38
  shouldCache?: () => boolean | Promise<boolean>;
@@ -58,21 +64,21 @@ export function cacheHtmlWhileStreaming(
58
64
  controller.enqueue(chunk);
59
65
  },
60
66
  async flush() {
61
- if (exceededMaxBodyBytes) {
62
- options.onSkip?.("body-too-large");
63
- return;
64
- }
65
- const body = new Uint8Array(byteLength);
66
- let offset = 0;
67
- for (const chunk of chunks) {
68
- body.set(chunk, offset);
69
- offset += chunk.byteLength;
70
- }
71
67
  try {
72
68
  if (options.shouldCache && !(await options.shouldCache())) {
73
69
  options.onSkip?.("store-skip");
74
70
  return;
75
71
  }
72
+ if (exceededMaxBodyBytes) {
73
+ options.onSkip?.("body-too-large");
74
+ return;
75
+ }
76
+ const body = new Uint8Array(byteLength);
77
+ let offset = 0;
78
+ for (const chunk of chunks) {
79
+ body.set(chunk, offset);
80
+ offset += chunk.byteLength;
81
+ }
76
82
  onComplete(body);
77
83
  } catch {
78
84
  }
@@ -14,6 +14,7 @@ const bypassReasons = [
14
14
  "render-not-found",
15
15
  "render-redirect",
16
16
  "late-redirect",
17
+ "body-too-large",
17
18
  "other",
18
19
  ] as const;
19
20
 
@@ -39,6 +39,10 @@ export declare class CsrLocation {
39
39
  static idxOf(state: unknown): number | undefined;
40
40
  /** Hears each `back()` as it moves, with the index of the entry it lands on; one listener, the router's. */
41
41
  onBack(listener: (idx: number) => void): void;
42
+ /** Holds the entry on screen as left until `moving`, a shell's back, settles; `back()` holds it until the pop lands. */
43
+ leaving(moving: unknown): void;
44
+ /** Whether a back has left the entry on screen and not landed yet. */
45
+ isLeaving(): boolean;
42
46
  back(): void;
43
47
  assign(href: string): void;
44
48
  reload(): void;
@@ -1,6 +1,6 @@
1
1
  import type { AkanMetricFamily } from "akanjs/service";
2
2
  declare const lookupReasons: readonly ["requested-query", "rewritten-query"];
3
- declare const bypassReasons: readonly ["env-opt-out", "dev-default-off", "ttl-disabled", "path-excluded", "request-not-public", "dev-registry", "no-route", "script-hashes", "dynamic-request-api", "render-not-found", "render-redirect", "late-redirect", "other"];
3
+ declare const bypassReasons: readonly ["env-opt-out", "dev-default-off", "ttl-disabled", "path-excluded", "request-not-public", "dev-registry", "no-route", "script-hashes", "dynamic-request-api", "render-not-found", "render-redirect", "late-redirect", "body-too-large", "other"];
4
4
  export type RouteCacheName = "rsc" | "html";
5
5
  export type RouteCacheLookupReason = (typeof lookupReasons)[number];
6
6
  export type RouteCacheBypassReason = (typeof bypassReasons)[number];
@@ -2,14 +2,14 @@
2
2
  export declare const badgeRecipe: (variants?: Omit<({
3
3
  size?: "lg" | "md" | "sm" | "xs" | undefined;
4
4
  outline?: boolean | undefined;
5
- variant?: "default" | "error" | "info" | "warning" | "success" | "primary" | "outline" | "secondary" | "accent" | "neutral" | undefined;
5
+ variant?: "error" | "default" | "info" | "warning" | "success" | "primary" | "outline" | "secondary" | "accent" | "neutral" | undefined;
6
6
  } & {
7
7
  class?: import("tailwind-variants/lite").ClassValue;
8
8
  className?: never;
9
9
  }) | ({
10
10
  size?: "lg" | "md" | "sm" | "xs" | undefined;
11
11
  outline?: boolean | undefined;
12
- variant?: "default" | "error" | "info" | "warning" | "success" | "primary" | "outline" | "secondary" | "accent" | "neutral" | undefined;
12
+ variant?: "error" | "default" | "info" | "warning" | "success" | "primary" | "outline" | "secondary" | "accent" | "neutral" | undefined;
13
13
  } & {
14
14
  class?: never;
15
15
  className?: import("tailwind-variants/lite").ClassValue;
@@ -2,7 +2,7 @@
2
2
  export declare const buttonRecipe: (variants?: Omit<({
3
3
  size?: "xl" | "lg" | "md" | "sm" | "xs" | "icon" | undefined;
4
4
  outline?: boolean | undefined;
5
- variant?: "default" | "link" | "info" | "warning" | "success" | "destructive" | "primary" | "outline" | "secondary" | "accent" | "neutral" | "ghost" | undefined;
5
+ variant?: "link" | "default" | "info" | "warning" | "success" | "destructive" | "primary" | "outline" | "secondary" | "accent" | "neutral" | "ghost" | undefined;
6
6
  shape?: "default" | "circle" | "square" | undefined;
7
7
  } & {
8
8
  class?: import("tailwind-variants/lite").ClassValue;
@@ -10,7 +10,7 @@ export declare const buttonRecipe: (variants?: Omit<({
10
10
  }) | ({
11
11
  size?: "xl" | "lg" | "md" | "sm" | "xs" | "icon" | undefined;
12
12
  outline?: boolean | undefined;
13
- variant?: "default" | "link" | "info" | "warning" | "success" | "destructive" | "primary" | "outline" | "secondary" | "accent" | "neutral" | "ghost" | undefined;
13
+ variant?: "link" | "default" | "info" | "warning" | "success" | "destructive" | "primary" | "outline" | "secondary" | "accent" | "neutral" | "ghost" | undefined;
14
14
  shape?: "default" | "circle" | "square" | undefined;
15
15
  } & {
16
16
  class?: never;
@@ -2,14 +2,14 @@
2
2
  export declare const inputRecipe: (variants?: Omit<({
3
3
  kind?: "field" | "select" | "area" | undefined;
4
4
  size?: "xl" | "lg" | "md" | "sm" | "xs" | undefined;
5
- tone?: "default" | "error" | "primary" | undefined;
5
+ tone?: "error" | "default" | "primary" | undefined;
6
6
  } & {
7
7
  class?: import("tailwind-variants/lite").ClassValue;
8
8
  className?: never;
9
9
  }) | ({
10
10
  kind?: "field" | "select" | "area" | undefined;
11
11
  size?: "xl" | "lg" | "md" | "sm" | "xs" | undefined;
12
- tone?: "default" | "error" | "primary" | undefined;
12
+ tone?: "error" | "default" | "primary" | undefined;
13
13
  } & {
14
14
  class?: never;
15
15
  className?: import("tailwind-variants/lite").ClassValue;
@@ -21,7 +21,7 @@ export declare class CsrSlide {
21
21
  static get isCalm(): boolean;
22
22
  static settleMove(kind: "push" | "replace", from: Location, to: Location): boolean;
23
23
  /** How an entry moves: its own page's transition, or that of the page it took the place of. */
24
- static motionOf(location: Location): "none" | "stack" | "fade" | "bottomUp" | "scaleOut";
24
+ static motionOf(location: Location): "stack" | "none" | "fade" | "bottomUp" | "scaleOut";
25
25
  /** Whether an entry swipes back: its own page's `gesture`, or that of the page it took the place of. */
26
26
  static swipesBack(location: Location): boolean;
27
27
  static isStill(entryId: string | undefined): boolean;
@@ -17,8 +17,8 @@ export declare const useCsrRefs: () => {
17
17
  pageContentRef: import("react").RefObject<HTMLDivElement | null>;
18
18
  prevPageContentRef: import("react").RefObject<HTMLDivElement | null>;
19
19
  onBack: import("react").RefObject<{
20
- none?: (() => Promise<void>) | undefined;
21
20
  stack?: (() => Promise<void>) | undefined;
21
+ none?: (() => Promise<void>) | undefined;
22
22
  fade?: (() => Promise<void>) | undefined;
23
23
  bottomUp?: (() => Promise<void>) | undefined;
24
24
  scaleOut?: (() => Promise<void>) | undefined;
package/ui/System/CSR.tsx CHANGED
@@ -333,7 +333,9 @@ const KeyboardLayer = ({
333
333
  type FrameSlotTarget = "topInset" | "topLeftAction" | "bottomInset" | "keyboardInset";
334
334
 
335
335
  const CSRFrameSlotTargets = ({ slot }: { slot: FrameSlotTarget }) => {
336
- const { stackEntries, topInset, topLeftAction, bottomInset } = useCsr();
336
+ const { stackEntries, topInset, topLeftAction, bottomInset, location: shownLocation } = useCsr();
337
+
338
+ const isLayerClear = shownLocation?.pathRoute?.pageState?.navbarMotion === "page";
337
339
  return (
338
340
  <>
339
341
  {stackEntries.map(({ key, location, pageType, zIndex }) => {
@@ -348,7 +350,7 @@ const CSRFrameSlotTargets = ({ slot }: { slot: FrameSlotTarget }) => {
348
350
  const { topInset: topHeight, bottomInset: bottomHeight, navbarMotion, overlay } = location.pathRoute.pageState;
349
351
  const collapsed = slot !== "keyboardInset" && (slot === "bottomInset" ? bottomHeight : topHeight) <= 0;
350
352
  const hidden = pageType !== "current" || collapsed;
351
- const ownBar = navbarMotion === "page" && (slot === "topInset" || slot === "topLeftAction");
353
+ const ownBar = (navbarMotion === "page" || isLayerClear) && (slot === "topInset" || slot === "topLeftAction");
352
354
  return (
353
355
  <animated.div
354
356
  key={id}