Repository navigation
Retain reading layouts across widget connections - #938
Conversation
leaf-agent
left a comment
There was a problem hiding this comment.
The three added reconnect assertions pass unchanged on the base runtime, so the suite still does not hold what this PR changes. I checked out the eight source files at their pre-image, kept the PR's test files, and ran the three cases: test_a_root_workspace_bounds_independent_regions_and_flows_when_it_cannot_fit, test_notification_playground_uses_shared_bounded_regions_and_flows_when_narrow, and test_visual_review_controls_keep_keyboard_navigation_local all passed against the old registerReadingElement path. That path rediscovered the same nodes by selector, so node identity across a remove-and-reinsert survived it too, and data-lf-reading-posture came back the same way. (The rewritten test_arrangement_admission_precedes_dom_construction_and_owns_one_layout is genuinely new-API-only and was not part of that run.)
What separates the two implementations is a reconnect where the retained declaration and a DOM search disagree — for instance a pane whose first arrangeReadingElement was refused by an occupied region id. On the old path the reconnect branch reads :scope > .lf-pane-content, finds nothing, and registerReadingArrangement throws leaf: a reading arrangement needs owner and content elements; here the layout is simply built on the next connection. The startup test already occupies a region id to force that refusal, so the case is constructible where it stands.
Second, smaller: the build guard is now split. lf-partition, lf-workspace, lf-monitor, and defineReadingPaneElement decide on !this.#layout and call once(this) only for its attribute stamp, while lf-ask, lf-playground, and lf-visual-review still decide on what once() returns. widget-upgrade.js documents once as "One-shot guard for connectedCallback", which is no longer what four of its callers use it for, and the two guards part company exactly when a first arrangement did not produce a layout: the instance-field widgets try again on the next connection, lf-ask never does. references/packages.md tells package authors to call connect() from connectedCallback but leaves which guard decides the build unstated, so a package copying lf-workspace and one copying lf-ask get different reconnect behaviour. Worth picking one.
The direction of the change reads right: every querySelector for a generated wrapper is gone from the runtime and the packages, the removed lost its arranged regions guards are guards the new shape cannot need, and nothing in the tree still imports registerReadingElement or fitRootReadingElement.
Verification
Merged tree at 890edbb (head 3207402).
uv run pytest tests/test_render_widgets.py tests/test_render_projection.py -k "workspace or pane or partition or playground or visual_review or ask or monitor or reading or layout"— 83 passed.uv run pytest tests/test_render_startup.py -k "arrangement_admission or reading"— 2 passed.- Base-discrimination run:
git apply -R --include='skills/leaf/assets/*' --include='skills/leaf/packages/*'over the PR diff, then the three node ids above — 3 passed.
Checked and found clean: no remaining .readingArrangement consumer or generated-wrapper selector in JS; data-lf-done is never serialized and no reading element is cloned, so a fresh instance over already-arranged markup is unreachable and dropping the rediscovery branch loses nothing; version.js keys upgraded widgets by id, so a retained region id cannot go stale under a patch.
|
I made the build boundary explicit: a single atomic arrangement is guarded by its retained handle and is marked upgraded only after successful construction. Ask now follows that same rule. Playground and VisualReview retain their one-shot guards around broader DOM/control/listener builds; reconnect only reactivates their retained layouts, and the package contract makes clear that compound construction is not a retryable transaction. The new pane test drives actual custom-element connection callbacks with an occupied region id, releases it, then reconnects twice. It verifies refusal leaves authored nodes and upgrade readiness untouched, successful registration and retirement, and retained node identity and reader draft. It passes on the candidate and fails against the base runtime with “a reading arrangement needs owner and content elements” on reconnect. The earlier reconnect checks remain behavior-preservation coverage; their passing on the base is expected for a refactor and is not presented as fault discrimination.
|
|
Confirmed on both counts. The new pane test discriminates. I checked the eight asset and package files out at the merge base The guard split is resolved too. One leftover, not blocking: VerificationAt head
|
Reading widgets reconstructed their registration declarations and searched generated wrappers whenever they reconnected. Keep one layout handle containing the nodes and region declarations instead. Its connect/disconnect lifecycle owns registration and root-fitting observers, so structural widgets, playgrounds, and visual reviews reuse their existing DOM and controls.
Replace the separate registration and root-fitting APIs throughout the runtime, package callers, examples in tests, and package guidance. Reconnect coverage exercises retained nodes and playground values, then continues keyboard and responsive-layout journeys.
Single-arrangement widgets retain a successful handle before marking their upgrade complete, so refused region admission can retry on a later connection. Compound widgets keep their one-shot chrome/listener builds and reconnect only retained layouts. A browser regression reproduces occupied-region refusal, release, retry, and a second reconnect with the same nodes and reader draft; it fails against the base runtime's generated-wrapper rediscovery.
Validation: all 1,272 everyday tests, 33 runtime tests, and pre-commit checks passed. The complete startup/widgets/projection selection had 423 passes; three environmental failures passed on rerun. Two remaining thread-disclosure expectations reproduce identically on the base tree and are already being updated in #917. Matched desktop playground screenshots were byte-identical; startup used the same 172 requests and 2,700 fewer response-body bytes.