Skip to content

Commit 08c22d9

Browse files
committed
docs(combobox-web): record migration step 2 as an openspec change
Adds openspec/changes/combobox-viewmodel with the container, config and gate decisions, ticks task 3.2 of combobox-mobx-store, and records the step 2 status and the composition-root decision in the design docs.
1 parent 1b91ab4 commit 08c22d9

6 files changed

Lines changed: 135 additions & 14 deletions

File tree

‎docs/design/headless-combobox.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ Each step keeps the MPK, the XML, and the existing unit and E2E tests green.
438438
1. **Extract the store.** Precondition: section 11, rules 1 to 5 in place. Move `getSelector`, the providers, and the selectors into a MobX store under a Core. Replace the forced re-render in `useGetSelector` with the snapshot hook. No change to `components/`.
439439
Status 2026-10-29: done in the package change `combobox-mobx-store` (stacked on the safety-net branch). The selectors and providers are observable, `useObservableSnapshot` replaces the `setState({})` trigger and subscribes to the search term only. The props gate was deferred to step 2 because the `Selector` seam still takes props by method call.
440440
2. **Build the ViewModel.** Add the computed slices from section 3. Rewrite `SingleSelection` and `MultiSelection` to read from the ViewModel instead of the Selector. Whatever they cannot get from the ViewModel is a gap in the contract; fix the contract, not the View.
441+
Status 2026-10-30: done in the package change `combobox-viewmodel`, on the same branch as step 1. `ComboboxCore` derives the ViewModel as cached slices, the two views render from the snapshot only, and `onAfterSearchTermChange` is gone. The Core is assembled by a brandi container (`src/core/Combobox.container.ts`), the composition root pattern of datagrid-web and gallery-web: a frozen config for the static properties, a props gate for the Mendix values, the selector family bound per instance, and a setup host for the debounced filter-input action. `getSelector` and `useGetSelector` are gone with it. Deferred to step 3: `isOpen`, `inputValue`, `highlightedIndex` and `highlighted` per option (downshift still owns them), and the selector reads inside the downshift and lazy-loading hooks. Deferred to step 4: option `content` is still rendered by the captions providers, so the Core does decide the caption markup until then. Additions to the contract found on the way: `selectedContent`, `canSelectAll`, `loading.lazy`, `hints.selectionMethod`, and `tabIndex` on the envelope.
441442
3. **Extract Behavior and Popover.** Make downshift controlled by the Core. Move `useDownshift*` and `useFloatingMenu` into the two hooks with the getter shapes from sections 4 and 5. Verify every item in the "behaviour that must survive" list.
442443
4. **Introduce classes and data attributes.** Replace literal class names with the map and modifier classes with data attributes per the table in section 6. Update `Combobox.scss` and the E2E selectors.
443444
5. **Split into parts.** Break the Atlas View into one component per class key. Add the `classes` and `parts` props.

‎docs/design/headless-widgets.md‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ interface WidgetViewModel<Hints = {}, Texts extends TextMap = {}> {
143143
a11y: { label?: string; required: boolean; describedBy?: string; statusMessage?: string };
144144
hints: Hints; // advisory, Atlas-presentation properties from Studio Pro
145145
t: Translate<Texts>; // all user-facing and ARIA texts, see 7.1
146+
tabIndex?: number; // Studio Pro "Tab index" system property
146147
className?: string; // Studio Pro "Class" system property
147148
style?: CSSProperties; // Studio Pro "Style" system property
148149
}
@@ -258,7 +259,7 @@ Concrete examples for each level live in the per-widget documents.
258259
The npm package is the product. The pluggable widget is the host for it inside apps. The wrapper keeps three responsibilities and sheds everything else:
259260

260261
1. Declare the Studio Pro surface: XML, editor config, editor preview, icons, package metadata.
261-
2. Kickstart the Core: create on mount, feed container props on every render, dispose on unmount.
262+
2. Kickstart the Core: create on mount, feed container props on every render, dispose on unmount. The Core is assembled by a brandi container, the composition root pattern already used by datagrid-web, gallery-web and maps-web: static properties in a frozen config, Mendix values through a props gate, side effects as setup components.
262263
3. Resolve the View: read the `uiVariant` property, ask the registry, fall back to the Atlas View.
263264

