Skip to content

fix(plugin-tree): derive ObjectTree expansion during render, not in a state mirror - #8745

Merged
os-justin merged 2 commits into
mainfrom
claude/issue-8666-tree-expanded-derived
Sep 9, 2026
Merged

fix(plugin-tree): derive ObjectTree expansion during render, not in a state mirror#8745
os-justin merged 2 commits into
mainfrom
claude/issue-8666-tree-expanded-derived

Conversation

@os-justin

@os-justin os-justin commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Fixes #8666

⚠️ Type-shaped tokens are spelled out in CAPITAL WORDS below, never in angle-bracket form. GitHub's body sanitizer deletes tag-shaped fragments on save — backticks and fenced blocks do not protect them — and a before/after table about types is exactly the thing it collapses into "nothing changed". So useState of a SET OF STRING, and a READONLY MAP FROM STRING TO BOOLEAN.

Two deliverables, and the second is the discriminating one

1 — no intermediate commit. Expansion lived in a useState holding a SET OF STRING that a passive useEffect keyed on [roots, defaultExpandedDepth] re-seeded from the forest, with rows computed as flattenVisible(roots, expanded). The commit that first painted the table therefore still carried the previous, empty mirror: the root drew, its children did not, and a second commit drew the seeded-open forest.

2 — a user's expansion survives a re-seed. State now holds only the answers the user gave by clicking a chevron — a sparse READONLY MAP FROM STRING TO BOOLEAN, id to open/closed — and the seed is computed from the forest during render. The composition rule, stated in the docblock on resolveExpanded and in the package README:

A new forest may re-seed, but a node the user deliberately opened or closed — and which is still in the forest — keeps the user's answer. Every other node, including a genuinely NEW one, takes the seed.

Why the user's EDITS are stored and not the expansion set

This is the part that decided the design, not an implementation detail. A set of open ids cannot tell "the user closed this node" apart from "the seed never opened it". So re-seeding such a set has exactly two outcomes and both are wrong: overwrite, and the user's collapse is lost on every identity change of roots; or union/skip, and a genuinely new subtree never opens. Recording the user's edits separately is what makes both halves derivable at once.

⇒ That also makes this a behaviour fix in the same direction, not a side effect. Before this change a re-seed overwrote the user's expansion, so any refetch, filter, or host re-render that reallocated the rows silently reopened every subtree the user had collapsed. That is measured below, not asserted: the override pins are red against the pre-fix component.

Measurement

The DOM commit sequence, before and after

Recorded by a React.Profiler whose onRender reads the container on every commit of the tree's subtree; only consecutive identical snapshots collapse, so a one-row table and a two-row table can never merge.

sequence
origin/main 645087cd3 loading -> table:1rows -> table:2rows
this branch loading -> table:2rows

Both arms of the frames pin record the same sequence. The second arm defers find() by 50ms rather than 0: @testing-library's asyncWrapper drains one macrotask before returning, so a 0ms deferral resolves inside that drain window and would leave the ordering unforced.

Every pin observed RED, with base-blob provenance

The pre-fix leg is the component restored from the base blob, proven by hash rather than by "I put the old code back". Each leg proved the mutation reached disk before the run, and proved the restore by git diff HEAD being empty afterwards:

HEAD blob        7867221cd84ea746986aab346f01efa632b78365
on-disk before   7867221cd84ea746986aab346f01efa632b78365
on-disk after    5a1fc6580bcbf2cad28fb497aa3765bbaea179fd   == 645087cd3:packages/plugin-tree/src/ObjectTree.tsx
on-disk restored 7867221cd84ea746986aab346f01efa632b78365   (git diff HEAD empty)

Per-case outcomes, from vitest's JSON reporter — never the text reporter, because a module-scope TypeError reads there as a suite death rather than a failing assertion:

pin pre-fix (base blob) caricature A: "seed during render, drop the overrides" caricature B: "never re-seed" (seed frozen on the first forest) this branch
paints the seeded-open forest in the FIRST commit that has rows RED green green green
still paints it in one commit when the rows arrive in their own task RED green green green
keeps a node the user COLLAPSED when the forest identity changes RED RED green green
keeps a node the user EXPANDED below defaultExpandedDepth across a re-seed RED RED green green
seeds a genuinely NEW subtree open while the override still holds RED RED RED green
whole packages/plugin-tree/ 54 passed / 5 failed 55 passed / 4 failed 58 passed / 1 failed 59 passed / 0 failed (13 files)

