This repository was archived by the owner on Nov 4, 2026. It is now read-only.
Repository navigation
Commit fde4caf
fix(fields): a lookup value hydrated from a bare id is labelled from the schema once it arrives (objectui#10487) (#10557)
Fixes #10487
Clause-②: no
A lookup that mounts already holding a bare id now labels its chip from
the referenced object's schema once that schema arrives. Before, when
the record fetch won the race against `getObjectSchema`, the chip kept
the no-schema label (the `name` guess) for good, while the dropdown
option for the same record read the declared `nameField`.
## Reproduction (base `db3896c4c`, the card's fixture)
Value `'c1'`; the object's `nameField` is `contract_no`; the row is `{
id: 'c1', name: 'Acme', contract_no: 'HT-001' }`. The pin's backend
holds `getObjectSchema` open until the chip is labelled, then releases
it.
| reading | base | head |
|---|---|---|
| mounted chip, before the schema | `Acme` | `Acme` |
| mounted chip, after the schema | `Acme` | `HT-001` |
| dropdown option for `c1` | `HT-001` | `HT-001` |
| chip after picking `c1` again | `HT-001` | `HT-001` |
The mechanism, confirmed at source: the hydration effect built each
option with `recordToOption` inside its async fetch, using the
`refObjectSchema` of the render it ran in (`null`), and cached the BUILT
option in `pickerResolvedRecords`. `findOption` then found the id in
that cache, so every later run of the effect returned early and nothing
rebuilt the label.
## The change: keep the RECORD, derive the label (one derivation)
`packages/fields/src/widgets/LookupField.tsx` only.
- The hydration effect fetches rows and builds no option. It merges them
into a new `hydratedRecords` state, keyed by `recordValue` (the value
expression `recordToOption` already used, now one helper both read).
- `hydratedOptions` is a memo that maps those rows through
`recordToOption` with the same inputs the dropdown's `fetchedOptions`
uses: the declared `displayField`, `idField`, the description field,
`refObjectSchema`, and the field-read gate of the current policy. It
re-derives when any of them changes, so the chip follows the schema when
it arrives.
- `findOption` and `findOptionLoose` consult static, fetched, picked
(`pickerResolvedRecords`), then hydrated options. A pick outranks the
hydrated row for the same value, as it did when the two shared one cache
and the later write won.
- The effect's dependency list drops `declaredDisplayField` and
`effectiveDescriptionField`, which the effect no longer reads. The
eslint disable stays. The reads it hides shrank from `dataSource`,
`findOption`, `perms`, `refObjectSchema` to `dataSource`, `findOption`
(the `--no-inline-config` message, base vs head).
No `key=` remount, and no re-fetch on the schema's arrival.
### Why this route and not the other two
- Relabel on arrival (an effect on `refObjectSchema` that rebuilds the
cached options) needs the rows anyway. An option cannot be rebuilt from
itself: `recordToOption` spreads the record over `label`, so the old
label would win the spread. That route is this change plus an effect,
and an extra render that still shows the stale label.
- Defer labelling until the schema is known needs a "schema settled"
state (`getObjectSchema` can be absent, can reject, or can be slow).
Every chip would wait on the metadata call, and it still needs a re-run
path. It is larger, and slower for the user.
- Keeping the record is the pattern the recents rail in the same file
already uses (`recentRows` state, `recentOptions` memo).
### Fetch count, measured
| ordering | base `findOne` calls | head |
|---|---|---|
| record first, schema later (the card) | 1 | 1 |
| schema arrives while the record fetch is in flight | 2 | 1 |
On base the second ordering got the right label only by accident. The
schema's arrival changed `effectiveDescriptionField` (it derives from
the schema's columns), which re-ran the effect, cancelled the fetch in
flight and issued a second one after the schema was known.
### `handleSelect` and the hydrated path
Both build the label through `recordToOption` with the same inputs, so
they agree once the schema is known: the pin's pick control and the
mounted chip both read `HT-001`. The pick path still caches a BUILT
option, so a pick made before the schema arrives keeps the no-schema
label. That is measured and reported under Acceptance notes; it is not
changed here.
### A second input follows too: the policy
The effect used to capture the field-read gate of the policy in force
when it ran (objectui#10373). The memo reads the current one. So a field
the policy denies after the chip is labelled (a policy that loads late)
leaves the chip's label, as it leaves the dropdown's. Pinned as row 4.
## Pin: `LookupField.hydratedLabel-10487.test.tsx`
| # | row | base | head |
|---|---|---|---|
| 1 | single hydrated id: the chip reads `HT-001` after the schema;
`findOne` once | red, `Acme` | green |
| 2 | batched `$in` path: the chips read `HT-001`, `HT-002`; one `$in`
query | red, `Acme`, `Initech` | green |
| 3 | the schema arrives while the fetch is in flight: chip `HT-001`,
`findOne` once | red, 2 calls | green |
| 4 | a field denied after the chip is labelled leaves the label (`c1`)
| red, `Acme` | green |
| 5 | control: the dropdown option reads `HT-001` | green | green |
| 6 | control: picking `c1` leaves the chip on `HT-001` | green | green
|
Rows 1 and 2 also assert the chip read `Acme` before the schema was
released, so the fixture's ordering is proven, not assumed.
## Ablations (one-shot, at `011676680`, restored by blob)
A1 and A3 ran through `../objectstack/scripts/ablation-replace.mjs`: the
anchor hit exactly once, the blob changed, and the restore was proven
(blob equal to HEAD's, `git diff HEAD` empty). A2 checked out the base
blob and restored the HEAD blob under a trap, proven the same way. The
pin imports `./LookupField` directly, so no `dist` is involved.
- A1, the derivation frozen: the `hydratedOptions` memo keyed on the
rows alone, so the label is built once, when the rows land. Predicted
and observed: rows 1, 2 and 4 red; rows 3, 5 and 6 green (3 failed, 3
passed).
- A3, the dependency list: the effect's deps regain
`declaredDisplayField` and `effectiveDescriptionField`. Predicted and
observed: row 3 red (`findOne` called 2 times), the rest green (1
failed, 5 passed).
- A2, the whole file at base `db3896c4c` (blob `7593aeb`; restored to
HEAD blob `3054087`): rows 1 to 4 red, the two controls green (4 failed,
2 passed).
## Verification (HEAD `011676680`)
- `pnpm exec vitest run packages/fields/` from the repo root: 198 files
passed and 1 skipped, of 199 (the tracked test files under
`packages/fields` also number 199); 3272 tests passed, 7 skipped.
- `pnpm --workspace-concurrency=2 --filter '@object-ui/fields^...' run
build`, then `pnpm --filter @object-ui/fields run type-check` (`tsc
--noEmit && tsc -p tsconfig.test.json`): exit 0. `tsc -p
tsconfig.test.json --listFiles` lists the pin.
- eslint on the two touched files, per rule, base vs head:
`LookupField.tsx` is equal in every rule (`react-hooks/exhaustive-deps`
3 and 3, or 5 and 5 with `--no-inline-config`; `no-explicit-any` 37 and
37). The pin has no messages.
- `pnpm check:control-bytes`, `pnpm check:new-line-citations` (0 new
citations), `node scripts/check-changeset-presence.mjs`, `pnpm
check:changeset-claims` (nothing flagged; its born-false leg found no
line address to judge), `node scripts/check-changeset-no-major.mjs`, and
`check:test-path-roots`, `check:phantom-deps`,
`check:pending-changeset-literals`, `check:unreferenced-sources`,
`check:shell-escape-residue`: all exit 0.
- NOT MEASURED: CI, and a browser run (the pin drives the real widget in
happy-dom).
Changeset: `@object-ui/fields` patch.
## Acceptance notes
- A behaviour change beyond the chip label: a browse-all
(`RecordPickerDialog`) pick replaced `pickerResolvedRecords` wholesale,
and that also dropped the hydrated entries. Hydrated rows now live in
their own state and survive it. The dialog's records still win for the
ids they carry.
- A finding, reported to the seat and not filed here: a pick made in the
dropdown BEFORE the schema arrives keeps the no-schema label. Measured
on head `011676680` with a throwaway probe: options before the schema
`Acme`, `Initech`; the chip after the pick `Acme`; the chip after the
schema `Acme`; the options after the schema `HT-001`, `HT-002`.
`handleSelect` caches the built option it is handed, and the row behind
it is not kept, so changing that is a design step, not a mechanical one.
The browse-all dialog path (`handlePickerSelectRecords`) builds options
the same way and was not measured.
Session: `https://claude.ai/code/session_01BA3nKVUwKQJf8DBxrSVtNC`
---
_Generated by [Claude
Code](https://claude.ai/code/session_01BA3nKVUwKQJf8DBxrSVtNC)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent aa6be30 commit fde4caf
3 files changed
Lines changed: 351 additions & 20 deletions
File tree
- .changeset
- packages/fields/src/widgets
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
0 commit comments