@funstack/ui 0.1.0-alpha.16 → 0.1.0-alpha.17

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 (143) hide show
  1. package/dist/accordion/accordion-root.mjs +1 -1
  2. package/dist/accordion/accordion-root.mjs.map +1 -1
  3. package/dist/button/button.d.mts +21 -8
  4. package/dist/button/button.d.mts.map +1 -1
  5. package/dist/button/button.mjs +8 -6
  6. package/dist/button/button.mjs.map +1 -1
  7. package/dist/checkbox-group/checkbox-group-root.mjs +5 -1
  8. package/dist/checkbox-group/checkbox-group-root.mjs.map +1 -1
  9. package/dist/combobox/combobox-popup.d.mts +4 -1
  10. package/dist/combobox/combobox-popup.d.mts.map +1 -1
  11. package/dist/combobox/combobox-popup.mjs.map +1 -1
  12. package/dist/combobox/combobox-root.d.mts +15 -5
  13. package/dist/combobox/combobox-root.d.mts.map +1 -1
  14. package/dist/combobox/combobox-root.mjs +9 -11
  15. package/dist/combobox/combobox-root.mjs.map +1 -1
  16. package/dist/combobox/combobox-trigger.mjs +7 -2
  17. package/dist/combobox/combobox-trigger.mjs.map +1 -1
  18. package/dist/dialog/dialog-close.d.mts +13 -3
  19. package/dist/dialog/dialog-close.d.mts.map +1 -1
  20. package/dist/dialog/dialog-close.mjs +3 -2
  21. package/dist/dialog/dialog-close.mjs.map +1 -1
  22. package/dist/dialog/dialog-context.mjs.map +1 -1
  23. package/dist/dialog/dialog-form.d.mts +2 -1
  24. package/dist/dialog/dialog-form.d.mts.map +1 -1
  25. package/dist/dialog/dialog-form.mjs.map +1 -1
  26. package/dist/dialog/dialog-popup.d.mts +9 -4
  27. package/dist/dialog/dialog-popup.d.mts.map +1 -1
  28. package/dist/dialog/dialog-popup.mjs +12 -20
  29. package/dist/dialog/dialog-popup.mjs.map +1 -1
  30. package/dist/dialog/dialog-root.d.mts +38 -24
  31. package/dist/dialog/dialog-root.d.mts.map +1 -1
  32. package/dist/dialog/dialog-root.mjs +10 -8
  33. package/dist/dialog/dialog-root.mjs.map +1 -1
  34. package/dist/dialog/dialog-trigger.d.mts +3 -3
  35. package/dist/dialog/dialog-trigger.mjs.map +1 -1
  36. package/dist/dialog/index.d.mts +5 -5
  37. package/dist/dialog/index.mjs +5 -5
  38. package/dist/dialog/index.mjs.map +1 -1
  39. package/dist/docs/components/button.md +65 -21
  40. package/dist/docs/components/checkbox-group.md +12 -3
  41. package/dist/docs/components/combobox.md +85 -22
  42. package/dist/docs/components/context-menu.md +8 -8
  43. package/dist/docs/components/dialog.md +42 -36
  44. package/dist/docs/components/menu.md +106 -25
  45. package/dist/docs/components/popover.md +101 -36
  46. package/dist/docs/components/progress.md +1 -1
  47. package/dist/docs/components/slider.md +1 -1
  48. package/dist/docs/components/toast.md +37 -14
  49. package/dist/docs/components/toolbar.md +2 -1
  50. package/dist/docs/components/tooltip.md +1 -1
  51. package/dist/docs/concepts/action-props.md +55 -25
  52. package/dist/docs/concepts/browser-owned-state.md +27 -12
  53. package/dist/docs/concepts/pending-and-optimistic.md +15 -2
  54. package/dist/docs/concepts/render.md +23 -0
  55. package/dist/docs/concepts/server-components.md +15 -1
  56. package/dist/docs/concepts/suspense.md +8 -3
  57. package/dist/docs/concepts/transitions.md +3 -9
  58. package/dist/docs/getting-started.md +9 -22
  59. package/dist/docs/index.md +5 -4
  60. package/dist/docs/roadmap.md +54 -0
  61. package/dist/docs/why.md +7 -3
  62. package/dist/index.d.mts +2 -2
  63. package/dist/internal/call-urgent-handler.mjs +37 -0
  64. package/dist/internal/call-urgent-handler.mjs.map +1 -0
  65. package/dist/internal/css-transition-cut.mjs +66 -0
  66. package/dist/internal/css-transition-cut.mjs.map +1 -0
  67. package/dist/internal/overlay-popup.mjs.map +1 -1
  68. package/dist/internal/report-dropped.mjs +45 -0
  69. package/dist/internal/report-dropped.mjs.map +1 -0
  70. package/dist/internal/types.d.mts +33 -7
  71. package/dist/internal/types.d.mts.map +1 -1
  72. package/dist/internal/use-action-trigger.mjs +32 -17
  73. package/dist/internal/use-action-trigger.mjs.map +1 -1
  74. package/dist/internal/use-controllable-action.mjs +52 -16
  75. package/dist/internal/use-controllable-action.mjs.map +1 -1
  76. package/dist/internal/use-exit-animation.mjs +1 -1
  77. package/dist/internal/use-exit-animation.mjs.map +1 -1
  78. package/dist/internal/use-native-group-reconciliation.mjs +4 -2
  79. package/dist/internal/use-native-group-reconciliation.mjs.map +1 -1
  80. package/dist/internal/use-overlay-close.mjs +10 -4
  81. package/dist/internal/use-overlay-close.mjs.map +1 -1
  82. package/dist/internal/use-overlay-root.mjs +40 -7
  83. package/dist/internal/use-overlay-root.mjs.map +1 -1
  84. package/dist/internal/use-popover-popup.mjs +22 -7
  85. package/dist/internal/use-popover-popup.mjs.map +1 -1
  86. package/dist/internal/use-popover-trigger.d.mts +1 -1
  87. package/dist/internal/use-popover-trigger.d.mts.map +1 -1
  88. package/dist/internal/use-popover-trigger.mjs +11 -3
  89. package/dist/internal/use-popover-trigger.mjs.map +1 -1
  90. package/dist/menu/menu-checkbox-item.d.mts +1 -1
  91. package/dist/menu/menu-checkbox-item.mjs.map +1 -1
  92. package/dist/menu/menu-item.d.mts +15 -4
  93. package/dist/menu/menu-item.d.mts.map +1 -1
  94. package/dist/menu/menu-item.mjs +10 -5
  95. package/dist/menu/menu-item.mjs.map +1 -1
  96. package/dist/menu/menu-outside.mjs +2 -2
  97. package/dist/menu/menu-outside.mjs.map +1 -1
  98. package/dist/menu/menu-popup.d.mts +3 -0
  99. package/dist/menu/menu-popup.d.mts.map +1 -1
  100. package/dist/menu/menu-popup.mjs.map +1 -1
  101. package/dist/menu/menu-root.d.mts +27 -12
  102. package/dist/menu/menu-root.d.mts.map +1 -1
  103. package/dist/menu/menu-root.mjs +5 -4
  104. package/dist/menu/menu-root.mjs.map +1 -1
  105. package/dist/number-field/number-field-root.d.mts.map +1 -1
  106. package/dist/number-field/number-field-root.mjs +2 -8
  107. package/dist/number-field/number-field-root.mjs.map +1 -1
  108. package/dist/popover/index.d.mts +3 -3
  109. package/dist/popover/index.mjs +3 -3
  110. package/dist/popover/index.mjs.map +1 -1
  111. package/dist/popover/popover-close.d.mts +14 -3
  112. package/dist/popover/popover-close.d.mts.map +1 -1
  113. package/dist/popover/popover-close.mjs +4 -2
  114. package/dist/popover/popover-close.mjs.map +1 -1
  115. package/dist/popover/popover-popup.d.mts +6 -3
  116. package/dist/popover/popover-popup.d.mts.map +1 -1
  117. package/dist/popover/popover-popup.mjs +3 -2
  118. package/dist/popover/popover-popup.mjs.map +1 -1
  119. package/dist/popover/popover-root.d.mts +31 -18
  120. package/dist/popover/popover-root.d.mts.map +1 -1
  121. package/dist/popover/popover-root.mjs +9 -7
  122. package/dist/popover/popover-root.mjs.map +1 -1
  123. package/dist/slider/slider-root.d.mts.map +1 -1
  124. package/dist/slider/slider-root.mjs +2 -8
  125. package/dist/slider/slider-root.mjs.map +1 -1
  126. package/dist/toast/toast-action.d.mts +14 -3
  127. package/dist/toast/toast-action.d.mts.map +1 -1
  128. package/dist/toast/toast-action.mjs +6 -4
  129. package/dist/toast/toast-action.mjs.map +1 -1
  130. package/dist/toast/toast-context.mjs.map +1 -1
  131. package/dist/toast/toast-queue.mjs.map +1 -1
  132. package/dist/toast/toast-viewport.d.mts.map +1 -1
  133. package/dist/toast/toast-viewport.mjs +15 -15
  134. package/dist/toast/toast-viewport.mjs.map +1 -1
  135. package/dist/toast/toast.d.mts +10 -7
  136. package/dist/toast/toast.d.mts.map +1 -1
  137. package/dist/toast/toast.mjs.map +1 -1
  138. package/dist/toggle-group/toggle-group-root.mjs +1 -1
  139. package/dist/toggle-group/toggle-group-root.mjs.map +1 -1
  140. package/package.json +1 -1
  141. package/skills/funstack-ui-knowledge/SKILL.md +6 -6
  142. package/dist/internal/use-superseded-rejection.mjs +0 -47
  143. package/dist/internal/use-superseded-rejection.mjs.map +0 -1
