Skip to content

Reintroduce a parent link on model nodes - #227

Merged
QuentinRoy merged 8 commits into
mainfrom
claude/issue-167-option-b-1bc079
Sep 3, 2026
Merged

Reintroduce a parent link on model nodes#227
QuentinRoy merged 8 commits into
mainfrom
claude/issue-167-option-b-1bc079

Conversation

@QuentinRoy

Copy link
Copy Markdown
Owner

Fixes #167

Model nodes expose their sub-items but have no way back up: given an item, there's no way to find the menu it belongs to. This link existed before the TypeScript migration and was dropped there, since restoring it created a circular type: a node's type would reference its parent's type, which references it back.

This restores parent by changing how a node's type is described. Instead of a node's own id, label and items, each node is now described by the whole menu it belongs to, plus a path locating it within that menu. parent is then the same lookup with the last step of the path dropped, so a node and its parent are derived independently from the menu description rather than one being defined in terms of the other. The root's parent is always null.

The runtime construction order changes to match: a node is built before its items, which are then built with it as their parent.

A menu built at runtime rather than described as a literal still works, but its items lose the precise typing, the same trade-off id and label already make in that case.

You can check the new behavior directly:

const menu = createModel({
  items: [{ id: 'a', label: 'A', items: [{ id: 'b', label: 'B' }] }],
});
menu.items[0].items[0].parent === menu.items[0]; // true
menu.parent; // null

Tests cover parent at runtime, at every level, with the root having none, and what the type system knows about it for both a literal menu description and one built dynamically.

QuentinRoy and others added 3 commits September 3, 2026 21:01
Adds `parent` throughout the model: `null` at the root, and a precise,
literal-preserving link up the tree for every item. Follows option B from
the issue's investigation — nodes are derived from a root menu description
plus an index path locating them within it, rather than from their own
literal shape, so an item's type and its parent's type are computed
independently instead of one referencing the other.

Runtime construction is flipped from child-first to parent-first: a node is
built before its items, which are then built with it as their parent via a
callback.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Cut redundant clauses and drop the ModelRoot.parent comment: parent:
null needs no explanation next to isRoot: true, which has none.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 16934e4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
marking-menu Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

QuentinRoy and others added 4 commits September 3, 2026 21:14
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
marking-menu shipped the parent property in 0.10.1. It was dropped
during the TypeScript migration, tracked by the (still unreleased)
remove-item-parent changeset, before this change brought it back.
Since that removal never reaches a release, drop its changeset and
describe the actual delta from 0.10.1 instead: parent stays, now
precisely typed, with null instead of undefined at the root.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
A consumer reading the changelog never saw parent removed; only the
diff between released versions is visible to them. Describe the
property directly instead of narrating its unreleased history.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@QuentinRoy
QuentinRoy enabled auto-merge (squash) September 3, 2026 19:27
@QuentinRoy
QuentinRoy merged commit 1efeece into main Sep 3, 2026
5 checks passed
@QuentinRoy
QuentinRoy deleted the claude/issue-167-option-b-1bc079 branch September 3, 2026 19:36
@github-actions github-actions Bot mentioned this pull request Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reintroduce a parent link on model nodes

1 participant