264265
```tsx
@@ -346,15 +347,16 @@ We cannot guarantee accessibility of a custom View. We can hand the author the t
346347

347348
## 14. Decisions log
348349

349-
| Date | Decision |
350-
| ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
351-
| 2026-10-28 | Views live in the app project; the rebuild route is rejected. We stay in control of the Core and the MPK. |
352-
| 2026-10-28 | The project bundler compiles the View file and deduplicates the package. We ship no build step. |
353-
| 2026-10-28 | Registry is the client's; registration is Studio Pro's. Both hardcoded in the first iteration. |
354-
| 2026-10-28 | `uiVariant` is a free string. |
355-
| 2026-10-28 | Editor preview keeps its own simplified rendering. |
356-
| 2026-10-28 | MobX inside the Core, never exposed. Plain snapshot ViewModel with structural sharing is the public contract. |
357-
| 2026-10-28 | Atlas View consumes the ViewModel through the public hook, as proof the contract is complete. |
358-
| 2026-10-28 | Combobox first, range slider second, data grid deferred. |
359-
| 2026-10-28 | Options carry `caption: string` always and `content?: ReactNode` when configured. Placement is a hint; the Core never decides where content is shown. |
360-
| 2026-10-28 | All texts, ARIA included, come through a typed `t(key, ...params)` on the envelope, wrapping the upcoming platform system-text API. Mechanics out of scope. |
350+
| Date | Decision |
351+
| ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
352+
| 2026-10-28 | Views live in the app project; the rebuild route is rejected. We stay in control of the Core and the MPK. |
353+
| 2026-10-28 | The project bundler compiles the View file and deduplicates the package. We ship no build step. |
354+
| 2026-10-28 | Registry is the client's; registration is Studio Pro's. Both hardcoded in the first iteration. |
355+
| 2026-10-28 | `uiVariant` is a free string. |
356+
| 2026-10-28 | Editor preview keeps its own simplified rendering. |
357+
| 2026-10-28 | MobX inside the Core, never exposed. Plain snapshot ViewModel with structural sharing is the public contract. |
358+
| 2026-10-28 | Atlas View consumes the ViewModel through the public hook, as proof the contract is complete. |
359+
| 2026-10-28 | Combobox first, range slider second, data grid deferred. |
360+
| 2026-10-28 | Options carry `caption: string` always and `content?: ReactNode` when configured. Placement is a hint; the Core never decides where content is shown. |
361+
| 2026-10-28 | All texts, ARIA included, come through a typed `t(key, ...params)` on the envelope, wrapping the upcoming platform system-text API. Mechanics out of scope. |
362+
| 2026-10-30 | The Core is composed with a brandi container like the data grid and gallery: config, gate, selector family and setup host as bindings. The container never crosses the package boundary. |

‎packages/pluggableWidgets/combobox-web/openspec/changes/combobox-mobx-store/tasks.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
## 3. Refactoring
1717

1818
- [x] 3.1 Remove the shadowing field redeclarations in `StaticOptionsProvider`.
19-
- [ ] 3.2 Step 2: remove `onAfterSearchTermChange` from the `OptionsProvider` interface, its base implementation and its two tests, and introduce the props gate.
19+
- [x] 3.2 Step 2: remove `onAfterSearchTermChange` from the `OptionsProvider` interface, its base implementation and its tests, and introduce the props gate. Done in `combobox-viewmodel` on 2026-10-30.
2020

2121
## 4. Verification
2222

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## Test Cases
2+
3+
The characterisation tests from `combobox-selector-safety-net` and the component tests remain the net. The Core gets its own spec against the same fixtures.
4+
5+
### Regression Tests
6+
7+
- Views render the same DOM (unit) - `src/__tests__/SingleSelection.spec.tsx`, `MultiSelection.spec.tsx`, `StaticSelection.spec.tsx`
8+
- **Given**: the views reading the ViewModel
9+
- **When**: the 29 component cases run
10+
- **Then**: all pass, the 5 snapshots are unchanged
11+
- Selector seam unchanged (unit) - every spec under `src/helpers/**/__tests__/` and `src/hooks/__tests__/useGetSelector.spec.tsx`
12+
- **Given**: the selectors untouched except for the removed callback
13+
- **When**: the suite runs with `enforceActions: "always"`
14+
- **Then**: all pass, no `[MobX]` warning
15+
16+
### Core (`src/core/__tests__/ComboboxCore.spec.tsx`)
17+
18+
- Single mode on the enumeration fixture: envelope, flags, hints, options with captions and the selected flag, empty value, unavailable status, `t` with and without parameters, `describedBy` from validation, commands writing to the attribute, filtering through `setInputValue`, filter-input callback.
19+
- Multi mode on the association fixture: chips in stored order, `allSelected`, `canSelectAll`, joined captions for the text style, `select`, `deselect`, `toggleItem`, `selectAll`, `clear` writing to the association, the forced boxes style arriving as a hint.
20+
- Structural sharing: unchanged slices and commands keep their reference across an equal props update; only the options whose values changed are rebuilt; the ViewModel is cached between reads.
21+
- `useComboboxCore`: one Core per host, one re-render per search-term change, the latest props pushed into the selector once per render, a props update reflected in the same render with no React error logged.
22+
- Filter-input action (`FilterInputEvent.service.spec.ts`): debounced, last term wins, configured interval, empty term sent as `undefined`, skipped when it cannot execute or is executing, read from the gate when the timer fires, dropped on dispose.
23+
24+
### Container (`src/core/__tests__/createComboboxContainer.spec.ts`)
25+
26+
- Every family and mode binds its selector class and the Core wraps it; the selector gets the creation props; `setProps` updates the gate and the selector together and ignores a props object it has seen; unsupported sources throw as before.
27+
28+
### E2E
29+
30+
- `pnpm run e2e` on the PR through CI. Visual snapshots must be identical; step 2 changes no DOM.
31+
32+
## Decisions
33+
34+
- **brandi container as the composition root.** The Core is assembled the way datagrid-web, gallery-web and maps-web assemble theirs: typed tokens, `injected` constructors, a container class whose constructor binds the props-independent parts and whose `init` binds the config, the gate and the selector family. The container stays inside the Core; views get the snapshot and never resolve anything, so `brandi-react` is not needed.
35+
- **Static properties in a frozen config.** Simple-type props never change for a widget instance, so `comboboxConfig(props)` reads them once. The Core's hints are a plain field; `filterable`, `canSelectAll`, `loading.lazy`, `id` and `tabIndex` read the config; the forced-boxes rule for chips is applied there instead of inside the multi selectors. The selectors keep their own copies for now: the characterisation tests pin them, and step 3 replaces the seam.
36+
- **One `setProps` for the gate and the selector.** The selector seam still takes props by method call, so the container pushes a props object through the gate and `selector.updateProps` in one action. A props object already seen is skipped, which keeps the first render at one `updateProps` call.
37+
- **Filter-input action as a setup component.** The debounced action lives in a service registered with the setup host, so `useSetup` disposes it on unmount and a pending call cannot fire after the widget is gone. It reads the action from the gate when the timer fires.
38+
- **Props during render, muted reaction.** The repo pattern pushes gate props from a `useEffect`, which costs a second render per props change. The selector already takes props during render (step 1 kept that for the characterisation tests), so the Core does the same, and the snapshot subscription ignores changes made while the host renders. The host reads the fresh snapshot in that render; React's own consistency check in `useSyncExternalStore` sees no difference afterwards. Verified by the "no render-phase update" test.
39+
- **Keep-alive ViewModel.** A MobX computed is not cached while nothing observes it, and `useSyncExternalStore` reads the snapshot before it subscribes. `viewModel` is `computed({ keepAlive: true })` so the first render and the editor preview, which never subscribes, get a stable object.
40+
- **Content rendered by the captions providers.** `ComboboxOptionVM.content` is `caption.render(id, placement)`, so the `CaptionContent` markup and the custom-content wrapper are still produced by the providers, and the preview providers' design-mode overrides keep working. Step 4 moves that markup into the View and leaves only the custom content in the ViewModel. The design doc's "the Core never decides where content is shown" therefore holds from step 4, not from step 2.
41+
- **No open state in the ViewModel yet.** Owning `isOpen`, `inputValue` and `highlightedIndex` means a controlled downshift, which is the Behavior work of step 3. The step 2 type omits them rather than carrying placeholders.
42+
- **Hints use the Studio Pro enumeration values** (`bordered` | `text`, `boxes` | `text`, `skeleton` | `spinner`, `checkbox` | `rowclick`) except `customContent`, which is mapped to `none` | `everywhere` | `menuOnly` as the design doc specifies.
43+
- **`tabIndex` joins the envelope.** It is a system property like class and style and the views need it. The generic design doc is updated.
44+
- **`selectedContent` and `canSelectAll`** are additions to the design doc's ViewModel: the first carries what the input area shows when idle (caption, custom content or joined chip captions), the second whether the select-all control is configured.
45+
- **Cheap structural sharing without `mobx-utils`.** Per-option caching is a `Map` keyed by id with a shallow comparison; slices are compared the same way. No new dependency.
46+
47+
## Notes
48+
49+
- Simplification 1: the single clear button used to show on `!readOnly && clearable && currentId !== null` or on a second clause for static sources that was implied by the first; now only the first. The click handler used to guard on `selectedItem || selectorType === "static"`, where `selectedItem` is the same `currentId`; now it clears unconditionally, since the button only renders with a value.
50+
- Simplification 2: `aria-required` used to be the raw `DynamicValue` value, which is `undefined` while the expression loads and then omits the attribute; it is now a boolean, so a loading expression renders `aria-required="false"` for that moment. No test or snapshot covers that state.
51+
- Quirk preserved: in multi mode, while the selector reports `currentId === null`, the options get no `aria-selected` attribute instead of `"false"`. Marked `// Quirk:` in `MultiSelectionMenu.tsx`.
52+
- Quirk removed: `useGetSelector` attached the filter-input callback from the second render on, so typed text during the first render only cleared the search term. The downshift hooks now call `core.setInputValue` for every input change.
53+
- The editor preview creates a new container per props object, as it created a new selector before. The preview selectors are plain objects, which is fine: the keep-alive computed evaluates once per Core.
54+
- Run-to-run noise: one full-suite run reported one suite failed to execute while `pnpm run build` was running in parallel in the same package; five later runs were green. Do not run the build and the suite at the same time in one package.

0 commit comments

Comments
 (0)