akanjs 3.3.0-rc.63 → 3.3.0-rc.64

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.
@@ -58,8 +58,10 @@ export interface PageConfig {
58
58
  ssr?: SsrRenderMode;
59
59
  /**
60
60
  * Opt-in suffix-only RSC commits under `AKAN_PUBLIC_RSC_PARTIAL_COMMIT=1`: the page's `.head()` is plain `title`,
61
- * `meta` and `link` tags, and the layouts above it render the same for each sibling page, apart from what they
62
- * read through `usePathCtx()`.
61
+ * `meta` and `link` tags, and the layouts above it draw on the server only from the args they declare. A move to a
62
+ * sibling page, or to another param or query of this page that no layout above declares with `.param()` or
63
+ * `.search()`, then renders the page alone and keeps those layouts as drawn; what follows the path in them is read
64
+ * on the client (`usePathCtx()`, `Link`'s `activeClassName`).
63
65
  */
64
66
  rscPatchHeadSafe?: boolean;
65
67
  /** `false` answers a `Link` prefetch of the page (on a layout, of every page under it) without rendering it, for a
@@ -180,6 +182,8 @@ export interface RouteRender {
180
182
  getRouteDefinition?: () => PromiseOrObject<RouteDefinition | undefined>;
181
183
  /** The query names the level reads; `undefined` for a legacy module, which receives every one. */
182
184
  getSearchNames?: () => PromiseOrObject<string[] | undefined>;
185
+ /** The params the level reads beyond `lang`; `undefined` for a legacy module, which receives every one. */
186
+ getParamNames?: () => PromiseOrObject<string[] | undefined>;
183
187
  }
