@rsc-kit/core 0.30.38 → 0.30.39

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.
Files changed (54) hide show
  1. package/dist/flash.d.ts +18 -0
  2. package/dist/flash.js +29 -0
  3. package/dist/flash.js.map +1 -0
  4. package/dist/flashCookie.d.ts +17 -0
  5. package/dist/flashCookie.js +36 -0
  6. package/dist/flashCookie.js.map +1 -0
  7. package/dist/js/ActivityRouter.js +3 -3
  8. package/dist/js/ActivityRouter.js.map +1 -1
  9. package/dist/js/Changes.js +1 -1
  10. package/dist/js/Changes.js.map +1 -1
  11. package/dist/js/DefaultRouteError.d.ts +1 -1
  12. package/dist/js/DefaultRouteError.js.map +1 -1
  13. package/dist/js/Form.d.ts +2 -2
  14. package/dist/js/Form.js +5 -5
  15. package/dist/js/Form.js.map +1 -1
  16. package/dist/js/Link.js +2 -2
  17. package/dist/js/Link.js.map +1 -1
  18. package/dist/js/RedirectBoundary.js +2 -2
  19. package/dist/js/RedirectBoundary.js.map +1 -1
  20. package/dist/js/SegmentBoundary.js +5 -5
  21. package/dist/js/SegmentBoundary.js.map +1 -1
  22. package/dist/js/SlotBoundary.js +3 -3
  23. package/dist/js/SlotBoundary.js.map +1 -1
  24. package/dist/js/changesStore.js +1 -1
  25. package/dist/js/changesStore.js.map +1 -1
  26. package/dist/js/createViteRscApp.js +14 -14
  27. package/dist/js/createViteRscApp.js.map +1 -1
  28. package/dist/js/navigate.d.ts +1 -1
  29. package/dist/js/navigate.js +8 -8
  30. package/dist/js/navigate.js.map +1 -1
  31. package/dist/js/nuqs.js +2 -2
  32. package/dist/js/nuqs.js.map +1 -1
  33. package/dist/js/pagePayload.js +2 -2
  34. package/dist/js/pagePayload.js.map +1 -1
  35. package/dist/js/refreshOn.js +3 -3
  36. package/dist/js/refreshOn.js.map +1 -1
  37. package/dist/js/section.d.ts +4 -4
  38. package/dist/js/section.js +2 -2
  39. package/dist/js/section.js.map +1 -1
  40. package/dist/js/useAppUpdate.js +1 -1
  41. package/dist/js/useAppUpdate.js.map +1 -1
  42. package/dist/js/useFlash.d.ts +16 -0
  43. package/dist/js/useFlash.js +56 -0
  44. package/dist/js/useFlash.js.map +1 -0
  45. package/dist/js/useOnline.js +1 -1
  46. package/dist/js/useOnline.js.map +1 -1
  47. package/dist/js/usePathname.js +1 -1
  48. package/dist/js/usePathname.js.map +1 -1
  49. package/dist/testing.d.ts +9 -0
  50. package/dist/testing.js +14 -2
  51. package/dist/testing.js.map +1 -1
  52. package/dist/vite.js +1 -0
  53. package/dist/vite.js.map +1 -1
  54. package/package.json +9 -1
@@ -0,0 +1,18 @@
1
+ import { type FlashKind } from "./flashCookie.js";
2
+ export type { FlashKind, FlashMessage } from "./flashCookie.js";
3
+ /**
4
+ * A message for the next page the visitor sees: "Saved." after a save that
5
+ * redirects to the list. Call it in a server action, middleware or a
6
+ * route.ts - anywhere a cookie can still be set - and show it with
7
+ * useFlash() from @rsc-kit/core/useFlash.
8
+ *
9
+ * A cookie the browser takes, not one the server reads. A page that read it
10
+ * would be a page that can never be stored or cached at the edge, and a
11
+ * render cannot clear it anyway: its headers leave before it starts. So the
12
+ * page is the same for everyone, and the browser picks the message up after
13
+ * the navigation and clears it, once.
14
+ *
15
+ * Two calls in one request are two messages. Unread, it lapses after a
16
+ * minute, so a message never turns up on some later, unrelated page.
17
+ */
18
+ export declare function flash(message: string, kind?: FlashKind): Promise<void>;
package/dist/flash.js ADDED
@@ -0,0 +1,29 @@
1
+ import { cookies } from "./request.js";
2
+ import { FLASH_COOKIE, readFlash } from "./flashCookie.js";
3
+ /**
4
+ * A message for the next page the visitor sees: "Saved." after a save that
5
+ * redirects to the list. Call it in a server action, middleware or a
6
+ * route.ts - anywhere a cookie can still be set - and show it with
7
+ * useFlash() from @rsc-kit/core/useFlash.
8
+ *
9
+ * A cookie the browser takes, not one the server reads. A page that read it
10
+ * would be a page that can never be stored or cached at the edge, and a
11
+ * render cannot clear it anyway: its headers leave before it starts. So the
12
+ * page is the same for everyone, and the browser picks the message up after
13
+ * the navigation and clears it, once.
14
+ *
15
+ * Two calls in one request are two messages. Unread, it lapses after a
16
+ * minute, so a message never turns up on some later, unrelated page.
17
+ */
18
+ export async function flash(message, kind = "success") {
19
+ const jar = await cookies();
20
+ const queued = readFlash(jar.get(FLASH_COOKIE)?.value);
21
+ // Readable by script on purpose (no HttpOnly): the browser is what takes it.
22
+ // It holds a message the app chose, never data.
23
+ jar.set(FLASH_COOKIE, JSON.stringify([...queued, { message, kind }]), {
24
+ path: "/",
25
+ maxAge: 60,
26
+ sameSite: "lax",
27
+ });
28
+ }
29
+ //# sourceMappingURL=flash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flash.js","sourceRoot":"","sources":["../src/flash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAkB,MAAM,kBAAkB,CAAC;AAI3E;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,OAAe,EAAE,IAAI,GAAc,SAAS;IACtE,MAAM,GAAG,GAAG,MAAM,OAAO,EAAE,CAAC;IAC5B,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,KAAK,CAAC,CAAC;IAEvD,6EAA6E;IAC7E,gDAAgD;IAChD,GAAG,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE;QACpE,IAAI,EAAE,GAAG;QACT,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE,KAAK;KAChB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { cookies } from \"./request.js\";\nimport { FLASH_COOKIE, readFlash, type FlashKind } from \"./flashCookie.js\";\n\nexport type { FlashKind, FlashMessage } from \"./flashCookie.js\";\n\n/**\n * A message for the next page the visitor sees: \"Saved.\" after a save that\n * redirects to the list. Call it in a server action, middleware or a\n * route.ts - anywhere a cookie can still be set - and show it with\n * useFlash() from @rsc-kit/core/useFlash.\n *\n * A cookie the browser takes, not one the server reads. A page that read it\n * would be a page that can never be stored or cached at the edge, and a\n * render cannot clear it anyway: its headers leave before it starts. So the\n * page is the same for everyone, and the browser picks the message up after\n * the navigation and clears it, once.\n *\n * Two calls in one request are two messages. Unread, it lapses after a\n * minute, so a message never turns up on some later, unrelated page.\n */\nexport async function flash(message: string, kind: FlashKind = \"success\"): Promise<void> {\n const jar = await cookies();\n const queued = readFlash(jar.get(FLASH_COOKIE)?.value);\n\n // Readable by script on purpose (no HttpOnly): the browser is what takes it.\n // It holds a message the app chose, never data.\n jar.set(FLASH_COOKIE, JSON.stringify([...queued, { message, kind }]), {\n path: \"/\",\n maxAge: 60,\n sameSite: \"lax\",\n });\n}\n"]}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The one-time message's cookie, shared by the server that writes it and the
3
+ * browser that takes it. No imports: the hook that reads it is in the
4
+ * browser bundle, and request.ts must never be.
5
+ */
6
+ export declare const FLASH_COOKIE = "rsc-flash";
7
+ export type FlashKind = "success" | "error" | "info" | "warning";
8
+ export interface FlashMessage {
9
+ message: string;
10
+ kind: FlashKind;
11
+ }
12
+ /**
13
+ * What a cookie value holds, keeping only well-formed messages. The value
14
+ * crossed the network and could have been written by anything that shares
15
+ * the domain, so nothing here trusts it beyond being text.
16
+ */
17
+ export declare function readFlash(value: string | undefined | null): FlashMessage[];
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The one-time message's cookie, shared by the server that writes it and the
3
+ * browser that takes it. No imports: the hook that reads it is in the
4
+ * browser bundle, and request.ts must never be.
5
+ */
6
+ export const FLASH_COOKIE = "rsc-flash";
7
+ const KINDS = new Set(["success", "error", "info", "warning"]);
8
+ /**
9
+ * What a cookie value holds, keeping only well-formed messages. The value
10
+ * crossed the network and could have been written by anything that shares
11
+ * the domain, so nothing here trusts it beyond being text.
12
+ */
13
+ export function readFlash(value) {
14
+ if (!value)
15
+ return [];
16
+ let parsed;
17
+ try {
18
+ parsed = JSON.parse(value);
19
+ }
20
+ catch {
21
+ return [];
22
+ }
23
+ if (!Array.isArray(parsed))
24
+ return [];
25
+ return parsed.flatMap((entry) => {
26
+ if (typeof entry !== "object" || entry === null)
27
+ return [];
28
+ const { message, kind } = entry;
29
+ if (typeof message !== "string" || message === "")
30
+ return [];
31
+ return [
32
+ { message, kind: typeof kind === "string" && KINDS.has(kind) ? kind : "info" },
33
+ ];
34
+ });
35
+ }
36
+ //# sourceMappingURL=flashCookie.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flashCookie.js","sourceRoot":"","sources":["../src/flashCookie.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,WAAW,CAAC;AASxC,MAAM,KAAK,GAAG,IAAI,GAAG,CAAS,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AAEvE;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,KAAgC;IACxD,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IAEtB,IAAI,MAAe,CAAC;IAEpB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,OAAO,EAAE,CAAC;IAEtC,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAkB,EAAE;QAC9C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO,EAAE,CAAC;QAE3D,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,KAAgC,CAAC;QAE3D,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,EAAE;YAAE,OAAO,EAAE,CAAC;QAE7D,OAAO;YACL,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAE,IAAkB,CAAC,CAAC,CAAC,MAAM,EAAE;SAC9F,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * The one-time message's cookie, shared by the server that writes it and the\n * browser that takes it. No imports: the hook that reads it is in the\n * browser bundle, and request.ts must never be.\n */\nexport const FLASH_COOKIE = \"rsc-flash\";\n\nexport type FlashKind = \"success\" | \"error\" | \"info\" | \"warning\";\n\nexport interface FlashMessage {\n message: string;\n kind: FlashKind;\n}\n\nconst KINDS = new Set<string>([\"success\", \"error\", \"info\", \"warning\"]);\n\n/**\n * What a cookie value holds, keeping only well-formed messages. The value\n * crossed the network and could have been written by anything that shares\n * the domain, so nothing here trusts it beyond being text.\n */\nexport function readFlash(value: string | undefined | null): FlashMessage[] {\n if (!value) return [];\n\n let parsed: unknown;\n\n try {\n parsed = JSON.parse(value);\n } catch {\n return [];\n }\n\n if (!Array.isArray(parsed)) return [];\n\n return parsed.flatMap((entry): FlashMessage[] => {\n if (typeof entry !== \"object\" || entry === null) return [];\n\n const { message, kind } = entry as Record<string, unknown>;\n\n if (typeof message !== \"string\" || message === \"\") return [];\n\n return [\n { message, kind: typeof kind === \"string\" && KINDS.has(kind) ? (kind as FlashKind) : \"info\" },\n ];\n });\n}\n"]}
@@ -14,9 +14,9 @@ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
14
14
  * visited entry is dropped past the limit.
15
15
  */
16
16
  import { Activity, useCallback, useEffect, useRef, useState, startTransition } from 'react';
17
- import { setNavigateHandler, setReplaceRootHandler, setRestoreHandler } from './navigate';
18
- import { navigationCommitted } from './perf';
19
- import { clearSegments, setSegment } from './segmentStore';
17
+ import { setNavigateHandler, setReplaceRootHandler, setRestoreHandler } from './navigate.js';
18
+ import { navigationCommitted } from './perf.js';
19
+ import { clearSegments, setSegment } from './segmentStore.js';
20
20
  /** Pages kept alive behind the visible one. Four covers ordinary back-and-forth. */
21
21
  export const DEFAULT_RETENTION = 4;
