Repository navigation
refactor(reorder): the controller reads a collection's rows through a reader - #11199
Conversation
… reader ListReorderController took its rows from the list element's children in eleven places. It now reads them through a rows(container) reader, which defaults to the element children, so List's behavior is unchanged. This lets AST-103 FR4b's attach drive a plain container. component:List names the reader.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
|
/approve-spec ffc6389 |
There was a problem hiding this comment.
Requesting changes: the refactor keeps List's reorder behavior unchanged and adds no public API, but the required lint check fails on this head.
Blocking
- The
@astryxdesign/coresource changes inlistReorderEngine.tsxandlistReorderContext.tsship without a Changeset, so Check Changeset coverage fails in the requiredlintjob; add a.changeset/*.mdwith'@astryxdesign/core': patchand a[chore] Internal: …line, as earlier internal Core refactors do.
Non-blocking
readRowscovers the ordered-row reads, butrowOfand theparentElement === listchecks still assume rows are the container's direct children; route them through the reader, or state that constraint in its JSDoc, beforeattachpasses its own reader.
PR Analysis Report🔎 Preview ·
|
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| CheckboxList | 71.5 kB (0) · 7.8 kB CSS (0) | — | — · — · — |
| ContextMenu | 112.1 kB (0) · 17.5 kB CSS (0) | — | — · — · — |
| DropdownMenu | 101.0 kB (0) · 17.6 kB CSS (0) | — | — · — · — |
14 more components
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| List | 18.9 kB (0) · 790 B CSS (0) | — | ✓ · ✓ · — |
| ListItem | 73.2 kB (0) · 11.5 kB CSS (0) | — | ✓ · ✓ · ✓ |
| Markdown | 192.3 kB (0) · 20.8 kB CSS (0) | — | — · — · — |
| MoreMenu | 101.3 kB (0) · 17.6 kB CSS (0) | — | — · — · — |
| PowerSearch | 296.3 kB (0) · 24.5 kB CSS (0) | — | — · — · — |
| Table | 129.3 kB (0) · 18.4 kB CSS (0) | — | — · — · — |
| TableCell | 113.4 kB (0) · 18.0 kB CSS (0) | — | — · — · — |
| TableHeaderCell | 112.9 kB (0) · 17.7 kB CSS (0) | — | — · — · — |
| lab/Comments | 357.6 kB (0) · 2.5 kB CSS (0) | — | — · — · — |
| lab/CommentThread | 350.7 kB (0) · 2.4 kB CSS (0) | — | — · — · — |
| lab/ListInput | 91.2 kB (0) · 922 B CSS (0) | — | — · — · — |
| lab/TabBarMoreList | 95.6 kB (0) · 1.8 kB CSS (0) | — | — · — · — |
| lab/TransferList | 105.3 kB (0) · 1.2 kB CSS (0) | — | — · — · — |
| lab/TransferListSelector | 114.0 kB (0) · 1.4 kB CSS (0) | — | — · — · — |
Package size: @astryxdesign/core 7.33 MB packed (+560 B); no new dependencies.
Touched components checked; add ci:run-visual or ci:run-rtl to run the full suites.
Generated by PR Enrichment workflow | View full report
…ows reader; add the internal changeset The reader becomes a rows source: read lists the rows in order, and holds tells whether an element is a row. rowOf and the two parentElement checks in a commit use holds, whose default is the old direct-child test, so List is unchanged. A [chore] Internal changeset covers the core source change.
|
/approve-spec 1f44bfe |
There was a problem hiding this comment.
Approved pending CI: some required test jobs are still running on this head.
The rows source keeps List's reorder behaviour unchanged (the default CHILD_ROWS is the old rowsOf read and direct-child test) and adds no public API, and the component:List sentence carries an engineering owner's spec approval for this head.
Non-blocking
- The comments on
CHILD_ROWSand on therowsconstructor parameter inlistReorderEngine.tsxrestate the name, theReorderRowstype and the default, whichrowsOfandcreateSessionalready document; consider dropping them. - The description's test command names
packages/core/src/TransferListandpackages/core/src/ListInput, which do not exist (those suites live underpackages/lab/src); please correct the paths so the evidence says what ran.
| ); | ||
| } | ||
|
|
||
| /** A List's rows: its element children. */ |
There was a problem hiding this comment.
Non-blocking (INV29): this comment restates the name CHILD_ROWS; rowsOf and createSession already say a List's rows are its element children. Consider dropping it.
| constructor( | ||
| private readonly getList: () => HTMLElement | null, | ||
| readonly hintId: string, | ||
| /** Finds the collection's rows. A List's rows are its element children. */ |
There was a problem hiding this comment.
Non-blocking (INV29): this restates the ReorderRows type and the CHILD_ROWS default. Consider dropping it; the type's JSDoc and createSession's already carry the fact.
…10815) * refactor(List): write the reorder refs at commit, not in render Conformance tidy, no visible change. The reorder session's list getter and the mode hint's layer handle were copied into refs during render. Each is now written in a one-line layout effect, so a render React discards leaves nothing behind. No failure is reachable today. Every list getter returns the same element. The layer ref's only reader is the hint's layout effect. It reads the ref at the commit, right after the committed render wrote it. The cleanup uses the handle it captured. * fix(List): a reorder handle's name follows its row's place and label A reorder handle named itself from the DOM in a passive effect: after Item's label element when that element shows a name, else after the row's place ("Reorder item N"). The effect ran only when the handle rendered. A memoized row whose place changed, because a row above it went or the rows reordered, kept the old place in its handle's name. A label that gained or lost its text through its own state left the handle named the old way. The reorder session now reads both from the DOM, outside React. It registers the list's rows and its handles' label elements with Core's shared mutation observer, and releases them with the list. It keeps each handle's label naming, and the place only for a handle named after it. The handle reads them through useSyncExternalStore, as it reads reorder mode, and renders its name from them. Only a change renders the handle again, so its passive effect is gone. A row named after its place still warns in development, once, from the session. positionOf loses its last caller and goes. The session follows the list element the List renders, which changes when its numbering turns on or off. ListReorderNames.test.tsx covers a row above that goes, a reorder, and a label that gains and loses text: each fails on main and passes here. A reorder after the numbering turns on passes on both. * Merge main 1740654 into the reorder handle names Main brings in #11199, whose controller reads a collection's rows through a reader, and #11352's committed-ref hook. #11199 edits positionOf, which this branch removes; it stays removed. One hand edit: refreshNames reads this.rows.read(list) instead of rowsOf(list), as #11199's positionOf did, so a collection's own reader numbers its rows. * refactor(List): the reorder refs use the committed-ref hook The session's list getter and the mode hint's layer handle were each copied into a ref by a one-line layout effect. They now use Core's useCommittedRef, which writes them in a commit-phase insertion effect. The session's useMemo lists the stable getter ref in its dependencies. No behavior changes. Every getter List passes reads the same list ref when called, and the hint's effect reads the handle after either write. A handle's cleanup can reach the getter through release(), and gets the same list. The hint's cleanup hides the handle its setup showed, so no cleanup reads the layer ref. * fix(List): an unchanged handle name keeps its snapshot The names refresh compared each handle's name with the session's own entry, which a handle named some other way has none of before the first read. So it stored a new {position: null, labelNamesRow: null} and the handle rendered again with the same name on every mount (architecture:react-component-runtime INV9). It now compares with handleNameOf, whose shared unread name has the same fields. A test counts the handle's renders through the verb it reads each render: once per handle on mount, and once for a row that mounts later. * fix(List): a hydrated handle keeps its server snapshot The handle's server snapshot was its own unread name, and the session answered an unread handle with another object with the same fields. So after hydration React saw a new snapshot, and each handle rendered again with the same name (architecture:react-component-runtime INV9). The handle now exports one unread name, and the session answers with it. A test hydrates server markup and counts the handle's renders through the verb it reads each render: once per handle. * fix(List): a label that names its row keeps the unread snapshot The names refresh stored whether Item's label element names the row: null before the first read, and true after it, though the handle and the session read both alike. So a handle named by its row's text label rendered again with the same name after mounting and after hydrating (architecture:react-component-runtime INV9). The snapshot now records whether the label shows no name, which stays false until a read finds the label blank. Both render-count cases add a row named by its text label. * Merge main 06b7e61 into the reorder handle names Main brings in #10912, which changes Layer/useLayer.tsx, the layer the mode hint shows. The merge needs no hand edit. * Merge main 31aacff into the reorder handle names Main brings in #11336, which changes List/ListItem.tsx, the row that renders the reorder handle. The merge needs no hand edit.
Summary
This is step 1 of 3 toward
spec:AST-103FR4b (attach), which makes plain elements reorderable without React; RichText's block move builds on it. It is a refactor with no behavior change.ListReorderControllerfound a collection's rows by assuming they are the list element's direct children: eleven ordered reads,rowOf, and two checks in a commit. It now finds them through an internal rows source,ReorderRows {read(container), holds(element, container)}. Its default,CHILD_ROWS, is the oldrowsOfread and the old direct-child test, and List passes no other source, so every List keeps its behavior exactly. FR4b'sattach(step 2) will pass a source built from itsitems(), whose rows need not be direct children.listReorderContext.ts: theReorderRowstype;ListReorderEngine.createSessiontakes an optional source.listReorderEngine.tsx: the controller takes the source (defaultCHILD_ROWS). The ordered reads useread;rowOfand the commit's row checks useholds.component:List: itsspec:AST-103relation names the rows reader, as Specs ruled. Theattachclause waits for step 2.[chore] InternalChangeset, because Core source changes.No public API or rendering change.
Evidence
vitest run packages/core/src/List packages/core/src/reorderable packages/core/src/TransferList packages/core/src/ListInput: 195 passed, all of List's reorder suites unchanged.tscand eslint.Writing rubric results
Run over the
List.spec.mdsentence.(Posted by Cindy's agent on her behalf.)