184
188
  export interface RouteViewport {
185
189
  /** `viewport-fit=cover`: the page runs under the notch and home indicator, and `env(safe-area-inset-*)` measures them. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akanjs",
3
- "version": "3.3.0-rc.63",
3
+ "version": "3.3.0-rc.64",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -324,7 +324,7 @@ export function resolveAkanRscPatchDecision({
324
324
  }
325
325
  return {
326
326
  status: "patch",
327
- reason: "same-route-search-params",
327
+ reason: "same-route-page",
328
328
  commonPrefixLength: partialDecision.commonPrefixLength,
329
329
  patch: {
330
330
  patchStartIndex,
@@ -335,6 +335,11 @@ export class RouteTreeBuilder {
335
335
  if (definition) return definition.args.filter((arg) => arg.kind === "search").map((arg) => arg.name);
336
336
  return parseRouteModuleKey(key).isInternalRootLayout ? [] : undefined;
337
337
  },
338
+ getParamNames: async () => {
339
+ const { definition } = await loadModule();
340
+ if (definition) return definition.args.filter((arg) => arg.kind === "param").map((arg) => arg.name);
341
+ return parseRouteModuleKey(key).isInternalRootLayout ? [] : undefined;
342
+ },
338
343
  };
339
344
  if (kind === "page") {
340
345
  routeRender.getPageConfig = pageConfigOf;
@@ -368,6 +373,7 @@ export class RouteTreeBuilder {
368
373
  return createElement(mod.default as never, { children } as never);
369
374
  }) as RouteRender["render"],
370
375
  getSearchNames: () => [],
376
+ getParamNames: () => [],
371
377
  };
372
378
  }
373
379
 
@@ -1,5 +1,5 @@
1
- import type { PageState, PathRoute } from "akanjs/client";
2
- import type { Logger } from "akanjs/common";
1
+ import type { PageState, PathRoute, RouteRender } from "akanjs/client";
2
+ import { type Logger, parseSearchParams } from "akanjs/common";
3
3
  import type { ReactNode } from "react";
4
4
  import { RouteHead } from "../client/route/RouteHead";
5
5
  import { akanHeadSnapshotKey, createAkanLocaleAlternateHeadSnapshot, mergeAkanHeadSnapshots } from "./head";
@@ -21,7 +21,8 @@ import { resolveAkanRscHeadSafePatchDecision } from "./rscWorkerCache";
21
21
  type RouteHeadLayers = Awaited<ReturnType<typeof RouteElementComposer.resolveHeadLayers>>;
22
22
  type RouteMatch = { pathRoute: PathRoute; params: Record<string, string> };
23
23
  type SearchParams = Record<string, string | string[]>;
24
- type FrameChange = "params-changed" | "layouts-changed" | "page-state-changed" | "frame-unknown";
24
+ type RouteRead = { params: Record<string, string>; searchParams: SearchParams };
25
+ type FrameChange = "params-changed" | "search-changed" | "layouts-changed" | "page-state-changed" | "frame-unknown";
25
26
 
26
27
  export interface RouteHeadSnapshots {
27
28
  layouts: AkanHeadSnapshotV1;
@@ -135,7 +136,7 @@ export class RscPatchPlanner {
135
136
  const routeHeadMounted = routeHeadKey !== undefined;
136
137
  const frameChange =
137
138
  pageConfig?.rscPatchHeadSafe === true && routeHeadMounted
138
- ? await this.#frameChangeOf(url, match, current, patchDecision.patch.patchStartIndex)
139
+ ? await this.#frameChangeOf(url, match, searchParams, current, patchDecision.patch.patchStartIndex)
139
140
  : undefined;
140
141
  let admittedHead: ResolvedRouteHead | undefined;
141
142
  if (pageConfig?.rscPatchHeadSafe === true && routeHeadMounted && !frameChange) {
@@ -183,20 +184,27 @@ export class RscPatchPlanner {
183
184
  async #frameChangeOf(
184
185
  url: URL,
185
186
  match: RouteMatch,
187
+ searchParams: SearchParams,
186
188
  current: AkanRouterStateV1 | null,
187
189
  patchStartIndex: number,
188
190
  ): Promise<FrameChange | undefined> {
189
191
  const currentUrl = current && URL.canParse(current.href) ? new URL(current.href) : null;
190
192
  const currentMatch = currentUrl ? RouteTreeBuilder.match(currentUrl.pathname, this.#props.routes()) : null;
191
- if (!currentMatch) return "frame-unknown";
192
- const paramNames = new Set([...Object.keys(currentMatch.params), ...Object.keys(match.params)]);
193
- if ([...paramNames].some((name) => currentMatch.params[name] !== match.params[name])) return "params-changed";
193
+ if (!currentUrl || !currentMatch) return "frame-unknown";
194
194
  const keptLayouts = (route: PathRoute) =>
195
195
  [...route.renderRootLayouts, ...route.renderLayouts].slice(0, patchStartIndex);
196
196
  const [fromLayouts, toLayouts] = [keptLayouts(currentMatch.pathRoute), keptLayouts(match.pathRoute)];
197
- if (fromLayouts.length !== toLayouts.length || fromLayouts.some((layout, index) => layout !== toLayouts[index]))
198
- return "layouts-changed";
197
+ const sameLayouts =
198
+ fromLayouts.length === toLayouts.length && fromLayouts.every((layout, index) => layout === toLayouts[index]);
199
+ if (currentMatch.params.lang !== match.params.lang) return "params-changed";
200
+ if (!sameLayouts) return "layouts-changed";
199
201
  try {
202
+ const readChange = await RscPatchPlanner.#readChangeOf(
203
+ toLayouts,
204
+ { params: currentMatch.params, searchParams: parseSearchParams(currentUrl.search) },
205
+ { params: match.params, searchParams },
206
+ );
207
+ if (readChange) return readChange;
200
208
  const basePath = this.#props.basePathOf(url);
201
209
  const [from, to] = await Promise.all([
202
210
  RouteElementComposer.resolveSsrFramePathRoute({ pathRoute: currentMatch.pathRoute, basePath }),
@@ -214,6 +222,24 @@ export class RscPatchPlanner {
214
222
  }
215
223
  }
216
224
 
225
+ static async #readChangeOf(
226
+ layouts: RouteRender[],
227
+ from: RouteRead,
228
+ to: RouteRead,
229
+ ): Promise<"params-changed" | "search-changed" | undefined> {
230
+ const reads = await Promise.all(
231
+ layouts.map(async (layout) => ({
232
+ params: await layout.getParamNames?.(),
233
+ search: (await layout.getSearchNames?.()) ?? [],
234
+ })),
235
+ );
236
+ const everyParam = [...new Set([...Object.keys(from.params), ...Object.keys(to.params)])];
237
+ if (reads.some(({ params }) => (params ?? everyParam).some((name) => from.params[name] !== to.params[name])))
238
+ return "params-changed";
239
+ const moved = (name: string) => JSON.stringify(from.searchParams[name]) !== JSON.stringify(to.searchParams[name]);
240
+ return reads.some(({ search }) => search.some(moved)) ? "search-changed" : undefined;
241
+ }
242
+
217
243
  static #keptFrameOf({ cache: _cache, ssr: _ssr, ...frame }: PageState) {
218
244
  return frame;
219
245
  }
@@ -281,7 +281,7 @@ export function resolveAkanRscHeadSafePatchDecision({
281
281
  pageConfig?: PageConfig;
282
282
  /** Whether the page the patch leaves from shows its head through `AkanRouteHead`, the only head a patch can swap. */
283
283
  routeHeadMounted?: boolean;
284
- frameChange?: "params-changed" | "layouts-changed" | "page-state-changed" | "frame-unknown";
284
+ frameChange?: "params-changed" | "search-changed" | "layouts-changed" | "page-state-changed" | "frame-unknown";
285
285
  headSnapshot?: AkanHeadSnapshotV1;
286
286
  /** Whether the target's layouts head differs from the one the page left from shows, which a patch would keep. */
287
287
  layoutsHeadChanged?: boolean;
@@ -51,8 +51,10 @@ export interface PageConfig {
51
51
  ssr?: SsrRenderMode;
52
52
  /**
53
53
  * Opt-in suffix-only RSC commits under `AKAN_PUBLIC_RSC_PARTIAL_COMMIT=1`: the page's `.head()` is plain `title`,
54
- * `meta` and `link` tags, and the layouts above it render the same for each sibling page, apart from what they
55
- * read through `usePathCtx()`.
54
+ * `meta` and `link` tags, and the layouts above it draw on the server only from the args they declare. A move to a
55
+ * sibling page, or to another param or query of this page that no layout above declares with `.param()` or
56
+ * `.search()`, then renders the page alone and keeps those layouts as drawn; what follows the path in them is read
57
+ * on the client (`usePathCtx()`, `Link`'s `activeClassName`).
56
58
  */
57
59
  rscPatchHeadSafe?: boolean;
58
60
  /** `false` answers a `Link` prefetch of the page (on a layout, of every page under it) without rendering it, for a
@@ -187,6 +189,8 @@ export interface RouteRender {
187
189
  getRouteDefinition?: () => PromiseOrObject<RouteDefinition | undefined>;
188
190
  /** The query names the level reads; `undefined` for a legacy module, which receives every one. */
189
191
  getSearchNames?: () => PromiseOrObject<string[] | undefined>;
192
+ /** The params the level reads beyond `lang`; `undefined` for a legacy module, which receives every one. */
193
+ getParamNames?: () => PromiseOrObject<string[] | undefined>;
190
194
  }
191
195
  export interface RouteViewport {
192
196
  /** `viewport-fit=cover`: the page runs under the notch and home indicator, and `env(safe-area-inset-*)` measures them. */
@@ -1,5 +1,5 @@
1
1
  import type { PathRoute } from "akanjs/client";
2
- import type { Logger } from "akanjs/common";
2
+ import { type Logger } from "akanjs/common";
3
3
  import type { ReactNode } from "react";
4
4
  import { RouteElementComposer } from "./routeElementComposer.d.ts";
5
5
  import { type AkanHeadSnapshotV1, type AkanRouterStateV1, type AkanRscPatchDecision, readAkanRouterStateRequest } from "./routeState.d.ts";
@@ -129,7 +129,7 @@ export declare function resolveAkanRscHeadSafePatchDecision({ partialCommitEnabl
129
129
  pageConfig?: PageConfig;
130
130
  /** Whether the page the patch leaves from shows its head through `AkanRouteHead`, the only head a patch can swap. */
131
131
  routeHeadMounted?: boolean;
132
- frameChange?: "params-changed" | "layouts-changed" | "page-state-changed" | "frame-unknown";
132
+ frameChange?: "params-changed" | "search-changed" | "layouts-changed" | "page-state-changed" | "frame-unknown";
133
133
  headSnapshot?: AkanHeadSnapshotV1;
134
134
  /** Whether the target's layouts head differs from the one the page left from shows, which a patch would keep. */
135
135
  layoutsHeadChanged?: boolean;
@@ -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;