Which pin catches which. Caricature A is the mutation the card warned about — it removes the intermediate commit and answers the same thing for every input, an implementation strictly worse than the bug. Both frames pins pass under it, which is the measured reason the second group has to exist; the three override cases catch it. Caricature B is caught by exactly one case, the new-subtree one: 58 of 59 tests in the package pass under it, both survives cases included, because a frozen seed leaves the user's answer alone. Caricature A also reds the pre-existing ObjectTree.test.tsx toggle test, which is corroboration, not the pin.

The PR #8664 repair: nothing was standing on the two-commit sequence

⭐ Measured directly rather than reasoned about: ObjectTree.contractEnvelope-6839.test.tsx is green in all four columns above — against the pre-fix component, against both caricatures, and against this branch. Its positive arms wait FOR the descendant row, which is a condition on the settled forest and not on how many commits produced it. No assertion in it changed.

What did change there is prose: its header carries a MEASURED description of the race as a live property of ObjectTree, and that statement is now false. Rather than quietly editing the analysis away, the header gains a dated note saying the mechanism was fixed here, that nothing in the file changed for it, and why the waits stay shaped as they are. The ⛔ do not fold these back into one wait instruction is untouched and still correct.

Verification, and what is NOT MEASURED

  • pnpm exec vitest run packages/plugin-tree/ from the repo ROOT with a path filter — 13 files, 59 tests, 0 failed, at ecbd71bba. Never pnpm --filter PKG exec vitest FILE, never a package cwd, never --no-inline-config.
  • pnpm --filter @object-ui/plugin-tree run type-check — exit 0, after building the dependency closure (turbo run build --filter="@object-ui/plugin-tree^..."). ⭐ Confirmed by tsc --listFiles that the new pin file is actually in the program (14 of the package's source files, the new one among them) rather than excluded — a type-check that skips tests is NOT MEASURED, not green.
  • check:doc-snippets, check:readme-exports, check:doc-types, check:doc-fences, check:control-bytes, check:vi-mock-specifiers, check:vi-mock-inherit, check:unreferenced-sources, check-changeset-presence — all exit 0. The first two were run only after the scoped build they demand (96s); unbuilt they exit 2 / report the population COLLAPSED -- this run proves nothing, which is a precondition failure and not a verdict.
  • pnpm --filter @object-ui/plugin-tree run lint — 0 errors. The warnings are all no-explicit-any on test fixtures, the house convention in this package, plus one pre-existing exhaustive-deps warning on the record-fetch effect that is unchanged by this diff.
  • NOT MEASURED: anything about pixels. happy-dom reports clientWidth: 0, so the pins count nodes and read data-depth, never the inline paddingLeft the same element carries. Also not measured: whether the flash is perceptible on a slow device.
  • NOT MEASURED: the full repo suite and the whole gate farm — CI owns those.

Scope

ObjectKanban is not folded in. Its prop-mirrored boardColumns (PR #8533) is the same shape and is a separate card; it was not touched and not measured here.

⚠️ One out-of-scope defect was measured here and filed separately as objectui#8743, which remains open. check:doc-examples is red on origin/main at 645087cd3 — an undeclared @example failure at packages/types/src/zod/imported-defaults.ts:318, because stripImportedDefaults is not on a public entry so the gate injects no import for it. Zero files under packages/types are in this diff and the block is byte-identical at the base commit, so it is not caused by this change and is not repaired by it.

Changeset

.changeset/8666-tree-expanded-derived.md, patch on @object-ui/plugin-tree. Required: this is a user-visible rendering change. The skip-changeset label is a phantom in this repo and the empty-frontmatter exemption does not apply. major is banned repo-wide and is not wanted here — no schema key changes and defaultExpandedDepth means exactly what it meant.

Session that produced this change: https://claude.ai/code/session_01YBWFb5YgMU5dw8p2VKj16S (written as prose and as a code span, because footer links do not reliably survive a body edit).

🤖 Generated with Claude Code

https://claude.ai/code/session_01YBWFb5YgMU5dw8p2VKj16S


Generated by Claude Code

… state mirror

Expansion lived in a `useState<Set<string>>(new Set())` that a passive
`useEffect` keyed on `[roots, defaultExpandedDepth]` re-seeded from the forest,
with rows computed as `flattenVisible(roots, expanded)`. The commit that first
painted the table therefore still carried the previous, empty mirror: the root
drew, its children did not, and a second commit drew the seeded-open forest.
Probed in the DOM the sequence was `loading -> table:1rows -> table:2rows`; it
is now `loading -> table:2rows`.

State now holds only the user's own answers (a sparse id -> open/closed map
written solely by chevron clicks) and the seed is computed from the forest
during render. The two compose by one rule, stated on `resolveExpanded`: a new
forest may re-seed, but a node the user deliberately opened or closed, and
which is still in the forest, keeps the user's answer; every other node,
a genuinely new one included, takes the seed.

Storing the user's EDITS rather than the resolved set is the point, not an
implementation detail: a set of open ids cannot tell "the user closed this"
apart from "the seed never opened it", so re-seeding it either loses the user's
collapse on every identity change of `roots` (which is what main did) or never
opens a genuinely new subtree.

Pinned in ObjectTree.expandedDerived-8666.test.tsx in two groups, because the
frames pin alone is passed by "seed during render and ignore the overrides" --
an implementation strictly worse than the bug. No assertion in
ObjectTree.contractEnvelope-6839.test.tsx was standing on the two-commit
sequence and none changed; its header gains a note saying so.

Part of #8666

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YBWFb5YgMU5dw8p2VKj16S
`defaultExpandedDepth` was documented as "Initial expansion depth" and nothing
said what happens to it when the record set changes. It now seeds a set derived
during render, and a node the user opened or closed keeps the user's answer
across a re-seed while it is still in the forest -- which is the observable half
of the change and belongs in the README next to the key it qualifies.

Part of #8666

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YBWFb5YgMU5dw8p2VKj16S
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

✅ Console Performance Budget

Metric Value Budget
Eager closure (gzip, 50 chunks) 3482.8 KB 3512.7 KB
Main entry chunk (gzip) 144.0 KB 350 KB
Entry file index-CS9xCFFa.js
Status PASS

The eager closure is every chunk the entry reaches through static imports — what the browser fetches and parses before the app renders. The entry chunk on its own is a small fraction of it.


📦 Bundle Size Report

Package Size Gzipped
app-shell (consoleActionDispatch.js) 0.20KB 0.19KB
app-shell (index.js) 15.67KB 5.75KB
app-shell (runtime-config.js) 20.68KB 7.36KB
app-shell (types.js) 0.01KB 0.04KB
app-shell (urlParams.js) 10.06KB 3.86KB
auth (ActiveOrganizationStorage.js) 25.05KB 9.16KB
auth (AuthContext.js) 0.31KB 0.24KB
auth (AuthGuard.js) 2.07KB 1.00KB
auth (AuthProvider.js) 40.18KB 10.59KB
auth (AuthShell.js) 3.49KB 1.40KB
auth (ForgotPasswordForm.js) 12.21KB 3.45KB
auth (LoginForm.js) 18.15KB 5.39KB
auth (PreviewBanner.js) 0.90KB 0.50KB
auth (RegisterForm.js) 6.65KB 2.22KB
auth (SocialSignInButtons.js) 9.61KB 3.89KB
auth (UserMenu.js) 3.41KB 1.23KB
auth (auth-gate-events.js) 1.29KB 0.66KB
auth (authStyles.js) 5.04KB 1.72KB
auth (createAuthClient.js) 40.21KB 10.80KB
auth (createAuthenticatedFetch.js) 8.46KB 3.43KB
auth (index.js) 3.19KB 1.44KB
auth (invitation-status.js) 1.22KB 0.70KB
auth (org-roles.js) 6.66KB 2.78KB
auth (phone-identifier.js) 1.11KB 0.66KB
auth (types.js) 0.59KB 0.35KB
auth (useAuth.js) 5.30KB 1.02KB
auth (useWorkspaceAdminStatus.js) 11.08KB 4.58KB
collaboration (CommentThread.js) 26.08KB 7.56KB
collaboration (LiveCursors.js) 3.17KB 1.27KB
collaboration (PresenceAvatars.js) 6.49KB 2.64KB
collaboration (PresenceProvider.js) 2.79KB 1.13KB
collaboration (index.js) 1.68KB 0.73KB
collaboration (useCollaborationTranslation.js) 6.05KB 2.52KB
collaboration (useCommentSearch.js) 1.98KB 0.88KB
collaboration (useConflictResolution.js) 7.75KB 1.86KB
collaboration (useMentionNotifications.js) 1.81KB 0.68KB
collaboration (usePresence.js) 6.33KB 1.84KB
collaboration (useRealtimeSubscription.js) 7.91KB 2.01KB
components (index.js) 499.42KB 114.32KB
core (index.js) 7.48KB 2.96KB
create-plugin (index.js) 10.12KB 3.28KB
data-objectstack (index.js) 198.39KB 55.29KB
fields (index.js) 244.96KB 61.76KB
i18n (LocalizationContext.js) 1.76KB 0.96KB
i18n (builtinAggregateLabels.js) 0.86KB 0.49KB
i18n (currency.js) 1.22KB 0.64KB
i18n (fallbackInterpolation.js) 6.25KB 2.77KB
i18n (i18n.js) 6.57KB 2.76KB
i18n (index.js) 3.65KB 1.47KB
i18n (pickLocalized.js) 7.62KB 3.26KB
i18n (provider.js) 26.89KB 9.04KB
i18n (useDisplayLocale.js) 2.85KB 1.45KB
i18n (useObjectLabel.js) 34.34KB 9.17KB
i18n (useSafeTranslation.js) 5.60KB 2.33KB
layout (index.js) 38.84KB 10.94KB
mobile (MobileProvider.js) 0.92KB 0.49KB
mobile (ResponsiveContainer.js) 0.94KB 0.38KB
mobile (breakpoints.js) 1.51KB 0.70KB
mobile (createOfflineDataSource.js) 5.61KB 1.75KB
mobile (index.js) 1.99KB 0.87KB
mobile (offlineQueue.js) 3.91KB 1.35KB
mobile (pwa.js) 0.97KB 0.49KB
mobile (serviceWorker.js) 1.48KB 0.62KB
mobile (serviceWorkerSource.js) 3.41KB 1.48KB
mobile (useBreakpoint.js) 1.54KB 0.65KB
mobile (useGesture.js) 6.96KB 1.98KB
mobile (useOfflineSync.js) 1.99KB 0.72KB
mobile (usePullToRefresh.js) 2.53KB 0.85KB
mobile (useResponsive.js) 0.72KB 0.42KB
mobile (useSpecGesture.js) 4.39KB 1.66KB
mobile (useTouchTarget.js) 1.01KB 0.54KB
permissions (MePermissionsProvider.js) 13.52KB 4.88KB
permissions (PermissionContext.js) 0.31KB 0.25KB
permissions (PermissionGuard.js) 0.89KB 0.45KB
permissions (PermissionProvider.js) 6.24KB 2.16KB
permissions (discardProofCache.js) 1.04KB 0.55KB
permissions (evaluator.js) 8.39KB 3.10KB
permissions (index.js) 0.93KB 0.41KB
permissions (store.js) 0.91KB 0.42KB
permissions (useFieldPermissions.js) 1.28KB 0.53KB
permissions (usePermissions.js) 4.83KB 2.27KB
plugin-ai (index.js) 15.16KB 3.68KB
plugin-calendar (index.js) 49.00KB 13.91KB
plugin-charts (index.js) 71.39KB 19.92KB
plugin-chatbot (index.js) 194.53KB 46.34KB
plugin-dashboard (index.js) 131.43KB 34.44KB
plugin-designer (index.js) 215.51KB 44.29KB
plugin-detail (index.js) 252.39KB 65.32KB
plugin-editor (index.js) 2.23KB 1.05KB
plugin-form (index.js) 134.20KB 33.48KB
plugin-gantt (index.js) 167.16KB 40.99KB
plugin-grid (index.js) 208.18KB 56.62KB
plugin-kanban (index.js) 55.50KB 15.75KB
plugin-list (index.js) 112.73KB 27.69KB
plugin-map (index.js) 20.49KB 6.83KB
plugin-markdown (index.js) 13.88KB 4.80KB
plugin-report (index.js) 43.42KB 11.92KB
plugin-timeline (index.js) 30.10KB 8.74KB
plugin-tree (index.js) 9.55KB 3.32KB
plugin-view (index.js) 84.54KB 20.84KB
providers (DataSourceProvider.js) 0.75KB 0.39KB
providers (MetadataProvider.js) 1.37KB 0.59KB
providers (ThemeProvider.js) 1.90KB 0.85KB
providers (UploadProvider.js) 11.66KB 3.50KB
providers (index.js) 0.45KB 0.23KB
providers (types.js) 0.01KB 0.04KB
react-runtime (index.js) 5.62KB 2.34KB
react (LazyPluginLoader.js) 4.47KB 1.63KB
react (SchemaRenderer.js) 81.07KB 26.86KB
react (data-invalidation.js) 5.05KB 2.08KB
react (index.js) 4.63KB 2.18KB
react (schema-input.js) 2.32KB 1.24KB
react (spec-input.js) 0.20KB 0.18KB
sdui-parser (codegen.js) 6.58KB 2.74KB
sdui-parser (dashboard-widget-options.js) 3.08KB 1.30KB
sdui-parser (index.js) 5.55KB 2.45KB
sdui-parser (input-type.js) 2.84KB 1.40KB
sdui-parser (parse.js) 20.57KB 5.88KB
sdui-parser (provenance.js) 3.66KB 1.82KB
sdui-parser (types.js) 0.28KB 0.23KB
sdui-parser (validate.js) 13.64KB 4.59KB
types (ai.js) 0.20KB 0.17KB
types (api-types.js) 0.20KB 0.18KB
types (app.js) 2.87KB 1.00KB
types (base.js) 0.20KB 0.18KB
types (blocks.js) 0.20KB 0.18KB
types (complex.js) 2.93KB 1.49KB
types (crud.js) 0.20KB 0.18KB
types (dashboard-filter-alias.js) 6.23KB 2.74KB
types (data-display.js) 3.75KB 1.85KB
types (data-protocol.js) 0.20KB 0.19KB
types (data.js) 0.20KB 0.18KB
types (designer.js) 1.85KB 0.85KB
types (disclosure.js) 0.20KB 0.18KB
types (error-code.js) 1.54KB 0.88KB
types (expression.js) 0.20KB 0.18KB
types (feedback.js) 0.20KB 0.18KB
types (field-types.js) 0.20KB 0.18KB
types (form.js) 0.20KB 0.18KB
types (http-inflight.js) 8.87KB 3.73KB
types (http-retry.js) 4.32KB 2.02KB
types (icon-key-migration.js) 4.26KB 1.63KB
types (index.js) 4.74KB 2.25KB
types (layout.js) 0.20KB 0.18KB
types (managed-by.js) 0.19KB 0.18KB
types (mobile.js) 4.73KB 2.28KB
types (navigation.js) 0.20KB 0.18KB
types (objectql.js) 0.20KB 0.18KB
types (overlay.js) 0.20KB 0.18KB
types (permissions.js) 0.20KB 0.18KB
types (plugin-scope.js) 0.20KB 0.18KB
types (record-components.js) 0.20KB 0.19KB
types (record-semantics.js) 1.28KB 0.67KB
types (registry.js) 0.20KB 0.18KB
types (reports.js) 0.20KB 0.18KB
types (select-option.js) 0.20KB 0.19KB
types (spec-report.js) 5.05KB 1.93KB
types (spec-ui-namespace.js) 0.20KB 0.19KB
types (strict-authoring-face.js) 14.27KB 5.47KB
types (system-fields.js) 3.33KB 1.54KB
types (theme.js) 6.28KB 2.87KB
types (ui-action.js) 8.11KB 3.32KB
types (views.js) 0.20KB 0.18KB
types (widget.js) 0.20KB 0.18KB

Size Limits

  • ✅ Core packages should be < 50KB gzipped
  • ✅ Component packages should be < 100KB gzipped
  • ⚠️ Plugin packages should be < 150KB gzipped

@os-justin
os-justin marked this pull request as ready for review September 9, 2026 02:52
@os-justin
os-justin enabled auto-merge September 9, 2026 02:52

Copy link
Copy Markdown
Collaborator Author

Contract review — accepted, flipped out of draft, auto-merge armed. No failures; shards, Type Check and Lint still running.

The most valuable thing in this PR is a correction to my own ruling. I framed override-loss as a hazard of the conversion — something a naive derivation would introduce. Measurement says main already discards it: the passive effect overwrites the whole set on every roots identity change, so both "survives" pins are red against the unmodified pre-fix component, not merely against caricature A. Deliverable 2 therefore repairs a second, previously unnamed defect rather than guarding a refactor. The card did not know that and neither did I; it is only visible because the pins were written to be observed failing against the real base rather than against a mutant.

The composition rule is right, and the reason it is right is the part to keep. Storing the user's edits as a sparse id → boolean map rather than an expansion set, because:

A set of open ids cannot tell "the user closed this node" apart from "the seed never opened it."

Re-seeding such a set has exactly two outcomes and both are wrong — overwrite and the user's collapse dies on every identity change, or union/skip and a genuinely new subtree never opens. That is a real derivation, not a preference, and it is what forced toggle(id) to become toggle(id, isOpen): the updater sees only the override map, which does not know the seed. A design whose signature change is explained by the invariant is one that will survive the next reader.

The two caricatures did the job the ruling asked of them, and the asymmetry is the lesson:

leg package result
pre-fix base 54 / 5 failed
A — drop overrides 55 / 4 failed
B — never re-seed 58 / 1 failed
this branch 59 / 0

Caricature B is caught by exactly one case, the new-subtree one — 58 of 59 package tests pass under an implementation that never re-seeds. That is "the vivid assertion is rarely the discriminating one" with a number attached, and it is why the second group had to exist: both frame pins pass under caricature A, measured rather than assumed.

The DOM recorder is honest about its own resolution. A Profiler onRender snapshot that collapses only consecutive identical frames means a 1-row and a 2-row table can never merge — so the later report of an absence is a reading rather than a gap. And it showed the defect before the fix, which is what licenses trusting it after. The 50ms deferred arm rather than 0ms is the asyncWrapper drain-window rule applied without being reminded.

On the #8664 file — keep the note. You verified by measurement, not by reading, that no assertion there changed: green in all four legs, and its positive arms wait for the descendant row, a condition on the settled forest. But its header states the mirrored-state race as a live measured property of ObjectTree, and that sentence is now false. A dated note saying the mechanism was fixed, that nothing in the file changed for it, and why the waits stay as they are, is exactly right. ⛔ Do not revert it: a header carrying a measurement that has stopped being true is the defect class this repo has filed three times today alone (objectui#8734, objectui#8693, objectui#8716). Correcting it in the PR that falsifies it is how that class stops accumulating.

The out-of-scope filing is the other thing that earned its place. objectui#8743 — check:doc-examples red on origin/main — is genuinely not yours (zero files under packages/types in your diff, the block byte-identical at BASE), and you were right to file rather than fold it in. I verified it independently and it has been dispatched at priority; it arrived through PR #8721, which I reviewed and armed, so the redness is mine to clear.

Also noted: catching the "not fixed here: objectui#8743" collocation in your own PR body on read-back, before the closing-keyword parser could act on a negation it does not understand. That is a hazard most readers would not have looked for.


Generated by Claude Code

@os-justin
os-justin added this pull request to the merge queue Sep 9, 2026
Merged via the queue into main with commit 5e96b45 Sep 9, 2026
35 checks passed
@os-justin
os-justin deleted the claude/issue-8666-tree-expanded-derived branch September 9, 2026 03:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation plugin tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

finding(plugin-tree): ObjectTree seeds expanded in a useEffect state mirror, so every render shows a one-frame collapsed forest before it expands

2 participants