akanjs 3.3.0-rc.23 → 3.3.0-rc.24

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.
@@ -8,8 +8,11 @@ import {
8
8
  RequestLocale,
9
9
  } from "akanjs/common";
10
10
  import { untrackedHeaders, untrackedRequest } from "akanjs/fetch";
11
- import type { ReactNode } from "react";
11
+ import * as React from "react";
12
+ import { type Context, type ReactNode, use } from "react";
12
13
  import { csrLocation } from "./csrLocation";
14
+ import type { PathContextType } from "./csrTypes";
15
+ import { sharedContextKey } from "./sharedContextKey";
13
16
  import { Translator } from "./translator";
14
17
 
15
18
  type TransMessage<Locale extends Record<string, unknown>> = {
@@ -52,6 +55,23 @@ const escapeRichParams = (param: { [key: string]: string | number } | undefined)
52
55
  ]),
53
56
  );
54
57
 
58
+ const reactInternals = (
59
+ React as unknown as { __CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE?: { H: unknown } }
60
+ ).__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
61
+
62
+ const entryPathname = (): string | undefined => {
63
+ const context = (globalThis as unknown as { [slot: symbol]: Context<PathContextType> | undefined })[
64
+ sharedContextKey("path")
65
+ ];
66
+ if (!context || !reactInternals?.H) return undefined;
67
+ try {
68
+ const { location, followsRouter } = use(context);
69
+ return followsRouter ? undefined : location?.pathname;
70
+ } catch {
71
+ return undefined;
72
+ }
73
+ };
74
+
55
75
  const getPageInfo = (): { locale: string; path: string } => {
56
76
  const { defaultLocale, locales } = parseAkanI18nEnv();
57
77
  const localeSet = new Set(locales);
@@ -59,7 +79,7 @@ const getPageInfo = (): { locale: string; path: string } => {
59
79
  const activePath = Translator.getActivePath();
60
80
  if (activePath) return { locale: activeLocale ?? defaultLocale, path: activePath };
61
81
  if (getEnv().side !== "server") {
62
- const pathname = Translator.getRenderPath() ?? csrLocation.pathname;
82
+ const pathname = Translator.getRenderPath() ?? entryPathname() ?? csrLocation.pathname;
63
83
  const [, firstSegment = "", ...rest] = pathname.split("/");
64
84
  const hasLocalePrefix = localeSet.has(firstSegment);
65
85
 
@@ -1,10 +1,12 @@
1
1
  "use client";
2
2
  import { type Context, createContext } from "react";
3
3
 
4
+ import { sharedContextKey } from "./sharedContextKey";
5
+
4
6
  /** Every framework context is made here: a build inlines modules into each client chunk, so a plain `createContext`
5
7
  * copy silently misses a Provider from another chunk. `use-agentic` keeps its own `useAgentic.`-prefixed twin. */
6
8
  export const sharedContext = <T>(name: string, initial: T): Context<T> => {
7
- const key = Symbol.for(`akanjs.context.${name}`);
9
+ const key = sharedContextKey(name);
8
10
  const holder = globalThis as typeof globalThis & { [slot: symbol]: Context<T> | undefined };
9
11
  const existing = holder[key];
10
12
  if (existing) return existing;
@@ -0,0 +1,2 @@
1
+ /** Where `sharedContext` keeps a framework context on `globalThis`, readable by a module the server loads too. */
2
+ export const sharedContextKey = (name: string) => Symbol.for(`akanjs.context.${name}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akanjs",
3
- "version": "3.3.0-rc.23",
3
+ "version": "3.3.0-rc.24",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -1,5 +1,5 @@
1
1
  import { type ErrConstructor, type ErrPayload, type ErrRestoreOption } from "akanjs/common";
2
- import type { ReactNode } from "react";
2
+ import { type ReactNode } from "react";
3
3
  export type { ErrPayload } from "akanjs/common";
4
4
  /** @deprecated `Err` from `akanjs/common`, the class `makePageProto`'s `Err` is. */
5
5
  export interface PageErrInstance extends Error {
@@ -0,0 +1,2 @@
1
+ /** Where `sharedContext` keeps a framework context on `globalThis`, readable by a module the server loads too. */
2
+ export declare const sharedContextKey: (name: string) => symbol;
@@ -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;
@@ -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;