22
22
  export function useActivityRouter(initial, retention = DEFAULT_RETENTION) {
@@ -1 +1 @@
1
- {"version":3,"file":"ActivityRouter.js","sourceRoot":"","sources":["../../src/js/ActivityRouter.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,OAAO,CAAA;AAE3F,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AACzF,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AA4B1D,oFAAoF;AACpF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAA;AAElC,MAAM,UAAU,iBAAiB,CAC/B,OAAoB,EACpB,SAAS,GAAW,iBAAiB;IAErC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAgB,CAAC,OAAO,CAAC,CAAC,CAAA;IAChE,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IAEvD,8EAA8E;IAC9E,8EAA8E;IAC9E,4BAA4B;IAC5B,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;IAClC,MAAM,QAAQ,GAAG,MAAM,CAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAA;IAEhD,MAAM,MAAM,GAAG,WAAW,CAAC,CAAC,IAAmB,EAAE,E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G,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CACtB,KAAC,QAAQ,IAAiB,IAAI,EAAE,KAAK,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,YAC3E,KAAK,CAAC,IAAI,IADE,KAAK,CAAC,GAAG,CAEb,CACZ,CAAC,GACD,CACJ,CAAA;AACH,CAAC","sourcesContent":["/**\n * Keeps recently visited pages mounted but hidden, so going back restores them\n * rather than rebuilding them.\n *\n * Rendering each navigation with root.render() unmounts the previous tree, and\n * unmounting destroys client state: a half-typed form, an open disclosure, a\n * scrolled list. React's <Activity mode=\"hidden\"> hides a tree without\n * unmounting it — effects are torn down, but state survives — which is what\n * makes returning feel like the browser's own back button rather than a reload.\n *\n * Retention is bounded. Hidden trees keep their DOM, so an unbounded history\n * would grow the document for the length of the session; the least recently\n * visited entry is dropped past the limit.\n */\n\nimport { Activity, useCallback, useEffect, useRef, useState, startTransition } from 'react'\nimport type { ReactNode } from 'react'\nimport { setNavigateHandler, setReplaceRootHandler, setRestoreHandler } from './navigate'\nimport { navigationCommitted } from './perf'\nimport { clearSegments, setSegment } from './segmentStore'\n\nexport interface RouterEntry {\n /** Identifies the page: its URL, or the intercept variant of one. */\n key: string\n tree: ReactNode\n}\n\nexport interface ActivityRouterHandle {\n /** Show `tree` for `key`, retaining whatever was visible before. */\n show(key: string, tree: ReactNode): void\n /**\n * Give the visible page a new tree, in place: the same entry, the same\n * Activity, re-rendered. For a re-render of the whole document after an\n * action - revalidate(\"all\") - which is the page the visitor is on, not a\n * page they went to. show() under the current url made a NEW entry when\n * the visible one was keyed by the url the document loaded with, and\n * every partial navigation since had left that key alone: the whole app\n * remounted under a second Activity, the old one hidden behind it, and\n * the form's state - its \"added to cart\" - went with it.\n */\n replace(tree: ReactNode): void\n /** Reveal a retained page without refetching. False when not retained. */\n restore(key: string): boolean\n /** Drop every retained page but the visible one. */\n clear(): void\n}\n\n/** Pages kept alive behind the visible one. Four covers ordinary back-and-forth. */\nexport const DEFAULT_RETENTION = 4\n\nexport function useActivityRouter(\n initial: RouterEntry,\n retention: number = DEFAULT_RETENTION,\n): { entries: RouterEntry[]; activeKey: string; handle: ActivityRouterHandle } {\n const [entries, setEntries] = useState<RouterEntry[]>([initial])\n const [activeKey, setActiveKey] = useState(initial.key)\n\n // The router calls into this from outside React, where the values captured by\n // the last render may already be stale. Refs mirror state so those calls read\n // what is actually mounted.\n const entriesRef = useRef(entries)\n const orderRef = useRef<string[]>([initial.key])\n\n const commit = useCallback((next: RouterEntry[]) => {\n entriesRef.current = next\n setEntries(next)\n }, [])\n\n // Recency, most recent last. Retention is by visit order rather than\n // insertion, so bouncing between two pages evicts neither.\n const touch = useCallback(\n (key: string) => {\n const next = orderRef.current.filter((k) => k !== key)\n next.push(key)\n orderRef.current = next.slice(-Math.max(1, retention))\n\n return orderRef.current\n },\n [retention],\n )\n\n const show = useCallback(\n (key: string, tree: ReactNode) => {\n const kept = touch(key)\n const others = entriesRef.current.filter((entry) => entry.key !== key && kept.includes(entry.key))\n\n commit([...others, { key, tree }])\n setActiveKey(key)\n },\n [commit, touch],\n )\n\n const replace = useCallback(\n (tree: ReactNode) => {\n const active = entriesRef.current.find((entry) => entry.key === activeKey)\n\n if (!active) return\n\n // A transition, so a boundary in the new tree still waiting on its row\n // keeps what is on screen rather than showing its fallback - which\n // would unmount the form under it and take its state along. The\n // document's payload arrives with some rows still pending, and a\n // synchronous render showed the product's skeleton for a frame and\n // remounted the \"add to cart\" form beneath it.\n startTransition(() => {\n commit(entriesRef.current.map((entry) => (entry === active ? { key: entry.key, tree } : entry)))\n })\n },\n [activeKey, commit],\n )\n\n const restore = useCallback(\n (key: string) => {\n if (!entriesRef.current.some((entry) => entry.key === key)) return false\n\n touch(key)\n setActiveKey(key)\n\n return true\n },\n [touch],\n )\n\n const clear = useCallback(() => {\n const kept = entriesRef.current.filter((entry) => entry.key === activeKey)\n\n commit(kept)\n orderRef.current = [activeKey]\n }, [activeKey, commit])\n\n const handleRef = useRef<ActivityRouterHandle>({ show, replace, restore, clear })\n handleRef.current = { show, replace, restore, clear }\n\n return { entries, activeKey, handle: handleRef.current }\n}\n\n/**\n * Root of the hydrated app.\n *\n * Registers itself with the navigation engine so a navigation becomes a state\n * update here rather than a fresh root.render(), which is what allows the\n * previous page to stay mounted.\n */\nexport function ActivityRoot({ initialKey, initialTree }: { initialKey: string; initialTree: ReactNode }) {\n const { entries, activeKey, handle } = useActivityRouter({ key: initialKey, tree: initialTree })\n\n // A whole document shown, or a held page revealed: the navigation's commit.\n useEffect(() => {\n navigationCommitted()\n }, [activeKey, entries])\n\n useEffect(() => {\n setNavigateHandler((tree, key, segmentDepth) => {\n // A partial payload replaces one segment inside the page that is already\n // showing; only a whole document is a new page to retain.\n if (segmentDepth > 0) {\n setSegment(segmentDepth, key, tree as ReactNode)\n\n return\n }\n\n clearSegments()\n handle.show(key, tree as ReactNode)\n })\n\n setRestoreHandler((key) => handle.restore(key))\n setReplaceRootHandler((tree) => handle.replace(tree as ReactNode))\n }, [handle])\n\n return (\n <>\n {entries.map((entry) => (\n <Activity key={entry.key} mode={entry.key === activeKey ? 'visible' : 'hidden'}>\n {entry.tree}\n </Activity>\n ))}\n </>\n )\n}\n"]}
1
+ {"version":3,"file":"ActivityRouter.js","sourceRoot":"","sources":["../../src/js/ActivityRouter.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,OAAO,CAAA;AAE3F,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAC5F,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AA4B7D,oFAAoF;AACpF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AC7C,yEAAyE;YACzE,0DAA0D;YAC1D,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;gBACrB,UAAU,CAAC,YAAY,EAAE,GAAG,EAAE,IAAiB,CAAC,CAAA;gBAEhD,OAAM;YACR,CAAC;YAED,aAAa,EAAE,CAAA;YACf,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,IAAiB,CAAC,CAAA;QACrC,CAAC,CAAC,CAAA;QAEF,iBAAiB,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAA;QAC/C,qBAAqB,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAiB,CAAC,CAAC,CAAA;IACpE,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAA;IAEZ,OAAO,CACL,4BACG,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CACtB,KAAC,QAAQ,IAAiB,IAAI,EAAE,KAAK,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,YAC3E,KAAK,CAAC,IAAI,IADE,KAAK,CAAC,GAAG,CAEb,CACZ,CAAC,GACD,CACJ,CAAA;AACH,CAAC","sourcesContent":["/**\n * Keeps recently visited pages mounted but hidden, so going back restores them\n * rather than rebuilding them.\n *\n * Rendering each navigation with root.render() unmounts the previous tree, and\n * unmounting destroys client state: a half-typed form, an open disclosure, a\n * scrolled list. React's <Activity mode=\"hidden\"> hides a tree without\n * unmounting it — effects are torn down, but state survives — which is what\n * makes returning feel like the browser's own back button rather than a reload.\n *\n * Retention is bounded. Hidden trees keep their DOM, so an unbounded history\n * would grow the document for the length of the session; the least recently\n * visited entry is dropped past the limit.\n */\n\nimport { Activity, useCallback, useEffect, useRef, useState, startTransition } from 'react'\nimport type { ReactNode } from 'react'\nimport { setNavigateHandler, setReplaceRootHandler, setRestoreHandler } from './navigate.js'\nimport { navigationCommitted } from './perf.js'\nimport { clearSegments, setSegment } from './segmentStore.js'\n\nexport interface RouterEntry {\n /** Identifies the page: its URL, or the intercept variant of one. */\n key: string\n tree: ReactNode\n}\n\nexport interface ActivityRouterHandle {\n /** Show `tree` for `key`, retaining whatever was visible before. */\n show(key: string, tree: ReactNode): void\n /**\n * Give the visible page a new tree, in place: the same entry, the same\n * Activity, re-rendered. For a re-render of the whole document after an\n * action - revalidate(\"all\") - which is the page the visitor is on, not a\n * page they went to. show() under the current url made a NEW entry when\n * the visible one was keyed by the url the document loaded with, and\n * every partial navigation since had left that key alone: the whole app\n * remounted under a second Activity, the old one hidden behind it, and\n * the form's state - its \"added to cart\" - went with it.\n */\n replace(tree: ReactNode): void\n /** Reveal a retained page without refetching. False when not retained. */\n restore(key: string): boolean\n /** Drop every retained page but the visible one. */\n clear(): void\n}\n\n/** Pages kept alive behind the visible one. Four covers ordinary back-and-forth. */\nexport const DEFAULT_RETENTION = 4\n\nexport function useActivityRouter(\n initial: RouterEntry,\n retention: number = DEFAULT_RETENTION,\n): { entries: RouterEntry[]; activeKey: string; handle: ActivityRouterHandle } {\n const [entries, setEntries] = useState<RouterEntry[]>([initial])\n const [activeKey, setActiveKey] = useState(initial.key)\n\n // The router calls into this from outside React, where the values captured by\n // the last render may already be stale. Refs mirror state so those calls read\n // what is actually mounted.\n const entriesRef = useRef(entries)\n const orderRef = useRef<string[]>([initial.key])\n\n const commit = useCallback((next: RouterEntry[]) => {\n entriesRef.current = next\n setEntries(next)\n }, [])\n\n // Recency, most recent last. Retention is by visit order rather than\n // insertion, so bouncing between two pages evicts neither.\n const touch = useCallback(\n (key: string) => {\n const next = orderRef.current.filter((k) => k !== key)\n next.push(key)\n orderRef.current = next.slice(-Math.max(1, retention))\n\n return orderRef.current\n },\n [retention],\n )\n\n const show = useCallback(\n (key: string, tree: ReactNode) => {\n const kept = touch(key)\n const others = entriesRef.current.filter((entry) => entry.key !== key && kept.includes(entry.key))\n\n commit([...others, { key, tree }])\n setActiveKey(key)\n },\n [commit, touch],\n )\n\n const replace = useCallback(\n (tree: ReactNode) => {\n const active = entriesRef.current.find((entry) => entry.key === activeKey)\n\n if (!active) return\n\n // A transition, so a boundary in the new tree still waiting on its row\n // keeps what is on screen rather than showing its fallback - which\n // would unmount the form under it and take its state along. The\n // document's payload arrives with some rows still pending, and a\n // synchronous render showed the product's skeleton for a frame and\n // remounted the \"add to cart\" form beneath it.\n startTransition(() => {\n commit(entriesRef.current.map((entry) => (entry === active ? { key: entry.key, tree } : entry)))\n })\n },\n [activeKey, commit],\n )\n\n const restore = useCallback(\n (key: string) => {\n if (!entriesRef.current.some((entry) => entry.key === key)) return false\n\n touch(key)\n setActiveKey(key)\n\n return true\n },\n [touch],\n )\n\n const clear = useCallback(() => {\n const kept = entriesRef.current.filter((entry) => entry.key === activeKey)\n\n commit(kept)\n orderRef.current = [activeKey]\n }, [activeKey, commit])\n\n const handleRef = useRef<ActivityRouterHandle>({ show, replace, restore, clear })\n handleRef.current = { show, replace, restore, clear }\n\n return { entries, activeKey, handle: handleRef.current }\n}\n\n/**\n * Root of the hydrated app.\n *\n * Registers itself with the navigation engine so a navigation becomes a state\n * update here rather than a fresh root.render(), which is what allows the\n * previous page to stay mounted.\n */\nexport function ActivityRoot({ initialKey, initialTree }: { initialKey: string; initialTree: ReactNode }) {\n const { entries, activeKey, handle } = useActivityRouter({ key: initialKey, tree: initialTree })\n\n // A whole document shown, or a held page revealed: the navigation's commit.\n useEffect(() => {\n navigationCommitted()\n }, [activeKey, entries])\n\n useEffect(() => {\n setNavigateHandler((tree, key, segmentDepth) => {\n // A partial payload replaces one segment inside the page that is already\n // showing; only a whole document is a new page to retain.\n if (segmentDepth > 0) {\n setSegment(segmentDepth, key, tree as ReactNode)\n\n return\n }\n\n clearSegments()\n handle.show(key, tree as ReactNode)\n })\n\n setRestoreHandler((key) => handle.restore(key))\n setReplaceRootHandler((tree) => handle.replace(tree as ReactNode))\n }, [handle])\n\n return (\n <>\n {entries.map((entry) => (\n <Activity key={entry.key} mode={entry.key === activeKey ? 'visible' : 'hidden'}>\n {entry.tree}\n </Activity>\n ))}\n </>\n )\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { useEffect } from "react";
3
- import { register } from "./changesStore";
3
+ import { register } from "./changesStore.js";
4
4
  /**
5
5
  * What a rendered region is live on, handed to the tab's watcher.
6
6
  *
@@ -1 +1 @@
1
- {"version":3,"file":"Changes.js","sourceRoot":"","sources":["../../src/js/Changes.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAC,EACtB,MAAM,EACN,KAAK,GAIN;IACC,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAElC,SAAS,CACP,GAAG,EAAE,CACH,QAAQ,CAAC;QACP,MAAM;QACN,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAqC;KAC3D,CAAC,EACJ,CAAC,MAAM,EAAE,GAAG,CAAC,CACd,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["\"use client\";\n\nimport { useEffect } from \"react\";\nimport { register } from \"./changesStore\";\n\n/**\n * What a rendered region is live on, handed to the tab's watcher.\n *\n * Renders nothing. Rendered by `RefreshOn` beside the region it describes,\n * so it arrives in the same payload - with the page, and again with the\n * region each time it is refreshed, carrying the versions that render saw.\n */\nexport function Changes({\n target,\n names,\n}: {\n target: string;\n names: Record<string, [number, string]>;\n}) {\n const key = JSON.stringify(names);\n\n useEffect(\n () =>\n register({\n target,\n names: JSON.parse(key) as Record<string, [number, string]>,\n }),\n [target, key],\n );\n\n return null;\n}\n"]}
1
+ {"version":3,"file":"Changes.js","sourceRoot":"","sources":["../../src/js/Changes.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAC,EACtB,MAAM,EACN,KAAK,GAIN;IACC,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAElC,SAAS,CACP,GAAG,EAAE,CACH,QAAQ,CAAC;QACP,MAAM;QACN,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAqC;KAC3D,CAAC,EACJ,CAAC,MAAM,EAAE,GAAG,CAAC,CACd,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["\"use client\";\n\nimport { useEffect } from \"react\";\nimport { register } from \"./changesStore.js\";\n\n/**\n * What a rendered region is live on, handed to the tab's watcher.\n *\n * Renders nothing. Rendered by `RefreshOn` beside the region it describes,\n * so it arrives in the same payload - with the page, and again with the\n * region each time it is refreshed, carrying the versions that render saw.\n */\nexport function Changes({\n target,\n names,\n}: {\n target: string;\n names: Record<string, [number, string]>;\n}) {\n const key = JSON.stringify(names);\n\n useEffect(\n () =>\n register({\n target,\n names: JSON.parse(key) as Record<string, [number, string]>,\n }),\n [target, key],\n );\n\n return null;\n}\n"]}
@@ -1,3 +1,3 @@
1
1
  import { type ReactNode } from "react";
2
- import type { RouteErrorProps } from "./RouteErrorBoundary";
2
+ import type { RouteErrorProps } from "./RouteErrorBoundary.js";
3
3
  export declare function DefaultRouteError({ error, reset, }: RouteErrorProps): ReactNode;
@@ -1 +1 @@
1
- {"version":3,"file":"DefaultRouteError.js","sourceRoot":"","sources":["../../src/js/DefaultRouteError.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,6DAA6D;AAC7D,EAAE;AACF,2EAA2E;AAC3E,6EAA6E;AAC7E,yEAAyE;AACzE,wEAAwE;AACxE,4DAA4D;AAC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,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IAE3E,OAAO,aAAa,CAClB,MAAM,EACN,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,oBAAoB,EAAE,EAAE,EAAE,EACvD,aAAa,CACX,IAAI,EACJ,EAAE,KAAK,EAAE,OAAO,EAAE,EAClB,GAAG,CAAC,CAAC,CAAC,iCAAiC,CAAC,CAAC,CAAC,sBAAsB,CACjE,EACD,GAAG;QACD,CAAC,CAAC,aAAa,CACX,KAAK,EACL,EAAE,KAAK,EAAE,GAAG,EAAE,EACd,KAAK,CAAC,KAAK,IAAI,IAAI,GAAG,KAAK,CAAC,OAAO,CACpC;QACH,CAAC,CAAC,aAAa,CACX,GAAG,EACH,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE;QACxB,oEAAoE;QACpE,mEAAmE;QACnE,iEAAiE;QACjE,wCAAwC;QACxC,KAAK,CAAC,MAAM;YACV,CAAC,CAAC,wCAAwC,GAAG,KAAK,CAAC,MAAM,GAAG,GAAG;YAC/D,CAAC,CAAC,8CAA8C,CACnD,EACL,GAAG;QACD,CAAC,CAAC,aAAa,CACX,GAAG,EACH,EAAE,KAAK,EAAE,IAAI,EAAE,EACf,sEAAsE,CACvE;QACH,CAAC,CAAC,IAAI,EACR,aAAa,CACX,QAAQ,EACR,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,EACjD,WAAW,CACZ,CACF,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\n\n// What a page that throws shows when no error.tsx covers it.\n//\n// Without this, nothing did: the Flight row failed, the browser rethrew on\n// hydration with no boundary to catch it, and React unmounted the document -\n// a black page with the cause nowhere near it. Next shows its overlay in\n// development and a plain \"something went wrong\" in production; this is\n// that, as a page, and the layouts above it stay on screen.\n//\n// In development the message and stack, because the developer is the one\n// looking. In production React has already replaced the message with a\n// digest, and the digest is what this shows: the line to search the server\n// log for.\n\nimport { createElement, type ReactNode } from \"react\";\nimport type { RouteErrorProps } from \"./RouteErrorBoundary\";\n\n// `import.meta.env.DEV` as Vite spells it, so the build replaces the whole\n// expression with a literal. A `typeof import.meta` guard in front of it\n// survived the build as a bare `import.meta` in the ssr chunk - the one\n// thing Bun cannot lower when it compiles a binary's bytecode, so\n// `--bytecode` failed on this file - and guarded nothing: where import.meta\n// does not exist, a typeof of it does not parse either.\nconst DEV = Boolean(import.meta.env.DEV);\n\nconst mono = \"ui-monospace,SFMono-Regular,Menlo,monospace\";\nconst box = {\n maxWidth: \"60rem\",\n margin: \"3rem auto\",\n padding: \"1.5rem\",\n font: \"14px/1.5 \" + mono,\n color: \"#fecaca\",\n background: \"#1f0b0b\",\n border: \"1px solid #7f1d1d\",\n borderRadius: 8,\n};\nconst heading = {\n margin: \"0 0 .75rem\",\n fontSize: 16,\n fontWeight: 600,\n color: \"#fff\",\n};\nconst pre = {\n whiteSpace: \"pre-wrap\" as const,\n wordBreak: \"break-word\" as const,\n margin: \".75rem 0 0\",\n color: \"#fecaca\",\n};\nconst hint = { margin: \".75rem 0 0\", color: \"#fca5a5\" };\nconst button = {\n marginTop: \"1rem\",\n padding: \".4rem .8rem\",\n border: \"1px solid #fca5a5\",\n borderRadius: 6,\n background: \"transparent\",\n color: \"#fff\",\n cursor: \"pointer\",\n font: \"inherit\",\n};\n\nexport function DefaultRouteError({\n error,\n reset,\n}: RouteErrorProps): ReactNode {\n const name = error.name && error.name !== \"Error\" ? error.name + \": \" : \"\";\n\n return createElement(\n \"main\",\n { role: \"alert\", style: box, \"data-rsc-kit-error\": \"\" },\n createElement(\n \"h1\",\n { style: heading },\n DEV ? \"This page threw while rendering\" : \"Something went wrong\",\n ),\n DEV\n ? createElement(\n \"pre\",\n { style: pre },\n error.stack || name + error.message,\n )\n : createElement(\n \"p\",\n { style: { margin: 0 } },\n // A digest is a server error's: React replaced the message with it,\n // and the server log has the rest. Without one nothing reached the\n // server - a client reference the page could not load, say - and\n // the console is where it was reported.\n error.digest\n ? \"The error was logged on the server as \" + error.digest + \".\"\n : \"The error was logged in the browser console.\",\n ),\n DEV\n ? createElement(\n \"p\",\n { style: hint },\n \"Add an error.tsx beside the page to show something of your own here.\",\n )\n : null,\n createElement(\n \"button\",\n { type: \"button\", style: button, onClick: reset },\n \"Try again\",\n ),\n );\n}\n"]}
1
+ {"version":3,"file":"DefaultRouteError.js","sourceRoot":"","sources":["../../src/js/DefaultRouteError.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,6DAA6D;AAC7D,EAAE;AACF,2EAA2E;AAC3E,6EAA6E;AAC7E,yEAAyE;AACzE,wEAAwE;AACxE,4DAA4D;AAC5D,EAAE;AACF,yEAAyE;AACzE,uEAAuE;AACvE,2EAA2E;AAC3E,WAAW;AAEX,OAAO,EAAE,aAAa,EAAkB,MAAM,OAAO,CAAC;AAGtD,2EAA2E;AAC3E,yEAAyE;AACzE,wEAAwE;AACxE,kEAAkE;AAClE,4EAA4E;AAC5E,wDAAwD;AACxD,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAEzC,MAAM,IAAI,GAAG,6CAA6C,CAAC;AAC3D,MAAM,GAAG,GAAG;IACV,QAAQ,EAAE,OAAO;IACjB,MAAM,EAAE,WAAW;IACnB,OAAO,EAAE,QAAQ;IACjB,IAAI,EAAE,WAAW,GAAG,IAAI;IACxB,KAAK,EAAE,SAAS;IAChB,UAAU,EAAE,SAAS;IACrB,MAAM,EAAE,mBAAmB;IAC3B,YAAY,EAAE,CAAC;CAChB,CAAC;AACF,MAAM,OAAO,GAAG;IACd,MAAM,EAAE,YAAY;IACpB,QAAQ,EAAE,EAAE;IACZ,UAAU,EAAE,GAAG;IACf,KAAK,EAAE,MAAM;CACd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M;YACV,CAAC,CAAC,wCAAwC,GAAG,KAAK,CAAC,MAAM,GAAG,GAAG;YAC/D,CAAC,CAAC,8CAA8C,CACnD,EACL,GAAG;QACD,CAAC,CAAC,aAAa,CACX,GAAG,EACH,EAAE,KAAK,EAAE,IAAI,EAAE,EACf,sEAAsE,CACvE;QACH,CAAC,CAAC,IAAI,EACR,aAAa,CACX,QAAQ,EACR,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,EACjD,WAAW,CACZ,CACF,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\n\n// What a page that throws shows when no error.tsx covers it.\n//\n// Without this, nothing did: the Flight row failed, the browser rethrew on\n// hydration with no boundary to catch it, and React unmounted the document -\n// a black page with the cause nowhere near it. Next shows its overlay in\n// development and a plain \"something went wrong\" in production; this is\n// that, as a page, and the layouts above it stay on screen.\n//\n// In development the message and stack, because the developer is the one\n// looking. In production React has already replaced the message with a\n// digest, and the digest is what this shows: the line to search the server\n// log for.\n\nimport { createElement, type ReactNode } from \"react\";\nimport type { RouteErrorProps } from \"./RouteErrorBoundary.js\";\n\n// `import.meta.env.DEV` as Vite spells it, so the build replaces the whole\n// expression with a literal. A `typeof import.meta` guard in front of it\n// survived the build as a bare `import.meta` in the ssr chunk - the one\n// thing Bun cannot lower when it compiles a binary's bytecode, so\n// `--bytecode` failed on this file - and guarded nothing: where import.meta\n// does not exist, a typeof of it does not parse either.\nconst DEV = Boolean(import.meta.env.DEV);\n\nconst mono = \"ui-monospace,SFMono-Regular,Menlo,monospace\";\nconst box = {\n maxWidth: \"60rem\",\n margin: \"3rem auto\",\n padding: \"1.5rem\",\n font: \"14px/1.5 \" + mono,\n color: \"#fecaca\",\n background: \"#1f0b0b\",\n border: \"1px solid #7f1d1d\",\n borderRadius: 8,\n};\nconst heading = {\n margin: \"0 0 .75rem\",\n fontSize: 16,\n fontWeight: 600,\n color: \"#fff\",\n};\nconst pre = {\n whiteSpace: \"pre-wrap\" as const,\n wordBreak: \"break-word\" as const,\n margin: \".75rem 0 0\",\n color: \"#fecaca\",\n};\nconst hint = { margin: \".75rem 0 0\", color: \"#fca5a5\" };\nconst button = {\n marginTop: \"1rem\",\n padding: \".4rem .8rem\",\n border: \"1px solid #fca5a5\",\n borderRadius: 6,\n background: \"transparent\",\n color: \"#fff\",\n cursor: \"pointer\",\n font: \"inherit\",\n};\n\nexport function DefaultRouteError({\n error,\n reset,\n}: RouteErrorProps): ReactNode {\n const name = error.name && error.name !== \"Error\" ? error.name + \": \" : \"\";\n\n return createElement(\n \"main\",\n { role: \"alert\", style: box, \"data-rsc-kit-error\": \"\" },\n createElement(\n \"h1\",\n { style: heading },\n DEV ? \"This page threw while rendering\" : \"Something went wrong\",\n ),\n DEV\n ? createElement(\n \"pre\",\n { style: pre },\n error.stack || name + error.message,\n )\n : createElement(\n \"p\",\n { style: { margin: 0 } },\n // A digest is a server error's: React replaced the message with it,\n // and the server log has the rest. Without one nothing reached the\n // server - a client reference the page could not load, say - and\n // the console is where it was reported.\n error.digest\n ? \"The error was logged on the server as \" + error.digest + \".\"\n : \"The error was logged in the browser console.\",\n ),\n DEV\n ? createElement(\n \"p\",\n { style: hint },\n \"Add an error.tsx beside the page to show something of your own here.\",\n )\n : null,\n createElement(\n \"button\",\n { type: \"button\", style: button, onClick: reset },\n \"Try again\",\n ),\n );\n}\n"]}
package/dist/js/Form.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { Route } from "../routes.js";
2
2
  import { type FormHTMLAttributes, type ReactNode, type Ref } from "react";
3
- import type { FormStore } from "./formStore";
4
- import type { StandardSchemaV1 } from "./standardSchema";
3
+ import type { FormStore } from "./formStore.js";
4
+ import type { StandardSchemaV1 } from "./standardSchema.js";
5
5
  type PrefetchStrategy = "hover" | "mount" | "none";
6
6
  /**
7
7
  * What `field(name)` hands a control, spread straight onto it.
package/dist/js/Form.js CHANGED
@@ -1,11 +1,11 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useActionState, useState, useSyncExternalStore, useTransition, } from "react";
4
- import { submitForm } from "../formSubmit";
5
- import { ActionRefusedError, ServerValidationError, ServerDumpError, ServerRedirectError, redirectedTo } from "./errors";
6
- import { buildFormData, decodeFormData } from "./formEncoding";
7
- import { createFormStore } from "./formStore";
8
- import { validateWith } from "./standardSchema";
4
+ import { submitForm } from "../formSubmit.js";
5
+ import { ActionRefusedError, ServerValidationError, ServerDumpError, ServerRedirectError, redirectedTo } from "./errors.js";
6
+ import { buildFormData, decodeFormData } from "./formEncoding.js";
7
+ import { createFormStore } from "./formStore.js";
8
+ import { validateWith } from "./standardSchema.js";
9
9
  /**
10
10
  * How long a blur that leaves the form waits before checking the field. A
11
11
  * dialog's exit animation is shorter than this; a form still on screen after
@@ -1 +1 @@
1
- {"version":3,"file":"Form.js","sourceRoot":"","sources":["../../src/js/Form.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAGb,OAAO,EAKL,aAAa,EACb,WAAW,EACX,UAAU,EACV,SAAS,EACT,eAAe,EACf,OAAO,EACP,MAAM,EACN,cAAc,EACd,QAAQ,EACR,oBAAoB,EACpB,aAAa,GACd,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,eAAe,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACzH,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGhD;;;;GAIG;AACH,MAAM,oBAAoB,GAAG,GAAG,CAAC;AA0SjC;;;;;;GAMG;AACH,SAAS,QAAQ,CACf,KAAc;IAEd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cesContent":["\"use client\";\n\nimport type { Route } from \"../routes.js\";\nimport {\n type FormHTMLAttributes,\n type FormEvent,\n type ReactNode,\n type Ref,\n createContext,\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useActionState,\n useState,\n useSyncExternalStore,\n useTransition,\n} from \"react\";\nimport { submitForm } from \"../formSubmit\";\nimport { ActionRefusedError, ServerValidationError, ServerDumpError, ServerRedirectError, redirectedTo } from \"./errors\";\nimport { buildFormData, decodeFormData } from \"./formEncoding\";\nimport { createFormStore } from \"./formStore\";\nimport type { FormStore } from \"./formStore\";\nimport { validateWith } from \"./standardSchema\";\nimport type { StandardSchemaV1 } from \"./standardSchema\";\n\n/**\n * How long a blur that leaves the form waits before checking the field. A\n * dialog's exit animation is shorter than this; a form still on screen after\n * it is one somebody is looking at.\n */\nconst LEAVE_FORM_SETTLE_MS = 300;\n\ntype PrefetchStrategy = \"hover\" | \"mount\" | \"none\";\n\n/**\n * What `field(name)` hands a control, spread straight onto it.\n *\n * The same four things react-hook-form's `<Controller>` gives, because it is\n * the same job: a component with no native control behind it needs a value and\n * a way to report a new one.\n */\ninterface FieldBinding<V> {\n name: string;\n value: V;\n /**\n * Either shape: a DOM event, or the value itself.\n *\n * A native input passes the event; a Radix select or a rich editor passes\n * what was chosen. A binder understanding only one of them would work on\n * half the controls anyone actually uses.\n */\n onChange: (next: V | { target: { value: V } }) => void;\n onBlur: () => void;\n}\n\n/**\n * A field's name: one the form declared, suggested by the editor - or any\n * path, because a nested or indexed field (`address.city`, `items[0].name`)\n * is a real name no defaultValues object can declare. The typo that matters\n * is caught on `field()`, which is closed to the declared names.\n */\ntype FieldPath<T> = (keyof T & string) | (string & {});\n\n/** Dots deep, so a self-referential or very wide input type cannot run the compiler out. */\ntype Depth = [never, 0, 1, 2, 3];\n\n/**\n * Every name an error can be filed under in a value: its keys, a nested object's\n * `address.city`, and a list's `items.0.sku` - the shape a Standard Schema\n * issue and a backend's validation both produce.\n */\ntype Paths<T, D extends number = 3> = [D] extends [never]\n ? never\n : T extends readonly (infer U)[]\n ? `${number}` | `${number}.${Paths<U, Depth[D]>}`\n : T extends object\n ? { [K in keyof T & string]: K | (T[K] extends object ? `${K}.${Paths<T[K], Depth[D]>}` : never) }[keyof T & string]\n : never;\n\n/**\n * What an action takes, read off the action: a generated stub's typed overload,\n * or the input of one built with `createActionClient().input(schema)`. Unknown\n * when it does not say - a url, or a function of a FormData - and then nothing\n * is claimed about its fields.\n */\ntype InputOfAction<A> = [A] extends [never]\n ? unknown // `action={signup as never}`: a cast says nothing about the input\n : 0 extends 1 & A\n ? unknown // any\n : A extends { (input: infer I): Promise<unknown>; (form: FormData): Promise<unknown> }\n ? Described<I>\n : A extends (input: infer I) => Promise<unknown>\n ? Described<I>\n : unknown;\n\n/** An action's parameter, without the FormData a form posts it as; unknown if that was all it said. */\ntype Described<I> = [Exclude<I, FormData | undefined>] extends [never] ? unknown : Exclude<I, FormData | undefined>;\n\ndeclare const NAMES: unique symbol;\n\n/**\n * A form's FormData, naming its fields.\n *\n * For an action the app writes that takes a form and passes it on - to a stub\n * whose parameters are plain strings, say - which says nothing of its fields to\n * anything reading its type. Declared on the parameter, where the names live\n * with the code that reads them:\n *\n * export async function createApp(form: FormFields<'name' | 'region'>) {\n * return await appsCreate(String(form.get('name')), String(form.get('region')))\n * }\n *\n * and `<Form action={createApp}>` closes `error()` to those names. Nothing runs:\n * it is a FormData, and every FormData is one. The names are a claim the types\n * keep, not a check the browser makes.\n */\nexport interface FormFields<Name extends string> extends FormData {\n readonly [NAMES]?: Name;\n}\n\n/** The names a form-taking action declared with FormFields, or never when it did not. */\ntype DeclaredNames<A> = A extends (form: FormFields<infer N>, ...rest: never[]) => Promise<unknown>\n ? string extends N\n ? never\n : N\n : never;\n\n/**\n * The names an action's validation can be read under, for `error()` and\n * `clearErrors()`: the input's own paths, the names a wrapper declared, and the\n * form's declared values.\n *\n * Closed when the action says what it takes, so `error('nmae')` fails the\n * typecheck rather than showing nothing, ever. Open, as it always was, when it\n * does not - a field is only a typo if something could have said so.\n */\ntype FieldNameOf<T, A, F extends string = never> = [F] extends [never]\n ? unknown extends InputOfAction<A>\n ? [DeclaredNames<A>] extends [never]\n ? FieldPath<T>\n : DeclaredKeys<T> | DeclaredNames<A>\n : DeclaredKeys<T> | Paths<InputOfAction<A>> | DeclaredNames<A>\n : // Named on the form itself: closed to these, beside everything else that names a field.\n F | DeclaredKeys<T> | DeclaredNames<A> | (unknown extends InputOfAction<A> ? never : Paths<InputOfAction<A>>);\n\n/** The form's declared values count - but T is the open record when it declared none, and all of `string` is not a name. */\ntype DeclaredKeys<T> = string extends keyof T ? never : keyof T & string;\n\n/** The field names an action's validation can name, for a component below a form to type. */\nexport type FieldNamesOf<A> = unknown extends InputOfAction<A>\n ? [DeclaredNames<A>] extends [never]\n ? string\n : DeclaredNames<A>\n : Paths<InputOfAction<A>> | DeclaredNames<A>;\n\ninterface FormRenderProps<\n T extends Record<string, unknown> = Record<string, unknown>,\n Refusal = unknown,\n Name extends string = FieldPath<T>,\n> {\n pending: boolean;\n /** What is being submitted, while it is. */\n data: T;\n /**\n * A field's error, or undefined: the one way to read one.\n *\n * {error('title') && <p>{error('title')}</p>}\n * <Field data-invalid={!!error('title')}>\n *\n * Nested paths join with dots - `error('address.city')`, the key a Standard\n * Schema issue for that field produces. A field is checked when it is left\n * and when the form is submitted, so an error never appears on a field\n * nobody has reached yet.\n */\n error: (field: Name) => string | undefined;\n /**\n * The refusal that is not about a field: the action's `serverError` - a\n * 402, a 409, \"that slot was just taken\" - or a validation message for the\n * form as a whole. Undefined otherwise. Cleared by the next submit, by a\n * success, and by `clearErrors()` and `reset()`, like a field's.\n *\n * {formError && <p role=\"alert\">{formError}</p>}\n *\n * Only what the action returned: a failure thrown on the way, the network\n * or a crash, goes to `onError` as before, where a production message is\n * React's stand-in and not something to show.\n */\n formError: string | undefined;\n /**\n * What the action's refusal carried beside `formError` - the records\n * blocking a delete, say - when the action refused with `refuse()` and\n * declared its shape with `.refusal(schema)`. Typed from the form's\n * `action` in its render prop; in a component below, `useForm<T, R>()`.\n * Goes when `formError` does.\n */\n formRefusal: Refusal | undefined;\n clearErrors: (...fields: Name[]) => void;\n reset: () => void;\n /**\n * Whether anything differs from what the form started with.\n *\n * For the Save button that stays quiet until there is something to save,\n * and the Discard that appears beside it. Read from the form itself - a\n * snapshot of its FormData on mount, compared on every input - so an\n * uncontrolled field counts, which nothing outside the form can do. A\n * successful submit makes the current values the new baseline; `reset()`\n * goes back to the first one.\n */\n dirty: boolean;\n /** Whether the last submit was accepted. */\n succeeded: boolean;\n /**\n * The same thing, for two seconds.\n *\n * The \"Saved ✓\" that appears and fades. Worth having as state rather than a\n * timer in every form that wants one, because the timer has to be cleared\n * when the component goes away and that is the part people forget.\n */\n recentlySucceeded: boolean;\n /**\n * Bind one field so this component holds its value.\n *\n * Most fields need nothing: they are uncontrolled, the DOM holds the value,\n * and it is read back as FormData on submit. Reach for this when the DOM\n * cannot hold it for you — a control with no native element behind it, or a\n * value you want to read as it is typed:\n *\n * <Input {...field('title')} />\n * <span>{field('body').value.length}/100</span>\n *\n * A bound field is still an ordinary named input, so it arrives in FormData\n * with everything else. Nothing merges; there is one source of truth.\n */\n field: <K extends keyof T & string>(name: K) => FieldBinding<T[K]>;\n}\n\n/** What a form can submit to: a url, or a server action. */\ntype FormAction = Route | ((formData: FormData) => Promise<unknown>);\n\n/**\n * What the action's refusal carries, read off the action itself - its\n * `.refusal(schema)` - so `formRefusal` is typed without a cast. Unknown for a\n * url, or for an action that does not say.\n */\ntype RefusalOf<A> = A extends (...args: never[]) => Promise<infer R>\n ? R extends { refusal?: infer F }\n ? F\n : unknown\n : unknown;\n\ninterface FormProps<\n T extends Record<string, unknown> = Record<string, unknown>,\n A extends FormAction = FormAction,\n F extends string = never,\n> extends Omit<\n FormHTMLAttributes<HTMLFormElement>,\n \"action\" | \"method\" | \"children\" | \"onSubmit\" | \"onError\"\n> {\n action: A;\n method?: \"get\" | \"post\";\n /**\n * The <form> element, for a caller that needs it - to focus, to scroll to,\n * to hand a library. The form keeps its own handle beside it; a caller's\n * never replaces it.\n */\n ref?: Ref<HTMLFormElement>;\n /**\n * Starting values for fields bound with `field()`.\n *\n * Uncontrolled fields do not need this — they take React's own\n * `defaultValue`, and the DOM keeps whatever is typed into them.\n */\n defaultValues?: Partial<T>;\n /**\n * The names `error()` and `clearErrors()` may be asked for, when nothing else\n * says: a form that posts nothing (its values live in React state, or it is a\n * button) has no FormData for an action to declare them on.\n *\n * <Form action={resize} fields={['size', 'copies']}>\n * {({ error }) => error('size')} // error('sise') fails the typecheck\n *\n * Types only: nothing is checked in the browser, and a name is a claim about\n * what the action's validation reports. Closes the set; names the action's own\n * input or `FormFields` declare, and `defaultValues` keys, are in it too.\n */\n fields?: readonly F[];\n /**\n * A store created above this form, from `useFormStore()`.\n *\n * For the one case the context cannot reach: something that is not a\n * descendant — a top bar showing unsaved changes, a sidebar preview — needs\n * the values to exist above both of them. Create the store where they share\n * an ancestor and hand it down.\n *\n * Without it the form makes its own, which is what almost every form wants.\n */\n store?: FormStore;\n prefetch?: PrefetchStrategy;\n cacheFor?: number;\n replace?: boolean;\n preserveScroll?: boolean;\n resetOnSuccess?: boolean;\n /**\n * Check the fields before submitting, with any Standard Schema — Zod,\n * Valibot, ArkType.\n *\n * A failure fills `errors` and the action is never called, so a mistake\n * costs no round trip. It is a courtesy and not a control: the same action\n * is reachable without this form, so the server still has to check.\n */\n schema?: StandardSchemaV1;\n /** Transform form data before submitting to the server action. */\n transform?: (data: T) => Record<string, unknown>;\n /** Called inside the transition with typed form data. Use it to call your useOptimistic setter. */\n optimistic?: (data: T) => void;\n onSuccess?: (result: unknown) => void;\n /**\n * Called when a submit does not succeed.\n *\n * Validation failures arrive as field errors, with no second argument.\n * Anything else arrives as an empty error map and the thrown value — there\n * are no field errors to report, but the form still has to say so.\n */\n onError?: (errors: Record<string, string[]>, error?: unknown) => void;\n onSubmit?: (formData: FormData) => void | false;\n children: ReactNode | ((form: FormRenderProps<T, RefusalOf<A>, FieldNameOf<T, A, F>>) => ReactNode);\n}\n\n/**\n * What an action built with createActionClient answers with.\n *\n * Recognised rather than thrown, because React serialises a rejected server\n * action opaquely: production strips the message and the fields it named are\n * gone. A returned object crosses intact, so a form reads it.\n */\nfunction resultOf(\n value: unknown,\n): { errors?: Record<string, string[]>; serverError?: string; refusal?: unknown; redirected?: string } | null {\n if (typeof value !== \"object\" || value === null) return null;\n\n const result = value as {\n validationErrors?: Record<string, string[]>;\n serverError?: string;\n refusal?: unknown;\n redirected?: string;\n };\n\n if (result.validationErrors) return { errors: result.validationErrors };\n if (result.serverError) return { serverError: result.serverError, refusal: result.refusal };\n if (typeof result.redirected === \"string\") return { redirected: result.redirected };\n\n return null;\n}\n\nconst FormStatusContext = createContext<FormRenderProps>({\n pending: false,\n data: {},\n dirty: false,\n error: () => undefined,\n formError: undefined,\n formRefusal: undefined,\n clearErrors: () => {},\n reset: () => {},\n succeeded: false,\n recentlySucceeded: false,\n // Outside a Form there is nothing holding a value, so a binding that reported\n // one would be lying. Name only, which is the part that is still true.\n field: ((name: string) => ({\n name,\n value: \"\",\n onChange: () => {},\n onBlur: () => {},\n })) as FormRenderProps[\"field\"],\n});\n\n/**\n * The store, on its own context.\n *\n * Separate from the status context because that one holds a fresh object every\n * render, so anything reading it re-renders with the form. The store is stable\n * for the life of the form, which is what lets a subscriber below it re-render\n * alone.\n */\nconst FormStoreContext = createContext<{\n store: FormStore;\n touch: (name: string) => void;\n} | null>(null);\n\n/**\n * A value store created above the form rather than by it.\n *\n * const store = useFormStore({ title: '' })\n *\n * <TopBar store={store} /> // not inside the form\n * <Form action={save} store={store}>…</Form>\n *\n * For the one case the context cannot reach. `<Form>` makes its own otherwise,\n * and almost every form should let it — this exists so that a component which\n * is not a descendant can still read the values, which is the flexibility\n * react-hook-form and TanStack Form get from `useForm()` being yours to call.\n *\n * Deliberately not reactive itself: creating the store does not subscribe to\n * it, so the component holding it does not re-render on every keystroke and\n * take the whole subtree with it. Read a field from it with `useField(name, store)`.\n */\nexport function useFormStore<T extends Record<string, unknown>>(\n initial: Partial<T> = {},\n): FormStore {\n const ref = useRef<FormStore | null>(null);\n\n ref.current ??= createFormStore({ ...initial });\n\n return ref.current;\n}\n\n/**\n * The form this component is inside: the same object `<Form>`'s render prop\n * gets, so a field split into its own component is written exactly as it\n * was inline.\n *\n * function Title() {\n * const { field, error } = useForm()\n *\n * return (\n * <>\n * <input name=\"title\" />\n * {error('title') && <p>{error('title')}</p>}\n * </>\n * )\n * }\n *\n * Not React's `useFormStatus`, which is a different hook with a different\n * answer - which is why this one is not called that.\n */\nexport function useForm<\n T extends Record<string, unknown> = Record<string, unknown>,\n Refusal = unknown,\n>(): FormRenderProps<T, Refusal> {\n return useContext(FormStatusContext) as FormRenderProps<T, Refusal>;\n}\n\n/**\n * One field, subscribed on its own - for a large controlled form.\n *\n * The same two words as everywhere else, for one name: `field` to spread,\n * `error` to show. The component re-renders when this field changes and at no\n * other time, where `useForm()` re-renders with the whole form. Reach for it\n * when re-rendering all of a form per keystroke is real:\n *\n * function Title() {\n * const { field, error } = useField('title')\n *\n * return <Input {...field} aria-invalid={!!error} />\n * }\n *\n * Given a store, it reads a form from outside it - see useFormStore.\n */\nexport function useField(\n name: string,\n store?: FormStore,\n): { field: FieldBinding<string>; error: string | undefined } {\n const ctx = useContext(FormStoreContext);\n const status = useContext(FormStatusContext);\n\n if (!ctx && !store) {\n throw new Error(\n \"useField() was called outside a <Form>. It reads that form's values, so there has to be one above it.\",\n );\n }\n\n const source = store ?? ctx!.store;\n const touch = ctx?.touch;\n\n const value = useSyncExternalStore(\n source.subscribe,\n () => (source.get(name) ?? \"\") as string,\n () => \"\",\n );\n\n return {\n field: {\n name,\n value,\n onChange: (next) => {\n source.set(\n name,\n typeof next === \"object\" && next !== null && \"target\" in next\n ? (next as { target: { value: string } }).target.value\n : next,\n );\n },\n onBlur: () => void touch?.(name),\n },\n error: status.error(name as never),\n };\n}\n\n/**\n * submitForm bound to an action, once per action.\n *\n * Bound on every render, it was a fresh function with a fresh promise for\n * its bound arguments each time - and React, seating a posted form's state\n * during the server render, suspends on that promise until it settles, then\n * renders the component again, which bound again. A render that never\n * finished, on every page a form was posted to without javascript. One\n * bound function per action, and the promise settles once.\n */\nconst boundSubmits = new WeakMap<Function, (previous: unknown, formData: FormData) => Promise<unknown>>();\n\nfunction boundSubmit(action: (formData: FormData) => Promise<unknown>) {\n let bound = boundSubmits.get(action);\n\n if (!bound) {\n bound = submitForm.bind(null, action);\n boundSubmits.set(action, bound);\n }\n\n return bound;\n}\n\n/**\n * A form's values as one comparable string.\n *\n * FormData in document order, a file by its name and size: enough to say\n * whether anything changed, which is all `dirty` asks.\n */\n/** Whether a GET form's action is the page on screen, whatever query it carries. */\nfunction isThisPage(action: string): boolean {\n return new URL(action, window.location.origin).pathname === window.location.pathname;\n}\n\nfunction serializeForm(form: HTMLFormElement): string {\n const parts: string[] = [];\n\n for (const [name, value] of new FormData(form)) {\n parts.push(\n name + \"=\" + (typeof value === \"string\" ? value : \"file:\" + value.name + \":\" + value.size),\n );\n }\n\n return parts.join(\"\\n\");\n}\n\n/**\n * Also exported by name, and re-exported below, because both spellings are in\n * use: `import Form from` and `import { Form } from`.\n */\nexport default function Form<\n T extends Record<string, unknown> = Record<string, unknown>,\n A extends FormAction = FormAction,\n const F extends string = never,\n>({\n action,\n method: methodProp,\n defaultValues,\n // A type-level claim only. Named so it is not passed on to the <form>.\n fields: _fields,\n store: providedStore,\n prefetch = \"hover\",\n cacheFor,\n replace = false,\n preserveScroll = false,\n resetOnSuccess = true,\n schema,\n transform,\n optimistic,\n onSuccess,\n onError,\n onSubmit,\n children,\n ref: callerRef,\n ...rest\n}: FormProps<T, A, F>) {\n void _fields;\n const isGetForm = typeof action === \"string\";\n const method = methodProp ?? (isGetForm ? \"get\" : \"post\");\n\n // The answer to this form posted without a runtime, seated by React into\n // the form that posted it - which is the only way a visitor with no\n // javascript sees a refusal. Registered through submitForm, bound to the\n // action, because React hands a form-state action a (previous, formData)\n // pair and the action takes the FormData alone. On the server a plain\n // function - a closure, not a server reference - cannot be bound into a\n // form; the form falls back to the action itself, and posts nothing\n // seatable, which is all a closure could ever have done.\n const bindable =\n typeof action === \"function\" && (typeof window !== \"undefined\" || \"$$FORM_ACTION\" in action);\n const [posted, formAction] = useActionState(\n bindable ? boundSubmit(action as (formData: FormData) => Promise<unknown>) : async () => null,\n null as unknown,\n );\n const postedRefusal = resultOf(posted);\n const [errors, setErrors] = useState<Record<string, string[]>>(() => postedRefusal?.errors ?? {});\n // A refusal's data, tied to the exact form-level error it came with: when\n // that entry is cleared or replaced - the next submit, a success,\n // clearErrors() - the data goes with it, without every place that touches\n // the errors having to know.\n const [refusal, setRefusal] = useState<{ for: string[]; data: unknown } | null>(null);\n const [touched, setTouched] = useState<Record<string, boolean>>({});\n\n /**\n * Mark a field visited, and check it.\n *\n * Checking on blur rather than on every keystroke, because an error that\n * appears while someone is halfway through typing an email address is a form\n * arguing with them. Leaving the field is the moment they have finished\n * saying what they meant.\n *\n * The whole object is validated and only this field's issues are kept: a\n * Standard Schema has no notion of one field, and filtering by path is the\n * honest way to ask it about one. Everything else's errors are left as they\n * were, so blurring an empty field does not light up the rest of the form.\n */\n const touch = useCallback(\n async (name: string) => {\n setTouched((prev) => (prev[name] ? prev : { ...prev, [name]: true }));\n\n if (!schema || !formRef.current) return;\n\n const invalid = await validateWith(\n schema,\n decodeFormData(new FormData(formRef.current), schema),\n );\n\n setErrors((prev) => {\n const next = { ...prev };\n\n if (invalid?.[name]) next[name] = invalid[name];\n else delete next[name];\n\n return next;\n });\n },\n [schema],\n );\n\n const [succeeded, setSucceeded] = useState(false);\n const [recentlySucceeded, setRecentlySucceeded] = useState(false);\n const recentTimer = useRef<ReturnType<typeof setTimeout> | undefined>(\n undefined,\n );\n\n // Cleared on unmount: a timer that fires into a component that has gone is\n // the warning nobody reads and the leak nobody finds.\n useEffect(() => () => clearTimeout(recentTimer.current), []);\n\n // Only the fields someone bound. Everything else is the DOM's.\n //\n // A store rather than state, so a component using `useField` can re-render\n // for one field while this one does not. See formStore.ts.\n const storeRef = useRef<FormStore | null>(null);\n\n storeRef.current ??= createFormStore({\n ...(defaultValues as Record<string, unknown> | undefined),\n });\n\n const store = providedStore ?? storeRef.current;\n\n // Which names the render prop read through `field()`. A change to one of\n // those has to re-render this component, because that is where the value is\n // being displayed; a change to anything else does not, which is what lets a\n // `useField` child stand on its own.\n const readHere = useRef(new Set<string>());\n const [, bump] = useState(0);\n\n useEffect(\n () =>\n store.subscribe((name) => {\n if (name === \"\" || readHere.current.has(name)) bump((n) => n + 1);\n }),\n [store],\n );\n const [currentData, setCurrentData] = useState<T>({} as T);\n const [isPending, startTransition] = useTransition();\n const formRef = useRef<HTMLFormElement>(null);\n // Read by the delayed blur check, which runs after the render that set it:\n // the value its closure captured is the one from before the submit began.\n const pendingRef = useRef(false);\n pendingRef.current = isPending;\n\n // A reset owed by a successful submit, performed in the commit that ends\n // it. The action resolves a tick before React commits its transition - the\n // result, whatever the action revalidated, pending going false - and a\n // reset done on resolve was a DOM write with a frame of its own: a chat's\n // composer emptied before the reply it was answered with appeared. In a\n // layout effect of the commit where pending turns false, it lands in the\n // same frame as the result, before the browser paints.\n const resetOwed = useRef<{ result: unknown } | null>(null);\n\n // What the form started with, as its FormData reads: the baseline `dirty`\n // is measured against. Taken on mount, retaken after a successful submit.\n const baseline = useRef<string | null>(null);\n const [dirty, setDirty] = useState(false);\n // Only a form that reads `dirty` pays for it: the flip from clean to dirty\n // is a render of the whole form, and a field that subscribes for itself\n // is promised that typing in it renders it alone.\n const dirtyRead = useRef(false);\n\n const snapshot = useCallback(() => {\n if (!formRef.current) return;\n\n baseline.current = serializeForm(formRef.current);\n setDirty(false);\n }, []);\n\n const measureDirty = useCallback(() => {\n if (!dirtyRead.current || !formRef.current || baseline.current === null) return;\n\n const now = serializeForm(formRef.current) !== baseline.current;\n\n setDirty((was) => (was === now ? was : now));\n }, []);\n\n useEffect(snapshot, [snapshot]);\n\n // A bound control with no native element behind it changes through the\n // store, not through an input event - a Radix select - so the store is\n // watched too. Its input, if it has one, is read back with the rest. In\n // a microtask: the fields subscribed before this effect ran, so React's\n // own flush of their update is queued ahead of the measure, and the\n // element is read after it was written.\n useEffect(() => store.subscribe(() => queueMicrotask(measureDirty)), [store, measureDirty]);\n\n // A reset writes every bound field at once, through a render of this\n // component; the measure has to read the elements after that commit,\n // and a microtask queued during the reset ran before it. Marked here,\n // measured by the effect below once the render lands.\n const remeasure = useRef(false);\n\n useEffect(() => {\n if (!remeasure.current) return;\n\n remeasure.current = false;\n measureDirty();\n });\n\n useLayoutEffect(() => {\n const owed = resetOwed.current;\n\n if (!owed || isPending) return;\n\n resetOwed.current = null;\n store.reset();\n formRef.current?.reset();\n setTouched({});\n setCurrentData({} as T);\n snapshot();\n // After the reset, as it always ran: an onSuccess that fills or focuses a\n // field must not have the reset undo it.\n onSuccess?.(owed.result);\n });\n\n // Both handles, one element. React 19 hands a function component its ref\n // as a prop, and spread after the form's own it replaced it - every\n // FormData read then found null. A caller's ref is filled beside ours.\n const attachForm = useCallback(\n (element: HTMLFormElement | null) => {\n formRef.current = element;\n\n if (typeof callerRef === \"function\") callerRef(element);\n else if (callerRef) callerRef.current = element;\n },\n [callerRef],\n );\n\n const error = useCallback(\n (field: FieldPath<T>): string | undefined => errors[field]?.[0],\n [errors],\n );\n\n const clearErrors = useCallback((...fields: FieldPath<T>[]) => {\n if (fields.length === 0) {\n setErrors({});\n } else {\n setErrors((prev) => {\n const next = { ...prev };\n for (const f of fields) {\n delete next[f];\n }\n return next;\n });\n }\n }, []);\n\n // The store first, then the DOM. A bound field renders from the store, so\n // a DOM reset alone put its default in the element for one frame and the\n // typed value back on the next render: a port's Discard left the name as\n // typed while the dirty flag went clean beside it.\n const resetForm = useCallback(() => {\n remeasure.current = true;\n store.reset();\n formRef.current?.reset();\n setErrors({});\n setCurrentData({} as T);\n queueMicrotask(measureDirty);\n }, [store, measureDirty]);\n\n useEffect(() => {\n if (isGetForm && prefetch === \"mount\" && !isThisPage(action)) {\n const fn = (window as any).__rsc_prefetch;\n fn?.(action, cacheFor);\n }\n }, [isGetForm, prefetch, action, cacheFor]);\n\n const doPrefetch = useCallback(() => {\n // The page on screen is not a shell to show: it is already shown.\n if (!isGetForm || isThisPage(action as string)) return;\n const fn = (window as any).__rsc_prefetch;\n fn?.(action as string, cacheFor);\n }, [isGetForm, action, cacheFor]);\n\n const handleSubmit = useCallback(\n async (e: FormEvent<HTMLFormElement>) => {\n e.preventDefault();\n const formData = new FormData(e.currentTarget);\n const data = decodeFormData<T>(formData, schema);\n setCurrentData(data);\n\n if (onSubmit?.(formData) === false) {\n return;\n }\n\n if (isGetForm && method === \"get\") {\n const url = new URL(action as string, window.location.origin);\n for (const [key, value] of formData.entries()) {\n if (typeof value === \"string\" && value !== \"\") {\n url.searchParams.set(key, value);\n }\n }\n\n const path = url.pathname + url.search;\n const shell = action as string;\n const nav = (window as any).__rsc_navigate;\n const prefetched = (window as any).__rsc_is_prefetched;\n\n // A search on the page it is on. There is no other page whose shell\n // could stand in while the query runs - the shell would be this page\n // with nothing in it - so the page stays, results and all, until the\n // new ones replace them, and the form says it is working. The\n // transition is what keeps pending true until they have: the\n // navigation's own update joins it, and commits with it.\n if (isThisPage(shell)) {\n startTransition(async () => {\n await nav?.(path, { replace, preserveScroll, inPlace: true })?.catch(() => {});\n });\n\n return;\n }\n\n // The route without its query is that route's shell: the layout, the\n // chrome, and whatever it renders with nothing to show yet. Prefetching\n // on hover put it in the cache, so going there first costs no request\n // and puts the page on screen while the real query is still running.\n //\n // The query itself is never prefetched. It is the expensive half, and\n // hovering a search button is not a reason to run someone's search.\n if (path !== shell && prefetched?.(shell)) {\n // Awaited rather than raced: navigate() aborts whatever is in flight,\n // so starting the real one first would cancel the shell before it\n // could render. It is a cache hit, so this is a render, not a wait.\n Promise.resolve(nav?.(shell, { replace, preserveScroll })).then(() =>\n // Replaces, so the shell does not become a back-button stop of its\n // own — the pair leaves exactly one entry behind.\n nav?.(path, { replace: true, preserveScroll }),\n );\n\n return;\n }\n\n nav?.(path, { replace, preserveScroll });\n return;\n }\n\n const serverAction = action as (formData: FormData) => Promise<unknown>;\n\n // Rebuilt rather than edited: transform returns the values to send, so\n // whatever was in the form and is not in the result should not go.\n if (transform) {\n for (const key of [...formData.keys()]) formData.delete(key);\n\n for (const [key, value] of buildFormData(transform(data))) {\n formData.append(key, value);\n }\n }\n\n setErrors({});\n\n // Before the transition, so a failure neither runs the optimistic\n // update nor leaves the form looking like it is submitting.\n const invalid = await validateWith(schema, data);\n\n if (invalid) {\n setErrors(invalid);\n onError?.(invalid);\n\n return;\n }\n\n startTransition(async () => {\n try {\n // Call optimistic updater inside the transition so React's\n // useOptimistic picks it up and auto-reverts on settle.\n optimistic?.(data);\n\n // Whatever an earlier call noted is not this action's: a redirect\n // from another form, or from an action no form was waiting for - a\n // logout button - is left behind until someone reads it, and the\n // next form to succeed took it for its own and skipped onSuccess.\n redirectedTo();\n\n const result = await serverAction(formData);\n const refused = resultOf(result);\n // Read every time, which is what clears it. Behind the || below it\n // went unread whenever the answer already said \"redirected\", and\n // stayed for the next form.\n const redirected = redirectedTo();\n\n // The action answered with somewhere to go, and callServer has\n // already started the navigation. Not an error for a form to\n // show, and not a save to announce either: signing in and going\n // to the dashboard is the whole success.\n if (refused?.redirected !== undefined || redirected !== null) return;\n\n if (refused) {\n if (refused.errors) {\n setErrors(refused.errors);\n onError?.(refused.errors);\n } else {\n // Under the form's own key, so every place that clears the\n // errors clears it too.\n const formLevel = [refused.serverError ?? \"The action was refused.\"];\n\n setErrors({ \"\": formLevel });\n setRefusal(refused.refusal === undefined ? null : { for: formLevel, data: refused.refusal });\n onError?.({}, new Error(refused.serverError));\n }\n\n return;\n }\n\n // Owed, not done: see resetOwed. Saved, so what is in the form is\n // what the server has - measured after the reset where there is one.\n if (resetOnSuccess) resetOwed.current = { result };\n else snapshot();\n\n setErrors({});\n setSucceeded(true);\n setRecentlySucceeded(true);\n\n clearTimeout(recentTimer.current);\n recentTimer.current = setTimeout(\n () => setRecentlySucceeded(false),\n 2_000,\n );\n\n if (!resetOnSuccess) onSuccess?.(result);\n } catch (err) {\n // A redirect no longer arrives here - callServer resolves after\n // performing it - but an action called through something older\n // than that still may.\n if (err instanceof ServerRedirectError) return;\n\n if (err instanceof ServerValidationError) {\n setErrors(err.errors);\n onError?.(err.errors);\n } else if (err instanceof ActionRefusedError) {\n // A backend turned a generated stub down: its message, written for\n // the person asking, is the form's error.\n setErrors({ \"\": [err.message] });\n setRefusal(null);\n onError?.({}, err);\n } else if (err instanceof ServerDumpError) {\n // Dump overlay is already shown — silently swallow\n } else if (onError) {\n // Not rethrown. A rejected action never settles, and until it\n // settles React keeps the optimistic update on screen — so an\n // unexpected failure left the row showing as though the write had\n // worked. Settling is what takes it back.\n onError({}, err);\n } else {\n // Nothing is handling it, and swallowing here would lose it\n // entirely — the reason this used to rethrow.\n console.error(\"[rsc-kit] form submit failed\", err);\n }\n }\n });\n },\n [\n action,\n isGetForm,\n method,\n replace,\n preserveScroll,\n resetOnSuccess,\n store,\n schema,\n transform,\n optimistic,\n onSubmit,\n onSuccess,\n onError,\n ],\n );\n\n const field = useCallback(\n <K extends keyof T & string>(name: K): FieldBinding<T[K]> => {\n // Recorded during render, deliberately: this is how the form knows which\n // values it is the one displaying. Idempotent, so a double render in\n // development records the same name twice and means the same thing.\n readHere.current.add(name);\n\n return {\n name,\n value: (store.get(name) ?? \"\") as T[K],\n onChange: (next: unknown) => {\n const value =\n typeof next === \"object\" && next !== null && \"target\" in next\n ? (next as { target: { value: string } }).target.value\n : next;\n\n store.set(name, value);\n },\n onBlur: () => void touch(name),\n };\n },\n [store, touch],\n );\n\n\n // Stable, so a subscriber below does not re-render because this one did.\n const storeContext = useMemo(() => ({ store, touch }), [store, touch]);\n\n const formStatus: FormRenderProps<T, RefusalOf<A>, FieldNameOf<T, A, F>> = {\n pending: isPending,\n data: currentData,\n get dirty() {\n dirtyRead.current = true;\n\n return dirty;\n },\n succeeded,\n recentlySucceeded,\n field,\n error,\n formError: errors[\"\"]?.[0],\n formRefusal: (refusal && errors[\"\"] === refusal.for ? refusal.data : undefined) as RefusalOf<A> | undefined,\n clearErrors,\n reset: resetForm,\n };\n\n return (\n <FormStoreContext.Provider value={storeContext}>\n <FormStatusContext.Provider value={formStatus as FormRenderProps}>\n <form\n ref={attachForm}\n // On the element as well as in the handler, which is what makes this\n // work before hydration. React emits a form a browser can submit on its\n // own for a server action, and an ordinary action/method pair for a\n // url — so a submit that happens before the javascript arrives still\n // reaches the server.\n //\n // The two do not fight: handleSubmit calls preventDefault() first, and\n // React does not run a form action when the submit event was cancelled.\n // So the enhanced path wins whenever there is one, and the native path\n // is what is left when there is not.\n action={(bindable ? formAction : action) as never}\n // Only for a url. React sets the method itself for a server action, and\n // passing one alongside is what it warns about.\n method={isGetForm ? method : undefined}\n onSubmit={handleSubmit}\n // Every keystroke and every toggle, from any control in the form,\n // uncontrolled ones included: React's onInput here is the bubbling\n // `input` event. A caller's own handler still runs.\n onInput={(event) => {\n rest.onInput?.(event);\n measureDirty();\n }}\n onChange={(event) => {\n rest.onChange?.(event);\n measureDirty();\n }}\n // On the form, not only on the bound fields. `focusout` bubbles where\n // `blur` does not, so React's onBlur here sees every control that was\n // left — including the uncontrolled ones, which are most of them and\n // would otherwise never be marked touched at all.\n onBlur={(event) => {\n const target = event.target as unknown as {\n name?: string;\n value?: string;\n };\n const name = target.name;\n\n if (!name) return;\n\n // Leaving a field is the moment to check it; leaving the form is\n // not the same moment. Focus going to nothing, or to something\n // outside the form, is a click on the page - most often a dialog\n // closing - and an error painted into a dialog as it animates out\n // reads as a submit that nobody made. An empty field left that way\n // is not checked at all. One with something in it is, but only\n // once the dust settles: if the form is gone or hidden by then, it\n // was a dialog closing, and nobody is there to read the error.\n const left = event.relatedTarget as Node | null;\n const stillInForm = !!left && !!formRef.current?.contains(left);\n\n if (stillInForm) {\n void touch(name);\n\n return;\n }\n\n if (!target.value) return;\n\n setTimeout(() => {\n const form = formRef.current;\n\n if (\n !form ||\n !form.isConnected ||\n form.getClientRects().length === 0\n )\n return;\n // A submit in flight is not a dialog closing, and its answer is\n // the verdict on every field. On iOS a tap on the submit button\n // does not focus it, so the last field's blur arrives here as\n // \"left the form\" - and by now the fields may be disabled for\n // the pending submit, missing from its data, and judged absent:\n // \"last name is required\" flashed on the way to the next step.\n if (pendingRef.current) return;\n // Nor a field disabled by now, for the same reason: its value is\n // not in the form's data, so it would always read as missing.\n if ((event.target as { disabled?: boolean }).disabled) return;\n if (\n form.closest(\n \"[hidden], [aria-hidden='true'], [data-ending-style], [data-closed]\",\n )\n )\n return;\n\n void touch(name);\n }, LEAVE_FORM_SETTLE_MS);\n }}\n onMouseEnter={prefetch === \"hover\" ? doPrefetch : undefined}\n data-pending={isPending ? \"\" : undefined}\n {...rest}\n >\n {typeof children === \"function\" ? children(formStatus) : children}\n </form>\n </FormStatusContext.Provider>\n </FormStoreContext.Provider>\n );\n}\n\n// Also by name, because both spellings are in use: `import Form` and\n// `import { Form }`. This was a re-export of \"./Form\" — from inside Form.tsx,\n// so the module named itself. It survived on the bundler tolerating a circular\n// self-reference, left over from when a separate barrel re-exported a\n// FormComponent.tsx that a case-insensitive filesystem would not let be called\n// Form.ts. There is one file now, and it can just export what it declares.\nexport { Form };\n"]}
1
+ {"version":3,"file":"Form.js","sourceRoot":"","sources":["../../src/js/Form.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAGb,OAAO,EAKL,aAAa,EACb,WAAW,EACX,UAAU,EACV,SAAS,EACT,eAAe,EACf,OAAO,EACP,MAAM,EACN,cAAc,EACd,QAAQ,EACR,oBAAoB,EACpB,aAAa,GACd,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,eAAe,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,a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,KACpC,IAAI,YAEP,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,GAC5D,GACoB,GACH,CAC7B,CAAC;AACJ,CAAC;AAED,qEAAqE;AACrE,8EAA8E;AAC9E,+EAA+E;AAC/E,sEAAsE;AACtE,+EAA+E;AAC/E,2EAA2E;AAC3E,OAAO,EAAE,IAAI,EAAE,CAAC","sourcesContent":["\"use client\";\n\nimport type { Route } from \"../routes.js\";\nimport {\n type FormHTMLAttributes,\n type FormEvent,\n type ReactNode,\n type Ref,\n createContext,\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useActionState,\n useState,\n useSyncExternalStore,\n useTransition,\n} from \"react\";\nimport { submitForm } from \"../formSubmit.js\";\nimport { ActionRefusedError, ServerValidationError, ServerDumpError, ServerRedirectError, redirectedTo } from \"./errors.js\";\nimport { buildFormData, decodeFormData } from \"./formEncoding.js\";\nimport { createFormStore } from \"./formStore.js\";\nimport type { FormStore } from \"./formStore.js\";\nimport { validateWith } from \"./standardSchema.js\";\nimport type { StandardSchemaV1 } from \"./standardSchema.js\";\n\n/**\n * How long a blur that leaves the form waits before checking the field. A\n * dialog's exit animation is shorter than this; a form still on screen after\n * it is one somebody is looking at.\n */\nconst LEAVE_FORM_SETTLE_MS = 300;\n\ntype PrefetchStrategy = \"hover\" | \"mount\" | \"none\";\n\n/**\n * What `field(name)` hands a control, spread straight onto it.\n *\n * The same four things react-hook-form's `<Controller>` gives, because it is\n * the same job: a component with no native control behind it needs a value and\n * a way to report a new one.\n */\ninterface FieldBinding<V> {\n name: string;\n value: V;\n /**\n * Either shape: a DOM event, or the value itself.\n *\n * A native input passes the event; a Radix select or a rich editor passes\n * what was chosen. A binder understanding only one of them would work on\n * half the controls anyone actually uses.\n */\n onChange: (next: V | { target: { value: V } }) => void;\n onBlur: () => void;\n}\n\n/**\n * A field's name: one the form declared, suggested by the editor - or any\n * path, because a nested or indexed field (`address.city`, `items[0].name`)\n * is a real name no defaultValues object can declare. The typo that matters\n * is caught on `field()`, which is closed to the declared names.\n */\ntype FieldPath<T> = (keyof T & string) | (string & {});\n\n/** Dots deep, so a self-referential or very wide input type cannot run the compiler out. */\ntype Depth = [never, 0, 1, 2, 3];\n\n/**\n * Every name an error can be filed under in a value: its keys, a nested object's\n * `address.city`, and a list's `items.0.sku` - the shape a Standard Schema\n * issue and a backend's validation both produce.\n */\ntype Paths<T, D extends number = 3> = [D] extends [never]\n ? never\n : T extends readonly (infer U)[]\n ? `${number}` | `${number}.${Paths<U, Depth[D]>}`\n : T extends object\n ? { [K in keyof T & string]: K | (T[K] extends object ? `${K}.${Paths<T[K], Depth[D]>}` : never) }[keyof T & string]\n : never;\n\n/**\n * What an action takes, read off the action: a generated stub's typed overload,\n * or the input of one built with `createActionClient().input(schema)`. Unknown\n * when it does not say - a url, or a function of a FormData - and then nothing\n * is claimed about its fields.\n */\ntype InputOfAction<A> = [A] extends [never]\n ? unknown // `action={signup as never}`: a cast says nothing about the input\n : 0 extends 1 & A\n ? unknown // any\n : A extends { (input: infer I): Promise<unknown>; (form: FormData): Promise<unknown> }\n ? Described<I>\n : A extends (input: infer I) => Promise<unknown>\n ? Described<I>\n : unknown;\n\n/** An action's parameter, without the FormData a form posts it as; unknown if that was all it said. */\ntype Described<I> = [Exclude<I, FormData | undefined>] extends [never] ? unknown : Exclude<I, FormData | undefined>;\n\ndeclare const NAMES: unique symbol;\n\n/**\n * A form's FormData, naming its fields.\n *\n * For an action the app writes that takes a form and passes it on - to a stub\n * whose parameters are plain strings, say - which says nothing of its fields to\n * anything reading its type. Declared on the parameter, where the names live\n * with the code that reads them:\n *\n * export async function createApp(form: FormFields<'name' | 'region'>) {\n * return await appsCreate(String(form.get('name')), String(form.get('region')))\n * }\n *\n * and `<Form action={createApp}>` closes `error()` to those names. Nothing runs:\n * it is a FormData, and every FormData is one. The names are a claim the types\n * keep, not a check the browser makes.\n */\nexport interface FormFields<Name extends string> extends FormData {\n readonly [NAMES]?: Name;\n}\n\n/** The names a form-taking action declared with FormFields, or never when it did not. */\ntype DeclaredNames<A> = A extends (form: FormFields<infer N>, ...rest: never[]) => Promise<unknown>\n ? string extends N\n ? never\n : N\n : never;\n\n/**\n * The names an action's validation can be read under, for `error()` and\n * `clearErrors()`: the input's own paths, the names a wrapper declared, and the\n * form's declared values.\n *\n * Closed when the action says what it takes, so `error('nmae')` fails the\n * typecheck rather than showing nothing, ever. Open, as it always was, when it\n * does not - a field is only a typo if something could have said so.\n */\ntype FieldNameOf<T, A, F extends string = never> = [F] extends [never]\n ? unknown extends InputOfAction<A>\n ? [DeclaredNames<A>] extends [never]\n ? FieldPath<T>\n : DeclaredKeys<T> | DeclaredNames<A>\n : DeclaredKeys<T> | Paths<InputOfAction<A>> | DeclaredNames<A>\n : // Named on the form itself: closed to these, beside everything else that names a field.\n F | DeclaredKeys<T> | DeclaredNames<A> | (unknown extends InputOfAction<A> ? never : Paths<InputOfAction<A>>);\n\n/** The form's declared values count - but T is the open record when it declared none, and all of `string` is not a name. */\ntype DeclaredKeys<T> = string extends keyof T ? never : keyof T & string;\n\n/** The field names an action's validation can name, for a component below a form to type. */\nexport type FieldNamesOf<A> = unknown extends InputOfAction<A>\n ? [DeclaredNames<A>] extends [never]\n ? string\n : DeclaredNames<A>\n : Paths<InputOfAction<A>> | DeclaredNames<A>;\n\ninterface FormRenderProps<\n T extends Record<string, unknown> = Record<string, unknown>,\n Refusal = unknown,\n Name extends string = FieldPath<T>,\n> {\n pending: boolean;\n /** What is being submitted, while it is. */\n data: T;\n /**\n * A field's error, or undefined: the one way to read one.\n *\n * {error('title') && <p>{error('title')}</p>}\n * <Field data-invalid={!!error('title')}>\n *\n * Nested paths join with dots - `error('address.city')`, the key a Standard\n * Schema issue for that field produces. A field is checked when it is left\n * and when the form is submitted, so an error never appears on a field\n * nobody has reached yet.\n */\n error: (field: Name) => string | undefined;\n /**\n * The refusal that is not about a field: the action's `serverError` - a\n * 402, a 409, \"that slot was just taken\" - or a validation message for the\n * form as a whole. Undefined otherwise. Cleared by the next submit, by a\n * success, and by `clearErrors()` and `reset()`, like a field's.\n *\n * {formError && <p role=\"alert\">{formError}</p>}\n *\n * Only what the action returned: a failure thrown on the way, the network\n * or a crash, goes to `onError` as before, where a production message is\n * React's stand-in and not something to show.\n */\n formError: string | undefined;\n /**\n * What the action's refusal carried beside `formError` - the records\n * blocking a delete, say - when the action refused with `refuse()` and\n * declared its shape with `.refusal(schema)`. Typed from the form's\n * `action` in its render prop; in a component below, `useForm<T, R>()`.\n * Goes when `formError` does.\n */\n formRefusal: Refusal | undefined;\n clearErrors: (...fields: Name[]) => void;\n reset: () => void;\n /**\n * Whether anything differs from what the form started with.\n *\n * For the Save button that stays quiet until there is something to save,\n * and the Discard that appears beside it. Read from the form itself - a\n * snapshot of its FormData on mount, compared on every input - so an\n * uncontrolled field counts, which nothing outside the form can do. A\n * successful submit makes the current values the new baseline; `reset()`\n * goes back to the first one.\n */\n dirty: boolean;\n /** Whether the last submit was accepted. */\n succeeded: boolean;\n /**\n * The same thing, for two seconds.\n *\n * The \"Saved ✓\" that appears and fades. Worth having as state rather than a\n * timer in every form that wants one, because the timer has to be cleared\n * when the component goes away and that is the part people forget.\n */\n recentlySucceeded: boolean;\n /**\n * Bind one field so this component holds its value.\n *\n * Most fields need nothing: they are uncontrolled, the DOM holds the value,\n * and it is read back as FormData on submit. Reach for this when the DOM\n * cannot hold it for you — a control with no native element behind it, or a\n * value you want to read as it is typed:\n *\n * <Input {...field('title')} />\n * <span>{field('body').value.length}/100</span>\n *\n * A bound field is still an ordinary named input, so it arrives in FormData\n * with everything else. Nothing merges; there is one source of truth.\n */\n field: <K extends keyof T & string>(name: K) => FieldBinding<T[K]>;\n}\n\n/** What a form can submit to: a url, or a server action. */\ntype FormAction = Route | ((formData: FormData) => Promise<unknown>);\n\n/**\n * What the action's refusal carries, read off the action itself - its\n * `.refusal(schema)` - so `formRefusal` is typed without a cast. Unknown for a\n * url, or for an action that does not say.\n */\ntype RefusalOf<A> = A extends (...args: never[]) => Promise<infer R>\n ? R extends { refusal?: infer F }\n ? F\n : unknown\n : unknown;\n\ninterface FormProps<\n T extends Record<string, unknown> = Record<string, unknown>,\n A extends FormAction = FormAction,\n F extends string = never,\n> extends Omit<\n FormHTMLAttributes<HTMLFormElement>,\n \"action\" | \"method\" | \"children\" | \"onSubmit\" | \"onError\"\n> {\n action: A;\n method?: \"get\" | \"post\";\n /**\n * The <form> element, for a caller that needs it - to focus, to scroll to,\n * to hand a library. The form keeps its own handle beside it; a caller's\n * never replaces it.\n */\n ref?: Ref<HTMLFormElement>;\n /**\n * Starting values for fields bound with `field()`.\n *\n * Uncontrolled fields do not need this — they take React's own\n * `defaultValue`, and the DOM keeps whatever is typed into them.\n */\n defaultValues?: Partial<T>;\n /**\n * The names `error()` and `clearErrors()` may be asked for, when nothing else\n * says: a form that posts nothing (its values live in React state, or it is a\n * button) has no FormData for an action to declare them on.\n *\n * <Form action={resize} fields={['size', 'copies']}>\n * {({ error }) => error('size')} // error('sise') fails the typecheck\n *\n * Types only: nothing is checked in the browser, and a name is a claim about\n * what the action's validation reports. Closes the set; names the action's own\n * input or `FormFields` declare, and `defaultValues` keys, are in it too.\n */\n fields?: readonly F[];\n /**\n * A store created above this form, from `useFormStore()`.\n *\n * For the one case the context cannot reach: something that is not a\n * descendant — a top bar showing unsaved changes, a sidebar preview — needs\n * the values to exist above both of them. Create the store where they share\n * an ancestor and hand it down.\n *\n * Without it the form makes its own, which is what almost every form wants.\n */\n store?: FormStore;\n prefetch?: PrefetchStrategy;\n cacheFor?: number;\n replace?: boolean;\n preserveScroll?: boolean;\n resetOnSuccess?: boolean;\n /**\n * Check the fields before submitting, with any Standard Schema — Zod,\n * Valibot, ArkType.\n *\n * A failure fills `errors` and the action is never called, so a mistake\n * costs no round trip. It is a courtesy and not a control: the same action\n * is reachable without this form, so the server still has to check.\n */\n schema?: StandardSchemaV1;\n /** Transform form data before submitting to the server action. */\n transform?: (data: T) => Record<string, unknown>;\n /** Called inside the transition with typed form data. Use it to call your useOptimistic setter. */\n optimistic?: (data: T) => void;\n onSuccess?: (result: unknown) => void;\n /**\n * Called when a submit does not succeed.\n *\n * Validation failures arrive as field errors, with no second argument.\n * Anything else arrives as an empty error map and the thrown value — there\n * are no field errors to report, but the form still has to say so.\n */\n onError?: (errors: Record<string, string[]>, error?: unknown) => void;\n onSubmit?: (formData: FormData) => void | false;\n children: ReactNode | ((form: FormRenderProps<T, RefusalOf<A>, FieldNameOf<T, A, F>>) => ReactNode);\n}\n\n/**\n * What an action built with createActionClient answers with.\n *\n * Recognised rather than thrown, because React serialises a rejected server\n * action opaquely: production strips the message and the fields it named are\n * gone. A returned object crosses intact, so a form reads it.\n */\nfunction resultOf(\n value: unknown,\n): { errors?: Record<string, string[]>; serverError?: string; refusal?: unknown; redirected?: string } | null {\n if (typeof value !== \"object\" || value === null) return null;\n\n const result = value as {\n validationErrors?: Record<string, string[]>;\n serverError?: string;\n refusal?: unknown;\n redirected?: string;\n };\n\n if (result.validationErrors) return { errors: result.validationErrors };\n if (result.serverError) return { serverError: result.serverError, refusal: result.refusal };\n if (typeof result.redirected === \"string\") return { redirected: result.redirected };\n\n return null;\n}\n\nconst FormStatusContext = createContext<FormRenderProps>({\n pending: false,\n data: {},\n dirty: false,\n error: () => undefined,\n formError: undefined,\n formRefusal: undefined,\n clearErrors: () => {},\n reset: () => {},\n succeeded: false,\n recentlySucceeded: false,\n // Outside a Form there is nothing holding a value, so a binding that reported\n // one would be lying. Name only, which is the part that is still true.\n field: ((name: string) => ({\n name,\n value: \"\",\n onChange: () => {},\n onBlur: () => {},\n })) as FormRenderProps[\"field\"],\n});\n\n/**\n * The store, on its own context.\n *\n * Separate from the status context because that one holds a fresh object every\n * render, so anything reading it re-renders with the form. The store is stable\n * for the life of the form, which is what lets a subscriber below it re-render\n * alone.\n */\nconst FormStoreContext = createContext<{\n store: FormStore;\n touch: (name: string) => void;\n} | null>(null);\n\n/**\n * A value store created above the form rather than by it.\n *\n * const store = useFormStore({ title: '' })\n *\n * <TopBar store={store} /> // not inside the form\n * <Form action={save} store={store}>…</Form>\n *\n * For the one case the context cannot reach. `<Form>` makes its own otherwise,\n * and almost every form should let it — this exists so that a component which\n * is not a descendant can still read the values, which is the flexibility\n * react-hook-form and TanStack Form get from `useForm()` being yours to call.\n *\n * Deliberately not reactive itself: creating the store does not subscribe to\n * it, so the component holding it does not re-render on every keystroke and\n * take the whole subtree with it. Read a field from it with `useField(name, store)`.\n */\nexport function useFormStore<T extends Record<string, unknown>>(\n initial: Partial<T> = {},\n): FormStore {\n const ref = useRef<FormStore | null>(null);\n\n ref.current ??= createFormStore({ ...initial });\n\n return ref.current;\n}\n\n/**\n * The form this component is inside: the same object `<Form>`'s render prop\n * gets, so a field split into its own component is written exactly as it\n * was inline.\n *\n * function Title() {\n * const { field, error } = useForm()\n *\n * return (\n * <>\n * <input name=\"title\" />\n * {error('title') && <p>{error('title')}</p>}\n * </>\n * )\n * }\n *\n * Not React's `useFormStatus`, which is a different hook with a different\n * answer - which is why this one is not called that.\n */\nexport function useForm<\n T extends Record<string, unknown> = Record<string, unknown>,\n Refusal = unknown,\n>(): FormRenderProps<T, Refusal> {\n return useContext(FormStatusContext) as FormRenderProps<T, Refusal>;\n}\n\n/**\n * One field, subscribed on its own - for a large controlled form.\n *\n * The same two words as everywhere else, for one name: `field` to spread,\n * `error` to show. The component re-renders when this field changes and at no\n * other time, where `useForm()` re-renders with the whole form. Reach for it\n * when re-rendering all of a form per keystroke is real:\n *\n * function Title() {\n * const { field, error } = useField('title')\n *\n * return <Input {...field} aria-invalid={!!error} />\n * }\n *\n * Given a store, it reads a form from outside it - see useFormStore.\n */\nexport function useField(\n name: string,\n store?: FormStore,\n): { field: FieldBinding<string>; error: string | undefined } {\n const ctx = useContext(FormStoreContext);\n const status = useContext(FormStatusContext);\n\n if (!ctx && !store) {\n throw new Error(\n \"useField() was called outside a <Form>. It reads that form's values, so there has to be one above it.\",\n );\n }\n\n const source = store ?? ctx!.store;\n const touch = ctx?.touch;\n\n const value = useSyncExternalStore(\n source.subscribe,\n () => (source.get(name) ?? \"\") as string,\n () => \"\",\n );\n\n return {\n field: {\n name,\n value,\n onChange: (next) => {\n source.set(\n name,\n typeof next === \"object\" && next !== null && \"target\" in next\n ? (next as { target: { value: string } }).target.value\n : next,\n );\n },\n onBlur: () => void touch?.(name),\n },\n error: status.error(name as never),\n };\n}\n\n/**\n * submitForm bound to an action, once per action.\n *\n * Bound on every render, it was a fresh function with a fresh promise for\n * its bound arguments each time - and React, seating a posted form's state\n * during the server render, suspends on that promise until it settles, then\n * renders the component again, which bound again. A render that never\n * finished, on every page a form was posted to without javascript. One\n * bound function per action, and the promise settles once.\n */\nconst boundSubmits = new WeakMap<Function, (previous: unknown, formData: FormData) => Promise<unknown>>();\n\nfunction boundSubmit(action: (formData: FormData) => Promise<unknown>) {\n let bound = boundSubmits.get(action);\n\n if (!bound) {\n bound = submitForm.bind(null, action);\n boundSubmits.set(action, bound);\n }\n\n return bound;\n}\n\n/**\n * A form's values as one comparable string.\n *\n * FormData in document order, a file by its name and size: enough to say\n * whether anything changed, which is all `dirty` asks.\n */\n/** Whether a GET form's action is the page on screen, whatever query it carries. */\nfunction isThisPage(action: string): boolean {\n return new URL(action, window.location.origin).pathname === window.location.pathname;\n}\n\nfunction serializeForm(form: HTMLFormElement): string {\n const parts: string[] = [];\n\n for (const [name, value] of new FormData(form)) {\n parts.push(\n name + \"=\" + (typeof value === \"string\" ? value : \"file:\" + value.name + \":\" + value.size),\n );\n }\n\n return parts.join(\"\\n\");\n}\n\n/**\n * Also exported by name, and re-exported below, because both spellings are in\n * use: `import Form from` and `import { Form } from`.\n */\nexport default function Form<\n T extends Record<string, unknown> = Record<string, unknown>,\n A extends FormAction = FormAction,\n const F extends string = never,\n>({\n action,\n method: methodProp,\n defaultValues,\n // A type-level claim only. Named so it is not passed on to the <form>.\n fields: _fields,\n store: providedStore,\n prefetch = \"hover\",\n cacheFor,\n replace = false,\n preserveScroll = false,\n resetOnSuccess = true,\n schema,\n transform,\n optimistic,\n onSuccess,\n onError,\n onSubmit,\n children,\n ref: callerRef,\n ...rest\n}: FormProps<T, A, F>) {\n void _fields;\n const isGetForm = typeof action === \"string\";\n const method = methodProp ?? (isGetForm ? \"get\" : \"post\");\n\n // The answer to this form posted without a runtime, seated by React into\n // the form that posted it - which is the only way a visitor with no\n // javascript sees a refusal. Registered through submitForm, bound to the\n // action, because React hands a form-state action a (previous, formData)\n // pair and the action takes the FormData alone. On the server a plain\n // function - a closure, not a server reference - cannot be bound into a\n // form; the form falls back to the action itself, and posts nothing\n // seatable, which is all a closure could ever have done.\n const bindable =\n typeof action === \"function\" && (typeof window !== \"undefined\" || \"$$FORM_ACTION\" in action);\n const [posted, formAction] = useActionState(\n bindable ? boundSubmit(action as (formData: FormData) => Promise<unknown>) : async () => null,\n null as unknown,\n );\n const postedRefusal = resultOf(posted);\n const [errors, setErrors] = useState<Record<string, string[]>>(() => postedRefusal?.errors ?? {});\n // A refusal's data, tied to the exact form-level error it came with: when\n // that entry is cleared or replaced - the next submit, a success,\n // clearErrors() - the data goes with it, without every place that touches\n // the errors having to know.\n const [refusal, setRefusal] = useState<{ for: string[]; data: unknown } | null>(null);\n const [touched, setTouched] = useState<Record<string, boolean>>({});\n\n /**\n * Mark a field visited, and check it.\n *\n * Checking on blur rather than on every keystroke, because an error that\n * appears while someone is halfway through typing an email address is a form\n * arguing with them. Leaving the field is the moment they have finished\n * saying what they meant.\n *\n * The whole object is validated and only this field's issues are kept: a\n * Standard Schema has no notion of one field, and filtering by path is the\n * honest way to ask it about one. Everything else's errors are left as they\n * were, so blurring an empty field does not light up the rest of the form.\n */\n const touch = useCallback(\n async (name: string) => {\n setTouched((prev) => (prev[name] ? prev : { ...prev, [name]: true }));\n\n if (!schema || !formRef.current) return;\n\n const invalid = await validateWith(\n schema,\n decodeFormData(new FormData(formRef.current), schema),\n );\n\n setErrors((prev) => {\n const next = { ...prev };\n\n if (invalid?.[name]) next[name] = invalid[name];\n else delete next[name];\n\n return next;\n });\n },\n [schema],\n );\n\n const [succeeded, setSucceeded] = useState(false);\n const [recentlySucceeded, setRecentlySucceeded] = useState(false);\n const recentTimer = useRef<ReturnType<typeof setTimeout> | undefined>(\n undefined,\n );\n\n // Cleared on unmount: a timer that fires into a component that has gone is\n // the warning nobody reads and the leak nobody finds.\n useEffect(() => () => clearTimeout(recentTimer.current), []);\n\n // Only the fields someone bound. Everything else is the DOM's.\n //\n // A store rather than state, so a component using `useField` can re-render\n // for one field while this one does not. See formStore.ts.\n const storeRef = useRef<FormStore | null>(null);\n\n storeRef.current ??= createFormStore({\n ...(defaultValues as Record<string, unknown> | undefined),\n });\n\n const store = providedStore ?? storeRef.current;\n\n // Which names the render prop read through `field()`. A change to one of\n // those has to re-render this component, because that is where the value is\n // being displayed; a change to anything else does not, which is what lets a\n // `useField` child stand on its own.\n const readHere = useRef(new Set<string>());\n const [, bump] = useState(0);\n\n useEffect(\n () =>\n store.subscribe((name) => {\n if (name === \"\" || readHere.current.has(name)) bump((n) => n + 1);\n }),\n [store],\n );\n const [currentData, setCurrentData] = useState<T>({} as T);\n const [isPending, startTransition] = useTransition();\n const formRef = useRef<HTMLFormElement>(null);\n // Read by the delayed blur check, which runs after the render that set it:\n // the value its closure captured is the one from before the submit began.\n const pendingRef = useRef(false);\n pendingRef.current = isPending;\n\n // A reset owed by a successful submit, performed in the commit that ends\n // it. The action resolves a tick before React commits its transition - the\n // result, whatever the action revalidated, pending going false - and a\n // reset done on resolve was a DOM write with a frame of its own: a chat's\n // composer emptied before the reply it was answered with appeared. In a\n // layout effect of the commit where pending turns false, it lands in the\n // same frame as the result, before the browser paints.\n const resetOwed = useRef<{ result: unknown } | null>(null);\n\n // What the form started with, as its FormData reads: the baseline `dirty`\n // is measured against. Taken on mount, retaken after a successful submit.\n const baseline = useRef<string | null>(null);\n const [dirty, setDirty] = useState(false);\n // Only a form that reads `dirty` pays for it: the flip from clean to dirty\n // is a render of the whole form, and a field that subscribes for itself\n // is promised that typing in it renders it alone.\n const dirtyRead = useRef(false);\n\n const snapshot = useCallback(() => {\n if (!formRef.current) return;\n\n baseline.current = serializeForm(formRef.current);\n setDirty(false);\n }, []);\n\n const measureDirty = useCallback(() => {\n if (!dirtyRead.current || !formRef.current || baseline.current === null) return;\n\n const now = serializeForm(formRef.current) !== baseline.current;\n\n setDirty((was) => (was === now ? was : now));\n }, []);\n\n useEffect(snapshot, [snapshot]);\n\n // A bound control with no native element behind it changes through the\n // store, not through an input event - a Radix select - so the store is\n // watched too. Its input, if it has one, is read back with the rest. In\n // a microtask: the fields subscribed before this effect ran, so React's\n // own flush of their update is queued ahead of the measure, and the\n // element is read after it was written.\n useEffect(() => store.subscribe(() => queueMicrotask(measureDirty)), [store, measureDirty]);\n\n // A reset writes every bound field at once, through a render of this\n // component; the measure has to read the elements after that commit,\n // and a microtask queued during the reset ran before it. Marked here,\n // measured by the effect below once the render lands.\n const remeasure = useRef(false);\n\n useEffect(() => {\n if (!remeasure.current) return;\n\n remeasure.current = false;\n measureDirty();\n });\n\n useLayoutEffect(() => {\n const owed = resetOwed.current;\n\n if (!owed || isPending) return;\n\n resetOwed.current = null;\n store.reset();\n formRef.current?.reset();\n setTouched({});\n setCurrentData({} as T);\n snapshot();\n // After the reset, as it always ran: an onSuccess that fills or focuses a\n // field must not have the reset undo it.\n onSuccess?.(owed.result);\n });\n\n // Both handles, one element. React 19 hands a function component its ref\n // as a prop, and spread after the form's own it replaced it - every\n // FormData read then found null. A caller's ref is filled beside ours.\n const attachForm = useCallback(\n (element: HTMLFormElement | null) => {\n formRef.current = element;\n\n if (typeof callerRef === \"function\") callerRef(element);\n else if (callerRef) callerRef.current = element;\n },\n [callerRef],\n );\n\n const error = useCallback(\n (field: FieldPath<T>): string | undefined => errors[field]?.[0],\n [errors],\n );\n\n const clearErrors = useCallback((...fields: FieldPath<T>[]) => {\n if (fields.length === 0) {\n setErrors({});\n } else {\n setErrors((prev) => {\n const next = { ...prev };\n for (const f of fields) {\n delete next[f];\n }\n return next;\n });\n }\n }, []);\n\n // The store first, then the DOM. A bound field renders from the store, so\n // a DOM reset alone put its default in the element for one frame and the\n // typed value back on the next render: a port's Discard left the name as\n // typed while the dirty flag went clean beside it.\n const resetForm = useCallback(() => {\n remeasure.current = true;\n store.reset();\n formRef.current?.reset();\n setErrors({});\n setCurrentData({} as T);\n queueMicrotask(measureDirty);\n }, [store, measureDirty]);\n\n useEffect(() => {\n if (isGetForm && prefetch === \"mount\" && !isThisPage(action)) {\n const fn = (window as any).__rsc_prefetch;\n fn?.(action, cacheFor);\n }\n }, [isGetForm, prefetch, action, cacheFor]);\n\n const doPrefetch = useCallback(() => {\n // The page on screen is not a shell to show: it is already shown.\n if (!isGetForm || isThisPage(action as string)) return;\n const fn = (window as any).__rsc_prefetch;\n fn?.(action as string, cacheFor);\n }, [isGetForm, action, cacheFor]);\n\n const handleSubmit = useCallback(\n async (e: FormEvent<HTMLFormElement>) => {\n e.preventDefault();\n const formData = new FormData(e.currentTarget);\n const data = decodeFormData<T>(formData, schema);\n setCurrentData(data);\n\n if (onSubmit?.(formData) === false) {\n return;\n }\n\n if (isGetForm && method === \"get\") {\n const url = new URL(action as string, window.location.origin);\n for (const [key, value] of formData.entries()) {\n if (typeof value === \"string\" && value !== \"\") {\n url.searchParams.set(key, value);\n }\n }\n\n const path = url.pathname + url.search;\n const shell = action as string;\n const nav = (window as any).__rsc_navigate;\n const prefetched = (window as any).__rsc_is_prefetched;\n\n // A search on the page it is on. There is no other page whose shell\n // could stand in while the query runs - the shell would be this page\n // with nothing in it - so the page stays, results and all, until the\n // new ones replace them, and the form says it is working. The\n // transition is what keeps pending true until they have: the\n // navigation's own update joins it, and commits with it.\n if (isThisPage(shell)) {\n startTransition(async () => {\n await nav?.(path, { replace, preserveScroll, inPlace: true })?.catch(() => {});\n });\n\n return;\n }\n\n // The route without its query is that route's shell: the layout, the\n // chrome, and whatever it renders with nothing to show yet. Prefetching\n // on hover put it in the cache, so going there first costs no request\n // and puts the page on screen while the real query is still running.\n //\n // The query itself is never prefetched. It is the expensive half, and\n // hovering a search button is not a reason to run someone's search.\n if (path !== shell && prefetched?.(shell)) {\n // Awaited rather than raced: navigate() aborts whatever is in flight,\n // so starting the real one first would cancel the shell before it\n // could render. It is a cache hit, so this is a render, not a wait.\n Promise.resolve(nav?.(shell, { replace, preserveScroll })).then(() =>\n // Replaces, so the shell does not become a back-button stop of its\n // own — the pair leaves exactly one entry behind.\n nav?.(path, { replace: true, preserveScroll }),\n );\n\n return;\n }\n\n nav?.(path, { replace, preserveScroll });\n return;\n }\n\n const serverAction = action as (formData: FormData) => Promise<unknown>;\n\n // Rebuilt rather than edited: transform returns the values to send, so\n // whatever was in the form and is not in the result should not go.\n if (transform) {\n for (const key of [...formData.keys()]) formData.delete(key);\n\n for (const [key, value] of buildFormData(transform(data))) {\n formData.append(key, value);\n }\n }\n\n setErrors({});\n\n // Before the transition, so a failure neither runs the optimistic\n // update nor leaves the form looking like it is submitting.\n const invalid = await validateWith(schema, data);\n\n if (invalid) {\n setErrors(invalid);\n onError?.(invalid);\n\n return;\n }\n\n startTransition(async () => {\n try {\n // Call optimistic updater inside the transition so React's\n // useOptimistic picks it up and auto-reverts on settle.\n optimistic?.(data);\n\n // Whatever an earlier call noted is not this action's: a redirect\n // from another form, or from an action no form was waiting for - a\n // logout button - is left behind until someone reads it, and the\n // next form to succeed took it for its own and skipped onSuccess.\n redirectedTo();\n\n const result = await serverAction(formData);\n const refused = resultOf(result);\n // Read every time, which is what clears it. Behind the || below it\n // went unread whenever the answer already said \"redirected\", and\n // stayed for the next form.\n const redirected = redirectedTo();\n\n // The action answered with somewhere to go, and callServer has\n // already started the navigation. Not an error for a form to\n // show, and not a save to announce either: signing in and going\n // to the dashboard is the whole success.\n if (refused?.redirected !== undefined || redirected !== null) return;\n\n if (refused) {\n if (refused.errors) {\n setErrors(refused.errors);\n onError?.(refused.errors);\n } else {\n // Under the form's own key, so every place that clears the\n // errors clears it too.\n const formLevel = [refused.serverError ?? \"The action was refused.\"];\n\n setErrors({ \"\": formLevel });\n setRefusal(refused.refusal === undefined ? null : { for: formLevel, data: refused.refusal });\n onError?.({}, new Error(refused.serverError));\n }\n\n return;\n }\n\n // Owed, not done: see resetOwed. Saved, so what is in the form is\n // what the server has - measured after the reset where there is one.\n if (resetOnSuccess) resetOwed.current = { result };\n else snapshot();\n\n setErrors({});\n setSucceeded(true);\n setRecentlySucceeded(true);\n\n clearTimeout(recentTimer.current);\n recentTimer.current = setTimeout(\n () => setRecentlySucceeded(false),\n 2_000,\n );\n\n if (!resetOnSuccess) onSuccess?.(result);\n } catch (err) {\n // A redirect no longer arrives here - callServer resolves after\n // performing it - but an action called through something older\n // than that still may.\n if (err instanceof ServerRedirectError) return;\n\n if (err instanceof ServerValidationError) {\n setErrors(err.errors);\n onError?.(err.errors);\n } else if (err instanceof ActionRefusedError) {\n // A backend turned a generated stub down: its message, written for\n // the person asking, is the form's error.\n setErrors({ \"\": [err.message] });\n setRefusal(null);\n onError?.({}, err);\n } else if (err instanceof ServerDumpError) {\n // Dump overlay is already shown — silently swallow\n } else if (onError) {\n // Not rethrown. A rejected action never settles, and until it\n // settles React keeps the optimistic update on screen — so an\n // unexpected failure left the row showing as though the write had\n // worked. Settling is what takes it back.\n onError({}, err);\n } else {\n // Nothing is handling it, and swallowing here would lose it\n // entirely — the reason this used to rethrow.\n console.error(\"[rsc-kit] form submit failed\", err);\n }\n }\n });\n },\n [\n action,\n isGetForm,\n method,\n replace,\n preserveScroll,\n resetOnSuccess,\n store,\n schema,\n transform,\n optimistic,\n onSubmit,\n onSuccess,\n onError,\n ],\n );\n\n const field = useCallback(\n <K extends keyof T & string>(name: K): FieldBinding<T[K]> => {\n // Recorded during render, deliberately: this is how the form knows which\n // values it is the one displaying. Idempotent, so a double render in\n // development records the same name twice and means the same thing.\n readHere.current.add(name);\n\n return {\n name,\n value: (store.get(name) ?? \"\") as T[K],\n onChange: (next: unknown) => {\n const value =\n typeof next === \"object\" && next !== null && \"target\" in next\n ? (next as { target: { value: string } }).target.value\n : next;\n\n store.set(name, value);\n },\n onBlur: () => void touch(name),\n };\n },\n [store, touch],\n );\n\n\n // Stable, so a subscriber below does not re-render because this one did.\n const storeContext = useMemo(() => ({ store, touch }), [store, touch]);\n\n const formStatus: FormRenderProps<T, RefusalOf<A>, FieldNameOf<T, A, F>> = {\n pending: isPending,\n data: currentData,\n get dirty() {\n dirtyRead.current = true;\n\n return dirty;\n },\n succeeded,\n recentlySucceeded,\n field,\n error,\n formError: errors[\"\"]?.[0],\n formRefusal: (refusal && errors[\"\"] === refusal.for ? refusal.data : undefined) as RefusalOf<A> | undefined,\n clearErrors,\n reset: resetForm,\n };\n\n return (\n <FormStoreContext.Provider value={storeContext}>\n <FormStatusContext.Provider value={formStatus as FormRenderProps}>\n <form\n ref={attachForm}\n // On the element as well as in the handler, which is what makes this\n // work before hydration. React emits a form a browser can submit on its\n // own for a server action, and an ordinary action/method pair for a\n // url — so a submit that happens before the javascript arrives still\n // reaches the server.\n //\n // The two do not fight: handleSubmit calls preventDefault() first, and\n // React does not run a form action when the submit event was cancelled.\n // So the enhanced path wins whenever there is one, and the native path\n // is what is left when there is not.\n action={(bindable ? formAction : action) as never}\n // Only for a url. React sets the method itself for a server action, and\n // passing one alongside is what it warns about.\n method={isGetForm ? method : undefined}\n onSubmit={handleSubmit}\n // Every keystroke and every toggle, from any control in the form,\n // uncontrolled ones included: React's onInput here is the bubbling\n // `input` event. A caller's own handler still runs.\n onInput={(event) => {\n rest.onInput?.(event);\n measureDirty();\n }}\n onChange={(event) => {\n rest.onChange?.(event);\n measureDirty();\n }}\n // On the form, not only on the bound fields. `focusout` bubbles where\n // `blur` does not, so React's onBlur here sees every control that was\n // left — including the uncontrolled ones, which are most of them and\n // would otherwise never be marked touched at all.\n onBlur={(event) => {\n const target = event.target as unknown as {\n name?: string;\n value?: string;\n };\n const name = target.name;\n\n if (!name) return;\n\n // Leaving a field is the moment to check it; leaving the form is\n // not the same moment. Focus going to nothing, or to something\n // outside the form, is a click on the page - most often a dialog\n // closing - and an error painted into a dialog as it animates out\n // reads as a submit that nobody made. An empty field left that way\n // is not checked at all. One with something in it is, but only\n // once the dust settles: if the form is gone or hidden by then, it\n // was a dialog closing, and nobody is there to read the error.\n const left = event.relatedTarget as Node | null;\n const stillInForm = !!left && !!formRef.current?.contains(left);\n\n if (stillInForm) {\n void touch(name);\n\n return;\n }\n\n if (!target.value) return;\n\n setTimeout(() => {\n const form = formRef.current;\n\n if (\n !form ||\n !form.isConnected ||\n form.getClientRects().length === 0\n )\n return;\n // A submit in flight is not a dialog closing, and its answer is\n // the verdict on every field. On iOS a tap on the submit button\n // does not focus it, so the last field's blur arrives here as\n // \"left the form\" - and by now the fields may be disabled for\n // the pending submit, missing from its data, and judged absent:\n // \"last name is required\" flashed on the way to the next step.\n if (pendingRef.current) return;\n // Nor a field disabled by now, for the same reason: its value is\n // not in the form's data, so it would always read as missing.\n if ((event.target as { disabled?: boolean }).disabled) return;\n if (\n form.closest(\n \"[hidden], [aria-hidden='true'], [data-ending-style], [data-closed]\",\n )\n )\n return;\n\n void touch(name);\n }, LEAVE_FORM_SETTLE_MS);\n }}\n onMouseEnter={prefetch === \"hover\" ? doPrefetch : undefined}\n data-pending={isPending ? \"\" : undefined}\n {...rest}\n >\n {typeof children === \"function\" ? children(formStatus) : children}\n </form>\n </FormStatusContext.Provider>\n </FormStoreContext.Provider>\n );\n}\n\n// Also by name, because both spellings are in use: `import Form` and\n// `import { Form }`. This was a re-export of \"./Form\" — from inside Form.tsx,\n// so the module named itself. It survived on the bundler tolerating a circular\n// self-reference, left over from when a separate barrel re-exported a\n// FormComponent.tsx that a case-insensitive filesystem would not let be called\n// Form.ts. There is one file now, and it can just export what it declares.\nexport { Form };\n"]}