@@ -1,6 +1,6 @@
1
1
  # Action props
2
2
 
3
- FUNSTACK UI has no `onClick`, `onChange` or `onValueChange`, with [one exception, below](#urgent-lane). Interactive props are _actions_: callbacks that the component runs inside its own transition and awaits.
3
+ FUNSTACK UI has no `onClick`, `onChange` or `onValueChange`. Interactive props are _actions_: callbacks that the component runs inside its own transition and awaits. A change that had already happened when the library heard of it, and that it could not hold, is reported to an [`on*` handler](#handlers) instead.
4
4
 
5
5
  An <a id="action"></a>action is a function prop that the component calls when the user (or the browser) asks for something, inside a React transition the component starts for it. To dispatch is to start that transition and call the action once; every click, key press or platform change that asks for a change is one dispatch. A transition is React's way to mark an update as non-urgent, so it can keep the current UI on screen while the update is prepared (see [Transitions & ViewTransition](transitions.md)).
6
6
 
@@ -8,7 +8,8 @@ An <a id="action"></a>action is a function prop that the component calls when th
8
8
 
9
9
  - **Settle**: An action settles when its promise resolves or rejects (a synchronous action settles when it returns). `data-pending` stays on until the settle and the render it causes have committed.
10
10
  - **<a id="adopt"></a>Adopt**: A controlled parent adopts a dispatched value by setting its controlled prop to it (in the synchronous part of the action, or inside `startTransition` after an `await`).
11
- - **Veto**: A controlled parent refuses a change by not adopting the value: when the action settles, the optimistic value snaps back to the committed one. Only library-owned changes can be vetoed; a [dismissal](browser-owned-state.md#dismissal) cannot.
11
+ - **Veto**: A controlled parent refuses a change by not adopting the value: when the action settles, the optimistic value snaps back to the committed one. Only a [request](#request) can be vetoed; a [dismissal](browser-owned-state.md#dismissal) is a [fact](#fact) and cannot.
12
+ - **<a id="urgent-update"></a>Urgent update**: A state update outside any transition. React renders it at once, in the event that caused it, and does not hold it back for a pending transition. A `setState` in an event handler is urgent unless it is wrapped in `startTransition`.
12
13
  - **<a id="form-channel"></a>Form channel**: React's own form machinery: `<form action>`, `useFormStatus`, `useActionState` and the automatic reset after a successful action. Independent of a control's change action; see [Form actions are a separate channel](#form-actions).
13
14
 
14
15
  ## Naming
@@ -48,6 +49,45 @@ A change action that returns data, and (on [Tabs](../components/tabs.md)) one th
48
49
  <Tabs.Root defaultValue="general" valueChangeAction={(tab) => analytics.track(tab)}>...</Tabs.Root>
49
50
  ```
50
51
 
52
+ ## <a id="handlers"></a>Requests and facts: `on*` handlers
53
+
54
+ The name of a callback prop is a contract. A prop named `action` or `fooAction` receives a <a id="request"></a>request: the component calls it before the change is committed, inside a transition, and awaits it; a rejection, or a controlled parent that does not adopt the value, rolls the UI back. A prop named `onFoo` is an <a id="on-handler"></a>`on*` handler: it reports a <a id="fact"></a>fact, a change that had already happened when the library heard of it and that the library could not hold.
55
+
56
+ The test: if the callback rejects, or the parent ignores it, can the library put the UI back without the user noticing? If yes, the change is a request. A form reset or a click before hydration on a checkbox passes the test (the DOM is the optimistic state, and the library restores it on a refusal), so it is a request even though the browser changed the DOM first. A popup the user dismissed with Escape fails it: the user saw it go away.
57
+
58
+ Most state has only an action. Where both kinds of change exist, a component offers both props, and each component page documents its own handlers. Every `on*` handler the library defines follows one rule:
59
+
60
+ - Called **synchronously**, in the event that reports the fact, outside any transition: a `setState` in the body is an [urgent update](#urgent-update).
61
+ - **Not awaited**, with no pending or optimistic state: the change has already happened.
62
+ - It **may return a promise** (an `async` function, a Server Function). A rejection, like a synchronous throw, goes to `reportError`, never to an Error Boundary; a throw does not stop the library from updating the component. Nothing warns about a returned promise.
63
+
64
+ ```typescript
65
+ /** Called synchronously, outside any Transition, and not awaited. */
66
+ type UrgentChangeHandler<T, Details extends ActionDetails = ActionDetails> =
67
+ (next: T, details: Details) => void;
68
+ /** The same for a fact that carries no next value. */
69
+ type UrgentHandler<Details extends ActionDetails = ActionDetails> = (details: Details) => void;
70
+ ```
71
+
72
+ Set state directly in a handler, not inside `startTransition` and not after an `await`. The advice for actions ([wrap a state update after an await](#after-await)) does not apply: a handler is not in a transition, and a late update leaves the UI showing the old value for a while.
73
+
74
+ Example: [Popover](../components/popover.md)
75
+
76
+ An overlay's open state has both kinds of change. Opening, and a close the user asks one of its parts for (a Close button), are requests: `openChangeAction`. Escape or a click outside is a fact: the browser has already hidden the popup when `onOpenChange(false, details)` is called from its event. A controlled Root adopts both, with the same setter:
77
+
78
+ ```tsx
79
+ const [open, setOpen] = useState(false);
80
+ <Popover.Root open={open} openChangeAction={setOpen} onOpenChange={setOpen}>
81
+ ```
82
+
83
+ See [Requests and facts](browser-owned-state.md#requests-and-facts) for what each one does to the popup.
84
+
85
+ Example: [Combobox](../components/combobox.md)
86
+
87
+ ### The text of a controlled input
88
+
89
+ React requires a controlled text input to update in the same event as the keystroke, so typed text is a fact: when the library hears of it, the DOM already holds it. Combobox keeps the usual pair, `inputValue` / `defaultInputValue`, but its callback is a handler, `onInputValueChange`, not an action. `(next) => setText(next)` is the whole controlled pattern. What the text drives (a deferred query, an open, a selection) goes back to transitions at once; a fetch whose results should render belongs there, through `useDeferredValue` of the text.
90
+
51
91
  ## `details.reason`
52
92
 
53
93
  Components that can change for more than one reason say why, with one library-wide vocabulary (the public type `ChangeReason`):
@@ -56,10 +96,10 @@ Components that can change for more than one reason say why, with one library-wi
56
96
  | - | - | - |
57
97
  | `"activate"` | The user acted on one of the component's parts: a click, Enter or Space, focus in automatic activation, a Close button or a form submit. | The native `click`, `keydown` or `focusin` event. For checkboxes and radios always the `click`, including Space and arrow keys. |
58
98
  | `"platform"` | The browser changed the state by itself: find-in-page, a form reset, or an interaction before hydration found on mount. Never a direct user interaction (a click, key press or touch). | The platform event (`beforematch`, `toggle`, `reset`), or `undefined` on mount. |
59
- | `"dismiss"` | The user closed the component without one of its parts: Escape, Android back, an assistive-technology dismiss, a click outside. Also a [Toast](../components/toast.md)'s Close part, which only means "go away". | The platform's `close` event; for Toast the click or keydown. |
99
+ | `"dismiss"` | The user closed the component without one of its parts: Escape, Android back, an assistive-technology dismiss, a click outside; also a close nobody caused through the component (script, another top-layer element, focus leaving). On an overlay most of these are [facts](#fact), reported to `onOpenChange`. Also a [Toast](../components/toast.md)'s Close part, which only means "go away". | The platform's `close` or `toggle` event; for Toast the click or keydown. |
60
100
  | `"timeout"` | The library's own timer closed the component: a [Toast](../components/toast.md) whose `duration` elapsed. No user interaction, no platform event. | `undefined` |
61
101
 
62
- A component uses only the reasons that can happen to it; its page lists them in the description of its change action. A `"platform"` dispatch goes through the same action as a user one, so a controlled parent hears about a form reset and decides whether to adopt it. See [Browser-owned state](browser-owned-state.md).
102
+ A component uses only the reasons that can happen to it; its page lists them in the description of its change action and of its `on*` handler. A `"platform"` dispatch goes through the same action as a user one, so a controlled parent hears about a form reset and decides whether to adopt it. See [Browser-owned state](browser-owned-state.md).
63
103
 
64
104
  ## What happens on a click
65
105
 
@@ -80,10 +120,10 @@ What you can rely on:
80
120
 
81
121
  - **Sync or async.** The action is awaited; `data-pending` stays on until the promise settles _and_ the resulting render has committed (including a Suspense wait).
82
122
  - **The synchronous part runs during the event.** `details.event.preventDefault()` works there, and a `setState` there is a transition update.
83
- - **Disabled parts never dispatch** for user interaction, and no-op interactions (clicking the tab that is already selected) do not dispatch either. (A form reset still reaches a disabled native input: the browser resets disabled inputs too, and the form's author asked for it.)
84
- - **Parts are never natively disabled while pending.** A trigger that changes state sets `data-pending` and takes every click: a second click is a new intent (below). A [pure trigger](pending-and-optimistic.md#pure-trigger) ignores a second activation while its own action is pending and is `aria-disabled="true"` meanwhile, so a double click never runs a save twice (see [A second click while pending](pending-and-optimistic.md#second-click)).
123
+ - **Disabled parts never dispatch** for user interaction, and no-op interactions (clicking the tab that is already selected) do not dispatch either. A form reset is not a user interaction with the control: `form.reset()` resets disabled inputs too, so a disabled control still follows it, with `reason: "platform"`.
124
+ - **Parts are never natively disabled while pending.** A trigger that changes state sets `data-pending` and takes every click: a second click is a new intent (below). What a [pure trigger](pending-and-optimistic.md#pure-trigger) does with a second activation while its own action is pending is its `whilePending` prop: `"run"` runs it again (the default of a `Button`), `"ignore"` drops it and makes the part `aria-disabled="true"` meanwhile (the default of a Close part; use it on a Save that must not run twice). See [A second click while pending](pending-and-optimistic.md#second-click).
85
125
 
86
- ## After an `await`, wrap state updates yourself
126
+ ## <a id="after-await"></a>After an `await`, wrap state updates yourself
87
127
 
88
128
  This is a React rule, and the library cannot hide it: a `setState` that runs after your own `await` is no longer part of the transition. Wrap it in `startTransition`.
89
129
 
@@ -119,7 +159,7 @@ valueChangeAction={async (next) => { await saveSelection(next); }}
119
159
 
120
160
  ## Errors go to Error Boundaries
121
161
 
122
- An action that throws or rejects reaches the nearest Error Boundary above the component that owns the transition (the [state owner](pending-and-optimistic.md#state-owner): usually the `Root`, or a single-element component such as a Toggle). The library never swallows an error. The optimistic state reverts automatically, and uncontrolled state is only written after success, so a failed action leaves it untouched.
162
+ An action that throws or rejects reaches the nearest Error Boundary above the component that owns the transition (the [state owner](pending-and-optimistic.md#state-owner): usually the `Root`, or a single-element component such as a Toggle). The library never swallows an error: the rejection of an older action that a newer one superseded goes to `reportError` instead (see [Overlapping actions](action-props.md#overlapping-actions)), and so does a rejection that arrives after the component unmounted (a toast or menu closed while its action ran) or while it is hidden (an `<Activity>`, a closed overlay with `keepMounted`, or a Suspense boundary showing its fallback), since React has no render left to deliver it through. A hidden component's error is reported once and does not show the Error Boundary when the component reappears. The optimistic state reverts automatically, and uncontrolled state is only written after success, so a failed action leaves it untouched.
123
163
 
124
164
  For inline error UI instead, catch inside the action. A caught error makes the action resolve, which counts as success: in uncontrolled mode the new value is committed. Use controlled mode when the parent must be able to veto.
125
165
 
@@ -187,6 +227,8 @@ function ControlledWithInlineError() {
187
227
 
188
228
  React neither cancels nor orders overlapping transitions: two actions started one after the other run at the same time, and either may finish first. The components handle this: the optimistic state always shows the most recent click, and uncontrolled state is committed only for the most recently dispatched action, even if an older one resolves later. The components have no queue and no abort signal; if you need to cancel a request, keep an `AbortController` in a ref inside your action.
189
229
 
230
+ Components whose value is a set of items (CheckboxGroup, and ToggleGroup and Accordion without `exclusive`) commit each change on its own instead: once every overlapping action has settled, the changes whose actions resolved are applied in the order they were made, and a change whose action rejected is left out. Check A, then B: if saving A fails and saving B succeeds, the uncontrolled group ends with only B checked. B's action still received `["A", "B"]` as `next`, because A was pending when B was clicked, so save `details.added` and `details.removed` rather than the whole `next`.
231
+
190
232
  If your actions must run in order, one after another, or each must build on the result of the one before (reducer-style accumulation), use React's [`useActionState`](https://react.dev/reference/react/useActionState) and call its dispatch function from the component's action. React queues those calls and runs them sequentially, passing each the state the previous one returned. Drive the component in controlled mode from that state:
191
233
 
192
234
  Example: [Toggle](../components/toggle.md)
@@ -202,11 +244,11 @@ const [pressed, dispatch] = useActionState(async (_previous: boolean, next: bool
202
244
 
203
245
  The component stays pending and keeps showing the latest optimistic value until the queue has drained. React's rules for the queue apply: when one call throws, React skips the calls still queued behind it and the error goes to the nearest Error Boundary above the component that called `useActionState`.
204
246
 
205
- React would silently drop the rejection of a superseded (older) action. The library catches it and rethrows it from render, so it still reaches the same Error Boundary as a failure of the latest action.
247
+ When an older action rejects after a newer one has started, React does not send the error to an Error Boundary: only the latest action's failure is thrown, and the UI keeps showing the latest intent. The library does the same, and also passes the older rejection to the global `reportError`, as React's standalone `startTransition` does with a rejection it has nowhere else to send. The error is not lost: it fires the window `error` event, so error monitoring sees it, and a test runner reports it as an uncaught error.
206
248
 
207
249
  ## Server Functions work directly
208
250
 
209
- A Server Function (`"use server"`) can be passed straight to any action prop, from a Server Component or a Client Component. `details` is a plain object of serialisable fields; `event` is served by a proxy and is not an own property, so React's serialiser never sees it. The server receives `(next, details)` with `details.event` undefined and every other field intact.
251
+ A Server Function (`"use server"`) can be passed straight to any action prop, from a Server Component or a Client Component, without a client wrapper. The server receives the same arguments, `(next, details)`, with one difference: a DOM event cannot be sent to the server, so `details.event` is `undefined` there. Every other field of `details` (`reason`, for example) arrives intact.
210
252
 
211
253
  Example: [Toggle](../components/toggle.md)
212
254
 
@@ -220,9 +262,9 @@ import { setFavorite } from "./actions"; // "use server"
220
262
  </Toggle>
221
263
  ```
222
264
 
223
- > **Costs of the virtual event**
265
+ > **details.event is not an ordinary field**
224
266
  >
225
- > `Object.keys(details)`, spreading and `JSON.stringify` do not include `event`; `"event" in details` and `details.event` do. `structuredClone(details)` throws. In tests, assert `details.event` directly rather than `toEqual({ event })`.
267
+ > To keep `details` serialisable, `event` is not an own property of the object, so some operations do not see it. `Object.keys(details)`, spreading and `JSON.stringify` do not include `event`; `"event" in details` and `details.event` do. `structuredClone(details)` throws. In tests, assert `details.event` directly rather than `toEqual({ event })`.
226
268
 
227
269
  ## <a id="form-actions"></a>Form actions are a separate channel
228
270
 
@@ -231,21 +273,9 @@ import { setFavorite } from "./actions"; // "use server"
231
273
  - A native form control (a Switch, for example) inside `<form action={serverFn}>` needs no change action: with a `name` it posts its value like any native input, and `useFormStatus().pending` covers the submit.
232
274
  - A control never folds `useFormStatus` into its own `pending`: that would mark every control in the form pending during a submit. Read `useFormStatus` in your own `className` function, or style `form:has(...)`.
233
275
  - "Autosave on change" is `checkedChangeAction={saveSetting}`; "submit on change" is `checkedChangeAction={() => formRef.current?.requestSubmit()}`.
234
- - A part may observe the form channel for a platform side effect: `Dialog.Form` closes its dialog once the form action has settled. It never wraps your action, so a Server Function keeps React's progressive enhancement.
276
+ - A part may observe the form channel for a platform side effect: `Dialog.Form` closes its dialog once the form action has settled. It watches the form's status and passes your action to `<form action>` unchanged, instead of wrapping it in a function of its own. That matters for a Server Function: React can only [submit a form before JavaScript loads](https://react.dev/reference/react-dom/components/form#handle-form-submission-with-a-server-function) when the `action` is the Server Function itself; a client wrapper around it would need JavaScript to run.
235
277
  - While a form action is pending, a control's transition waits for it, and the reverse: React commits them together.
236
278
 
237
- ## <a id="urgent-lane"></a>The urgent lane
238
-
239
- One kind of state cannot be a transition: the text of a controlled text input, which React must update in the same event as the keystroke. Such a state keeps the `x` / `defaultX` pair (`inputValue` / `defaultInputValue` on [Combobox](../components/combobox.md)), but its callback is a handler, not an action: `onInputValueChange`, typed:
240
-
241
- ```typescript
242
- /** Called synchronously, outside any Transition, and not awaited. */
243
- type UrgentChangeHandler<T, Details extends ActionDetails = ActionDetails> =
244
- (next: T, details: Details) => void;
245
- ```
246
-
247
- Nothing is pending or optimistic for it: the DOM already holds the value when it runs, so `(next) => setText(next)` is the whole controlled pattern. Everything the urgent value drives leaves the urgent lane at once (a deferred query, an open, a selection). A returned promise is ignored and warned about in development. It is the library's one `on*` prop, and it is one on purpose: `fooAction` always means a handler the component runs in a transition, so a callback that must not run in one is named like the plain React handler it is. Nothing else the library defines is an `on*`prop.
248
-
249
279
  ## What about native handlers?
250
280
 
251
281
  DOM event props that a part does not use itself pass through to the element (an `onPointerEnter` on a Tab, an `onClick` on a Tooltip trigger). They are the platform's API, not the library's. Handlers the part does install (for example `onClick` on a Toggle) are removed from its props type so they cannot be clobbered by accident.
@@ -10,9 +10,9 @@
10
10
  - **<a id="invoker"></a>Invoker**: A button that names a popover or dialog by id, so that the browser itself opens or closes it on click, without JavaScript: through `popovertarget` (the Popover API) or through `commandfor` and `command` (Invoker Commands). A `<button>` or an `<input type="button">` / `<input type="reset">` can be one; a disabled button and a submit button inside a form are not. See [Triggers of a popup](#popup-triggers).
11
11
  - **<a id="foreign-invoker"></a>Foreign invoker**: An invoker of your own that targets a component's popup or dialog, but is not one of the component's parts.
12
12
  - **<a id="platform-path"></a>Platform path**: A change the browser makes to library-owned state on its own, without a click the library sees: a form reset, find-in-page opening an item, a click before hydration. The component dispatches it like a user change, with `details.reason: "platform"`, and re-applies the committed state afterwards.
13
- - **Notification**: A change action called after the browser has already made the change (a dismissal, a platform path). It is still awaited, but the UI did not wait for it: nothing can be vetoed, only re-applied.
14
- - **<a id="parts-close"></a>A part's close**: A close the user asks one of the component's parts for (a Close button, the Trigger, a form submit). It is library-owned: dispatched in a transition, awaited, vetoable and animatable. The opposite of a dismissal.
15
- - **<a id="js-free-mode"></a>JS-free mode and library mode**: Some components can run either way. In **JS-free mode** (no controlled or default state and no change action), the browser owns the state and the library adds no behaviour on the native path. In **library mode** (any of those props), the state is library-owned. See [Two modes](#two-modes).
13
+ - **Request and fact**: A [request](action-props.md#request) is a change the library can still roll back: it goes to an action prop (`openChangeAction`) before it is committed. A [fact](action-props.md#fact) is a change that had already happened when the library heard of it, and that it could not hold: it is reported to an [\`on\*\` handler](action-props.md#on-handler) (`onOpenChange`). Both terms are defined on Action props; see [Requests and facts](#requests-and-facts) for what they mean for a popup.
14
+ - **<a id="parts-close"></a>A part's close**: A close the user asks one of the component's parts for (a Close button, the Trigger, a form submit). It is a request: dispatched in a transition, awaited, vetoable and animatable. The opposite of a dismissal.
15
+ - **<a id="js-free-mode"></a>JS-free mode and library mode**: Some components can run either way. In **JS-free mode** (no controlled or default state, no change action and no `on*` handler), the browser owns the state and the library adds no behaviour on the native path. In **library mode** (any of those props), the state is library-owned. See [Two modes](#two-modes).
16
16
 
17
17
  ## Two kinds of state
18
18
 
@@ -20,11 +20,11 @@
20
20
  | - | - | - |
21
21
  | Who changes it | the library, inside its transition | the browser (hover, light dismiss, Escape, find-in-page, a summary click, an [invoker](#invoker)) |
22
22
  | Optimistic state | React state ([optimistic](pending-and-optimistic.md#optimistic), `useOptimistic`) | the DOM itself |
23
- | Action prop | awaited; the UI waits for it | a notification after the fact, or none |
23
+ | Callback | an action prop for a [request](action-props.md#request), awaited; an `on*` handler for a [fact](action-props.md#fact) (typed text) | an `on*` handler for a fact (`onOpenChange`), not awaited; or none |
24
24
  | Styling | `data-*` attributes | pseudo-classes: `:popover-open`, `:open` |
25
25
  | Animation | `transition` prop (`<ViewTransition>`) | CSS: `@starting-style`, `transition-behavior: allow-discrete` |
26
26
 
27
- The library never mirrors browser-owned state into React state. It reads the DOM when it needs to, and it does not duplicate a pseudo-class with a data attribute. State that nobody persists or awaits (whether a hint is showing) is left to the browser entirely, with no prop and no action. One read is mirrored: whether a popup is shown, where no native element exposes it to assistive technology: on a Trigger that is no invoker, and on the Combobox input (see [Triggers of a popup](#popup-triggers)). Each component page says what it leaves to the browser in its **Browser-owned state** section.
27
+ The library never mirrors browser-owned state into React state. It reads the DOM when it needs to, and it does not duplicate a pseudo-class with a data attribute. State that nobody persists or awaits is left to the browser entirely, with no prop and no action. Whether a hint popup (such as a tooltip) is showing is one example. One read is mirrored: whether a popup is shown, where no native element exposes it to assistive technology: on a Trigger that is no invoker, and on the Combobox input (see [Triggers of a popup](#popup-triggers)). Each component page says what it leaves to the browser in its **Browser-owned state** section.
28
28
 
29
29
  Example: [Tooltip](../components/tooltip.md)
30
30
 
@@ -42,7 +42,7 @@ A tooltip's visibility is not application state. The popup is a `popover` in the
42
42
 
43
43
  ## <a id="two-modes"></a>Two modes, one anatomy
44
44
 
45
- Some components built on a native element that does the whole interaction offer both (their pages have a **Two modes** section). Without any controlled value, default value or change action it runs in [JS-free mode](#js-free-mode): the browser owns the state and nothing runs when it changes. Add any of them and the component switches to **library mode**: the native interaction is intercepted, the state is React state changed in a transition, and triggers get optimistic data attributes and `data-pending`. The parts and the markup are the same in both. The mode is decided on the first render; switching between them later is not supported (development warning).
45
+ Some components built on a native element that does the whole interaction offer both (their pages have a **Two modes** section). Without any controlled value, default value, change action or `on*` handler it runs in [JS-free mode](#js-free-mode): the browser owns the state and nothing runs when it changes. Add any of them and the component switches to **library mode**: the native interaction is intercepted, the state is React state changed in a transition, and triggers get optimistic data attributes and `data-pending`. The parts and the markup are the same in both. The mode is decided on the first render; switching between them later is not supported (development warning).
46
46
 
47
47
  The browser can still change the state in library mode (find-in-page, a text fragment, a click before hydration). The component turns that into a regular dispatch with `details.reason === "platform"`, and once the action settles it re-applies the committed state to the DOM, so a controlled parent that refuses the change gets its state back.
48
48
 
@@ -58,15 +58,30 @@ An Accordion without `value`, `defaultValue` and `valueChangeAction` leaves ever
58
58
  <Accordion.Root exclusive defaultValue={null} valueChangeAction={save}>...</Accordion.Root>
59
59
  ```
60
60
 
61
- ## Parts vs dismissals
61
+ ## Requests and facts
62
62
 
63
- For something that opens and closes in library mode, ownership is split by **who asked**. Opening, and a close the user asks one of the component's parts for, belong to the library: the click, submit or command is cancelled and dispatched in a transition, the action is awaited, a controlled parent can refuse it, and it can animate with a view transition. A [dismissal](#dismissal) belongs to the browser: the element closes natively and at once, the change action is called afterwards as a notification with `reason: "dismiss"`, and a controlled parent that refuses cannot keep it open (it can only open it again).
63
+ For something that opens and closes in library mode, a change is either a [request](action-props.md#request) or a [fact](action-props.md#fact), and each has its own prop. Opening, and a close the user asks one of the component's parts for, are requests: the click, submit or command is cancelled and dispatched in a transition, `openChangeAction` is awaited, a controlled parent can veto it, and it can animate with a view transition. A [dismissal](#dismissal) is a fact: the element closes natively and at once, and `onOpenChange(false, details)` is called synchronously from the browser's own event. Nothing is pending, no view transition runs (a CSS exit animates it), and the committed state is `false` in the same event. A close the library performs itself but cannot hold, because the user has already moved on (focus leaving the popup), is a fact too.
64
64
 
65
- The line sits where the platform lets the library cancel a step freely: a part's click (which cancels its command), a `command` event, a form's `submit`. A dismissal goes through a close request instead, whose `cancel` the browser honours only once per user activation, and a user who pressed Escape expects the element to go away now. So the library never promises to hold a dismissal.
65
+ The line sits where the platform lets the library cancel a step freely: a part's click (which cancels its command), a `command` event, a form's `submit`. Escape and the back gesture reach the element as an HTML [close request](https://html.spec.whatwg.org/multipage/interaction.html#close-requests) (the platform's term, not a request in the sense above), whose `cancel` event the browser honours only once per user activation, and a user who pressed Escape expects the element to go away now. So the library never holds a dismissal.
66
+
67
+ A popup the browser opened before hydration is still a request (`openChangeAction(true, { reason: "platform" })`): the library can roll it back by hiding the empty popup, and its load-on-open code runs. So `onOpenChange` is only ever called with `false`.
68
+
69
+ **Controlled mode needs both props.** Pass the same setter to both: `openChangeAction` adopts a request (in a transition), `onOpenChange` adopts a fact (an [urgent update](action-props.md#urgent-update)). Set state directly in `onOpenChange`, never in `startTransition` and never after an `await`: a parent that still says `open={true}` once the browser's event has been handled gets the element shown again at once, and a late `false` then closes it a second time. A controlled Root without `onOpenChange` warns in development.
70
+
71
+ A parent that keeps `open={true}` after a dismissal on purpose gets the same re-open. This is not a veto: the user sees the element close and come back, possibly for a frame. A popup that must not be dismissed is set up on the platform side instead, where the component offers it. The re-open applies no initial focus of its own: a Menu, a Combobox or a Popover rendered as a `<div>` shown again this way leaves focus where the dismissal put it (the Trigger after Escape, the next field after Tab), so a parent that never adopts `false` cannot trap the keyboard in it. A popup that is a `<dialog>` (a Dialog, a Popover by default) still gets the browser's dialog focusing steps on the re-show, as on any open.
72
+
73
+ **Uncontrolled, pass what you need.** `openChangeAction` for work an open or a part's close must wait for (loading data on open); `onOpenChange` to observe a dismissal (logging it, remembering it). To hear every close, pass one function to both props and check its first argument: the action is called with `true` for an open too.
66
74
 
67
75
  Example: [Dialog](../components/dialog.md)
68
76
 
69
- A library-mode Dialog opens through its Trigger and closes through its Close parts and `Dialog.Form` after `openChangeAction` resolves. Escape or a click outside closes it at once, and `openChangeAction(false, details)` follows with `reason: "dismiss"`; a controlled parent that keeps `open` gets the dialog re-opened once the action settles.
77
+ A library-mode Dialog opens through its Trigger and closes through its Close parts and `Dialog.Form` after `openChangeAction` resolves. Escape or a click outside closes it at once and calls `onOpenChange(false, details)` with `reason: "dismiss"`. Controlled, with both props:
78
+
79
+ ```tsx
80
+ const [open, setOpen] = useState(false);
81
+ <Dialog.Root open={open} openChangeAction={setOpen} onOpenChange={setOpen}>
82
+ ```
83
+
84
+ A Dialog without `lightDismiss` ignores a click outside; Escape still closes a modal dialog.
70
85
 
71
86
  ## <a id="popup-triggers"></a>Triggers of a popup
72
87
 
@@ -78,13 +93,13 @@ A component whose popup is a popover has a **Trigger**: the part that opens and
78
93
 
79
94
  A component may give up one of these on purpose; its page says so.
80
95
 
81
- Only a `<button>` can be the Trigger's invoker. A Trigger rendered as a link or another element works through the library's click handler instead, and has none of the above: it renders `aria-expanded` itself, from whether the popup is shown; and a press on it while the popup is open counts as a click outside, so light dismiss closes the popup before the click arrives. That close is not awaited, a controlled parent cannot refuse it, and there is no exit transition. A development warning says so. A disabled Trigger that stays focusable (it renders `aria-disabled`) is no invoker either, so that nothing native can open the popup.
96
+ Only a `<button>` can be the Trigger's invoker. A Trigger rendered as a link or another element works through the library's click handler instead, and has none of the above: it renders `aria-expanded` itself, from whether the popup is shown; and a press on it while the popup is open counts as a click outside, so light dismiss closes the popup before the click arrives. That close is a [fact](action-props.md#fact), reported to `onOpenChange` (with `reason: "activate"` and the click), not a request: it is not awaited, a controlled parent cannot veto it, and there is no view transition. A development warning says so. A disabled Trigger that stays focusable (it renders `aria-disabled`) is no invoker either, so that nothing native can open the popup.
82
97
 
83
98
  **Two kinds of open state on a Trigger.** What assistive technology hears is whether the popup is shown. In library mode, `data-open` is the [optimistic](pending-and-optimistic.md#optimistic) state: it flips at the click, while an open that waits for an action or for content is still pending. Style click feedback with `[data-open]` and `[data-pending]`, never with `[aria-expanded]`, which a `<button>` Trigger does not have. An element that controls a popup without being its invoker, such as the Combobox input, renders `aria-expanded` from the shown popup too.
84
99
 
85
100
  **One Trigger per Root.** The library anchors the popup to its Trigger or returns focus to it, so a Root has one. A second Trigger in the same Root is not supported (development warning); use a Root per trigger.
86
101
 
87
- **Foreign invokers.** A [foreign invoker](#foreign-invoker) still works in library mode. An open through it is routed through the library like the Trigger's, so the action runs and the content loads first. A close through it is reported with `reason: "activate"`, because the user asked for it; each component page says whether that close is awaited or a notification. A component that keeps focus in its popup or its input does not lose it when you press a foreign invoker: the invoker's own close is the only one.
102
+ **Foreign invokers.** A [foreign invoker](#foreign-invoker) still works in library mode. An open through it is routed through the library like the Trigger's, so the action runs and the content loads first. A close through it has `reason: "activate"`, because the user acted on a button. It is a request where the component routes it through the library (it cancels the invoker's step and closes after `openChangeAction`), and a [fact](action-props.md#fact) reported to `onOpenChange` where the browser performs it first; each component page says which. A component that keeps focus in its popup or its input does not lose it when you press a foreign invoker: the invoker's own close is the only one.
88
103
 
89
104
  Example: [Popover](../components/popover.md)
90
105
 
@@ -215,6 +215,7 @@ Each component page lists which of its parts show which value in its **Optimisti
215
215
  - **On the state owner** while its transition is pending.
216
216
  - **On the trigger the user is waiting on**: the one whose optimistic value differs from the committed one, or that started the action. Decorative parts that follow the trigger (an indicator) may mirror it.
217
217
  - **Never on content regions.** A content region shows the committed value or nothing; it is never "in between". To dim the old content while the next one loads, select through the state owner.
218
+ - **Never for a fact.** A [fact](action-props.md#fact), a change that had already happened when the library heard of it (a popup dismissed with Escape or a click outside), is reported to an `on*` handler and is not awaited, so nothing is pending for it: the popup, `data-open` and the committed state all change at once ([Requests and facts](browser-owned-state.md#requests-and-facts)).
218
219
 
219
220
  The same names exist in the function props (`className`, `style`, `children` as a function of state): `state.pending`, and the state's own name such as `state.pressed`, `state.selected` or `state.open`.
220
221
 
@@ -235,11 +236,23 @@ Example: [Tabs](../components/tabs.md)
235
236
 
236
237
  ## <a id="second-click"></a>A second click while pending
237
238
 
238
- A trigger that changes state takes every click: a second click on a pending trigger is a new intent, the optimistic value follows it, and the latest intent wins (see [Overlapping actions](action-props.md#overlapping-actions)). A [pure trigger](#pure-trigger) ignores a second click, Enter or Space while its own action is pending, and renders `aria-disabled="true"` for as long as it shows `data-pending`, so a double click never runs a save twice. Neither kind is ever natively disabled, so focus stays where it is.
239
+ A trigger that changes state takes every click: a second click on a pending trigger is a new intent, the optimistic value follows it, and the latest intent wins (see [Overlapping actions](action-props.md#overlapping-actions)). A [pure trigger](#pure-trigger) has no value to protect, so what a second click, Enter or Space does while its own action is pending is its `whilePending` prop:
240
+
241
+ - `"run"`: the activation runs the action again, in the same transition. The part shows `data-pending` until every run has settled, and is not `aria-disabled`: it still acts.
242
+ - `"ignore"`: the activation starts nothing and its default action (a link's navigation, a form submission, a command) is cancelled. The part renders `aria-disabled="true"` for as long as it shows `data-pending`, so a screen-reader user who presses again hears that it is unavailable.
243
+
244
+ The default follows **who owns the action**. Where the action is yours alone (a `Button`), every click runs, as with React's own `useTransition`: only you know whether two overlapping runs are a bug (Save) or the point (a counter). Where the library acts after your action (a `Dialog.Close` or `Popover.Close` closes its overlay, a `Menu.Item` closes its menu, a `Toast.Action` closes its toast), a second activation is ignored: the first one already ends in that close. Switch the library's close off (`closeOnActivate={false}`, `closeOnSettle={false}`) and the item or action becomes yours, so it runs every activation again. Either way the prop overrides the default, and no part is ever natively disabled, so focus stays where it is. A closing part in `"run"` mode closes once, when its last run has settled, and only if the latest run resolved: a rejection leaves the overlay, menu or toast open, as it does in `"ignore"` mode.
239
245
 
240
246
  Example: [Button](../components/button.md)
241
247
 
242
- A `Button` is a pure trigger. While the promise its `action` returned is pending, it ignores further clicks and carries `aria-disabled`. For a button that should count every click (a "+1"), do not return the promise: `action={() => { void increment(); }}`.
248
+ A counter wants every click; a Save must not run twice. Opt the Save in to `"ignore"`:
249
+
250
+ ```tsx
251
+ <Button action={async () => { await incrementOnServer(); }}>+1</Button> // every click runs
252
+ <Button action={save} whilePending="ignore">Save</Button> // one save at a time
253
+ ```
254
+
255
+ In `"run"` mode the runs overlap, and their errors follow [the usual rule](action-props.md#overlapping-actions): the latest run's rejection reaches the Error Boundary, an older run's goes to `reportError`. For runs that must happen one after another, each seeing the previous result, use `useActionState` and call its dispatch from the action.
243
256
 
244
257
  ## Rollback
245
258
 
@@ -0,0 +1,23 @@
1
+ # Replacing the element: render
2
+
3
+ Every [part](../getting-started.md#part) that renders an element accepts `render`. Use it when the default element is not the one you want: a button from your design system, a link instead of a button. You don't need it to style a part; for that, see [Getting started](../getting-started.md).
4
+
5
+ ## Two forms
6
+
7
+ The element form replaces the default element and merges the library's props into it. The function form hands you the props and the state, and you render the element yourself.
8
+
9
+ ```tsx
10
+ // Element form: a design-system button. It must accept `ref` and spread its props.
11
+ <Toggle render={<MyButton variant="ghost" />}>Bold</Toggle>
12
+
13
+ // Function form: full control.
14
+ <Toggle render={(props, state) => <button {...props}>{state.pressed ? "On" : "Off"}</button>} />
15
+ ```
16
+
17
+ On every component page, each part's props table is followed by two fixed lines: **State**, the object the function props and `render` receive, and **Owned**, the props the part sets itself, which a `render` element cannot override. Everything not listed passes through to the element.
18
+
19
+ ## Merge rules for the element form
20
+
21
+ - `className` values are concatenated; `style` objects are merged (the element wins). Event handlers the part installs run after the element's own.
22
+ - Attributes the part computes (its `role`, ARIA state, ids, `data-*` state) always win. ARIA id lists (`aria-describedby`, `aria-labelledby`, `aria-controls`) are merged instead.
23
+ - Everything else, the element wins. `type="button"` is added when the rendered element is a `<button>` or a component (which may render one), and left out for another HTML element such as `<a>`.
@@ -28,7 +28,7 @@ export function Settings() {
28
28
 
29
29
  Compound parts find their Root through context, and a Server Component cannot read context, so parts are client modules. The exceptions are [Progress](../components/progress.md) and [Meter](../components/meter.md): their Roots have no `"use client"` (they only compute, then render a context provider created in a client module), so a Server Component renders the Root on the server, may pass it function props, and only the small context module and the parts reach the browser.
30
30
 
31
- Server-rendered ids inside FUNSTACK Static `defer()` need `@funstack/static` 1.3.4 or later; other frameworks that render several server payloads into one page must give each its own `identifierPrefix`, or ids from different payloads can collide.
31
+ A framework that renders several server payloads into one page must give each its own `identifierPrefix`, or server-rendered ids from different payloads can collide.
32
32
 
33
33
  ## <a id="js-free"></a>What "JS-free" means
34
34
 
@@ -51,6 +51,20 @@ import { saveOpenSections } from "./actions"; // "use server"
51
51
  </Accordion.Root>
52
52
  ```
53
53
 
54
+ A Server Function can be passed to an [`on*` handler](action-props.md#on-handler) too: it is called and not awaited, nothing shows pending, and a rejection goes to `reportError`.
55
+
56
+ Example: [Dialog](../components/dialog.md)
57
+
58
+ A Dialog closed by its Close button is a request (`openChangeAction`), and closed with Escape a fact (`onOpenChange`). To remember either, pass the Server Function to both props. It receives `(open, details)`; this dialog has no Trigger, so it is only ever called with `false`.
59
+
60
+ ```tsx
61
+ <Dialog.Root
62
+ defaultOpen={!user.sawWelcome}
63
+ openChangeAction={rememberClosed}
64
+ onOpenChange={rememberClosed}
65
+ >
66
+ ```
67
+
54
68
  ## Before hydration
55
69
 
56
70
  The server HTML of every part carries its markup, its ARIA attributes and its data attributes, so it is accessible and styled from the first paint. What the user can _do_ before hydration depends on who performs the interaction:
@@ -97,7 +97,7 @@ The same rule has two more shapes. Content that is hidden until a state opens it
97
97
 
98
98
  Example: [Accordion](../components/accordion.md#suspense)
99
99
 
100
- `Accordion.Panel` is always mounted; its function child receives the committed `open` state, which is how content is mounted lazily. In library mode, if that content suspends, the item stays closed with the trigger pending until the content is ready, then opens.
100
+ `Accordion.Panel` is always mounted; its function child receives the committed `open` state, which is how content is mounted lazily. In [library mode](browser-owned-state.md#two-modes), if that content suspends, the item stays closed with the trigger pending until the content is ready, then opens.
101
101
 
102
102
  Example: [Combobox](../components/combobox.md#suspense)
103
103
 
@@ -119,6 +119,11 @@ Example: [Tabs](../components/tabs.md)
119
119
 
120
120
  To get a fresh fallback per tab rather than a wait, key the boundary: `<Suspense key={tab}>`.
121
121
 
122
- ## What must not suspend
122
+ ## Keep triggers from suspending
123
123
 
124
- [Trigger](pending-and-optimistic.md#trigger) content is rendered from [optimistic state](pending-and-optimistic.md#optimistic), which updates synchronously, and a synchronous render that suspends shows a fallback. A `children` function on a trigger must not suspend, or must have its own boundary inside the trigger. The props tables mark these props "must not suspend". Content that a component renders ahead of time, before it is shown, follows the same rule: keep it static or put the boundary inside the part that shows it.
124
+ A [trigger](pending-and-optimistic.md#trigger) should answer a click at once. Its content is rendered from [optimistic state](pending-and-optimistic.md#optimistic), which React renders right away rather than in the transition. React shows a fallback when such a render suspends, so if a trigger's content suspends, the nearest Suspense boundary above it replaces the trigger (and everything else inside that boundary) with its fallback. That is React working as designed, but rarely what you want.
125
+
126
+ To keep the trigger on screen:
127
+
128
+ - Don't suspend in a trigger's `children` function, or give the part that suspends its own Suspense boundary inside the trigger. The props tables mark these props "must not suspend".
129
+ - Do the same for content that a component renders ahead of time, before it is shown: keep it static, or put the boundary inside the part that shows it.
@@ -40,7 +40,7 @@ Example: [Tabs](../components/tabs.md)
40
40
  }
41
41
  ```
42
42
 
43
- The library ships no animation, so there is nothing to turn off for reduced motion; keep the media query above in your own stylesheet.
43
+ Every animation comes from your stylesheet, so reduced motion is yours to handle: when you write an animation (a view transition or plain CSS), add a `prefers-reduced-motion` rule like the one above.
44
44
 
45
45
  If you want only your own named animations, you can opt out of the page cross-fade with the CSS below. It is optional and applies to every view transition on the page, including your router's. The last rule keeps clicks working during a transition in Firefox, which otherwise suppresses hit testing.
46
46
 
@@ -85,13 +85,9 @@ Example: [Tabs](../components/tabs.md)
85
85
 
86
86
  ### <a id="css-exit"></a>A popup with a CSS exit and a view transition
87
87
 
88
- A popup in the top layer can close two ways. A close the library performs (a part's close, a controlled `open={false}`) happens in a commit, so the popup's `transition` prop can animate it with a view transition in every engine. A [dismissal](browser-owned-state.md#dismissal) happens in the browser before React hears about it, so only a CSS exit (`@starting-style`, `transition-behavior: allow-discrete`) can animate it. Keep both, and turn the CSS exit off while a view transition runs:
88
+ A popup in the top layer can close two ways. A close the library performs (a part's close, a controlled `open={false}`) happens in a commit, so the popup's `transition` prop can animate it with a view transition in every engine. A [dismissal](browser-owned-state.md#dismissal) happens in the browser before React hears about it, so only a CSS exit (`@starting-style`, `transition-behavior: allow-discrete`) can animate it; it is a fact, reported to `onOpenChange` in an urgent commit, which starts no view transition at all. Write both: the `transition` prop animates what the library does, CSS animates what the browser does, and the library's own show or hide never runs a CSS transition.
89
89
 
90
- ```css
91
- html:active-view-transition .my-popup { transition: none; }
92
- ```
93
-
94
- Without that rule, a popup the library hides keeps rendering through its CSS fade, and Chromium captures it in the close's new snapshot as well as the old one: a double image. The selector has no transition type on purpose, because a controlled close carries none. The cost is that an unrelated view transition of the page also cuts a CSS fade in progress. Put the rule on the whole popup class, so that nested popups that close with their parent are covered too.
90
+ While a view transition runs, the library turns off the popup's CSS transitions for the moment of its own show or hide. Otherwise Chromium would keep a popup the library hides rendering through its CSS fade and capture it in the close's new snapshot as well as the old one (a double image), and the CSS enter would run under the view transition's enter. To do this, the library writes an inline `transition: none !important` on the popup for the length of that one call and then puts your inline `transition` back. A dismissal is never cut, so its CSS fade runs even when another view transition of the page starts during it (a dismissal while the library's own view transition runs fades inside that transition's new image). Only CSS transitions are cut: an exit written as a `@keyframes` animation on the closed state still runs during a library close, and Chromium captures it twice. Write the exit as a `transition`.
95
91
 
96
92
  Example: [Dialog](../components/dialog.md)
97
93
 
@@ -107,8 +103,6 @@ A Dialog with a CSS fade for Escape and a click outside, and a view transition f
107
103
  @starting-style { .dialog:open { opacity: 0; } }
108
104
  ::view-transition-new(.pop) { animation: 180ms ease-out both pop-in; }
109
105
  ::view-transition-old(.pop) { animation: 140ms ease-in both pop-out; }
110
- /* Keep the CSS exit for dismissals, but not while a view transition runs. */
111
- html:active-view-transition .dialog { transition: none; }
112
106
  ```
113
107
 
114
108
  ## Rules the library follows for you
@@ -57,7 +57,7 @@ export function FavoriteButton({ postId, initial }: { postId: string; initial: b
57
57
 
58
58
  `pressedChangeAction` is an [action](concepts/action-props.md#action): it runs inside a transition. While the returned promise is pending, the button already shows the new pressed state ([optimistic](concepts/pending-and-optimistic.md#optimistic)) and carries `data-pending`. If it rejects, the pressed state rolls back and the error goes to the nearest Error Boundary. The [Action props](concepts/action-props.md) page explains the details.
59
59
 
60
- ## Styling: data attributes and CSS
60
+ ## <a id="styling"></a>Styling: data attributes and CSS
61
61
 
62
62
  Components render plain, accessible HTML and ship no styles. Library state appears as `data-*` attributes, emitted by presence (`data-pending=""` when true, absent when false). Enum-like states carry a value (`data-orientation="vertical"`).
63
63
 
@@ -83,33 +83,20 @@ When CSS is not enough, `className`, `style` and `children` also accept a functi
83
83
  </Toggle>
84
84
  ```
85
85
 
86
- ## Replacing the element: `render`
86
+ Each component page lists the fields of a part's state object in the **State** line under the part's props table.
87
87
 
88
- Every part that renders an element accepts `render`. The element form replaces the default element and merges the library's props into it; the function form hands you the props and the state.
89
-
90
- ```tsx
91
- // Element form: a design-system button. It must accept `ref` and spread its props.
92
- <Toggle render={<MyButton variant="ghost" />}>Bold</Toggle>
93
-
94
- // Function form: full control.
95
- <Toggle render={(props, state) => <button {...props}>{state.pressed ? "On" : "Off"}</button>} />
96
- ```
97
-
98
- On every component page, each part's props table is followed by two fixed lines: **State**, the object the function props and `render` receive, and **Owned**, the props the part sets itself, which a `render` element cannot override. Everything not listed passes through to the element.
99
-
100
- Merge rules for the element form:
101
-
102
- - `className` values are concatenated; `style` objects are merged (the element wins). Event handlers the part installs run after the element's own.
103
- - Attributes the part computes (its `role`, ARIA state, ids, `data-*` state) always win. ARIA id lists (`aria-describedby`, `aria-labelledby`, `aria-controls`) are merged instead.
104
- - Everything else, the element wins. `type="button"` is only added when the rendered element is a `<button>`.
88
+ To render a different element (your design system's button, a link), pass `render`; see [Replacing the element: `render`](concepts/render.md).
105
89
 
106
90
  ## What the components share
107
91
 
108
- | Pattern | Meaning |
92
+ These props mean the same on every component that has them:
93
+
94
+ | Prop | Meaning |
109
95
  | - | - |
110
96
  | `x` / `defaultX` / `xChangeAction` | Controlled value, initial uncontrolled value, and the action called on every change. |
111
- | `data-pending` | An action dispatched through this component is in flight. |
112
97
  | `transition` | On parts whose content is driven by library state: forwarded to the part's `<ViewTransition default>`. Without it the part renders no `<ViewTransition>`. |
113
- | `render` | Element polymorphism (no `asChild`, no `as`). |
98
+ | `render` | Replaces the rendered element (no `asChild`, no `as`). See [Replacing the element](concepts/render.md). |
114
99
  | `ref` | An ordinary prop on every part that renders an element. |
115
100
  | `experimental_*` | Opt-in use of a platform feature that is not in every engine yet. |
101
+
102
+ One attribute is shared too, but it is not a prop: every component with an action renders `data-pending` while an action dispatched through it is in flight (see [Styling](#styling) above).
@@ -131,13 +131,13 @@ FUNSTACK UI is part of the FUNSTACK family, which aims to be the most modern Rea
131
131
 
132
132
  ### Introduction
133
133
 
134
- - [Why FUNSTACK UI](why.md): Why choose FUNSTACK UI: headless React components that already do the async work React 19 asks for. Pending and optimistic state, Suspense, transitions and the platform, built in.
134
+ - [Why FUNSTACK UI](why.md): Why choose FUNSTACK UI: headless React components built for Async React, which already do the async work for you. Pending and optimistic state, Suspense, transitions and the platform, built in.
135
135
  - [Overview](index.md): FUNSTACK UI is a headless React component library and the first UI library that is Async React-native: Suspense-native, transition by default, action props, and \<ViewTransition> built in.
136
136
  - [Getting started](getting-started.md): Install @funstack/ui, import a component from its subpath, and style it with data attributes and CSS.
137
137
 
138
138
  ### Concepts
139
139
 
140
- - [Action props](concepts/action-props.md): FUNSTACK UI components take action props instead of event handlers. Actions run inside the component's transition, may be async, and report errors to Error Boundaries.
140
+ - [Action props](concepts/action-props.md): FUNSTACK UI components take action props instead of event handlers. Actions run inside the component's transition, may be async, and report errors to Error Boundaries. A change that had already happened is reported to an on\* handler instead.
141
141
  - [Pending & optimistic state](concepts/pending-and-optimistic.md): A state owner keeps a committed, an optimistic and a pending value. Triggers render the optimistic value, content regions the committed one, and data-pending marks an action in flight.
142
142
  - [Transitions & ViewTransition](concepts/transitions.md): Every state change in FUNSTACK UI is a transition. Parts whose content is driven by library state take a transition prop that renders a \<ViewTransition>, and changes are tagged with fsui-\* transition types.
143
143
  - [Suspense](concepts/suspense.md): FUNSTACK UI content regions keep old content on screen while new content suspends. You own the Suspense boundaries.
@@ -146,13 +146,14 @@ FUNSTACK UI is part of the FUNSTACK family, which aims to be the most modern Rea
146
146
 
147
147
  ### Guides
148
148
 
149
+ - [Replacing the element (render)](concepts/render.md): How the render prop replaces the element a FUNSTACK UI part renders: the element form, the function form, and how the part's props are merged into yours.
149
150
  - [Experimental features](concepts/experimental.md): Platform features that are not in every engine yet are opt-in through experimental\_\* props on the part that uses them.
150
151
  - [Content Security Policy](concepts/content-security-policy.md): What a strict style-src needs for FUNSTACK UI: the SHA-256 of the two shipped stylesheets (STYLE_SHA256) or a nonce through CSPProvider, and style-src-attr for server-rendered inline styles.
151
152
  - [Using with AI agents](concepts/ai-agents.md): Give a coding agent FUNSTACK UI knowledge: install the funstack-ui-knowledge skill from the npm package, or point the agent at the Markdown docs bundled in the package and published as llms.txt.
152
153
 
153
154
  ### Components
154
155
 
155
- - [Button](components/button.md): A button whose click is a transition: action in its own transition, data-pending, a second click ignored while pending, formAction with per-submitter pending.
156
+ - [Button](components/button.md): A button whose click is a transition: action in its own transition, data-pending, whilePending to run or ignore a click while pending, formAction with per-submitter pending.
156
157
  - [Toggle](components/toggle.md): A two-state button with an async pressedChangeAction, optimistic aria-pressed and data-pending.
157
158
  - [ToggleGroup](components/toggle-group.md): A set of aria-pressed toggle buttons sharing one value: several pressed, or at most one with exclusive. Optimistic, with pending state.
158
159
  - [Toolbar](components/toolbar.md): A WAI-ARIA toolbar with one Tab stop and arrow keys over any focusable children: toggles, menu buttons, links, inputs. No wrapper parts.
@@ -163,7 +164,7 @@ FUNSTACK UI is part of the FUNSTACK family, which aims to be the most modern Rea
163
164
  - [Dialog](components/dialog.md): A dialog built on \<dialog> and Invoker Commands: JS-free when you need no state; a transition-driven open with a pending trigger, Suspense-ready content, and library-owned closes with a ViewTransition exit in every engine when you do.
164
165
  - [Menu](components/menu.md): A menu button on the Popover API: items whose actions run in their own transition with pending state, optimistic checkbox and radio items, the APG keyboard model with typeahead, and submenus with hover intent.
165
166
  - [Context menu (Menu)](components/context-menu.md): Menu.ContextTrigger: a region whose right-click, Shift+F10 or touch long-press opens a Menu at the pointer, with the menu's pending items, optimistic checkbox and radio items and submenus unchanged.
166
- - [Toast](components/toast.md): Notifications fed by a toast() function and rendered by your own Viewport: an urgent queue that shows while the action it reports on is still pending, promise toasts, an Undo action prop, closeAction for the Undo window, ariaNotify announcements, and a region that stays interactive above modal dialogs.
167
+ - [Toast](components/toast.md): Notifications fed by a toast() function and rendered by your own Viewport: an urgent queue that shows while the action it reports on is still pending, promise toasts, an Undo action prop, an onClose handler for the Undo window, ariaNotify announcements, and a region that stays interactive above modal dialogs.
167
168
  - [Field and Form](components/field.md): Labelled, described, validated form fields on top of native constraint validation and :user-invalid, and a Form that runs its action in a transition, routes server errors to fields and resets only on success.
168
169
  - [Checkbox](components/checkbox.md): A native \<input type=checkbox> with an async checkedChangeAction, optimistic checked state, a controlled indeterminate state and native form participation.
169
170
  - [CheckboxGroup](components/checkbox-group.md): A group of native \<input type=checkbox> in a \<fieldset> with a set value, a mixed-state select-all Parent, group-level required, an async valueChangeAction and data-pending.