Repository navigation
Let a URL name a part of a widget by its key - #5034
Merged
Merged
Conversation
A widget that draws one item at a time (`lf-items` here, answering keys such as `b/3` through `lfRevealDatum` and `lfElementsFor`) has parts no element id can name: they are absent until their item is drawn, and every item's parts would share ids. The test loads `#items:b/3`, follows a link to `#items:a/2`, goes Back and Forward across them, and reloads the URL `navigateToDatum` writes. On main the fresh load stays on item a, since `fragmentTarget` reads only element ids. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A fragment now names an element by its id, `#<id>`, or a part of a widget by the widget's id and a key the widget answers, `#<id>:<key>`, such as `#build-log:3-5` for lines 3 to 5 of a code block. Every route that reads a fragment resolves the key through the step threads and `navigateToDatum` already share: `revealAddressed` draws the part, `addressedElements` finds it. - `fragmentAddress` (anchor-resolution.js) reads the whole fragment as an element id first, so an authored id holding a colon keeps its link, and otherwise as a widget id split at the first colon and a key. `fragmentTarget` returns the drawn part, else the widget, so the readers that need only an element (a reply link's liveness, a tab set's panel, the thread link's precedence) land on the widget as before. - A followed link and Back or Forward ask the widget to draw the key's part, then land on it. Back to an entry whose item the user has since left is a place the page no longer shows, so it travels rather than restoring the offset. - At load the widget's answer counts as a deferred arrival, and the page lands on the part once it is drawn. A reload or full-document traversal also lands a key the widget does not draw once it upgrades, since the restored offset was read over another of the widget's states. - `navigateToDatum` writes the key's fragment. Where the part was already readable, so the step adds no history entry, it now renames the current entry to the key instead of leaving the URL on the previous place. - `fragmentUrl(element, key)`, exported from widget-api.js, builds the URL, so a copy-link control doesn't spell the format. The heading link uses it in place of its own copy of the id spelling. Rejected spellings, recorded in anchor-coordinate.js: a query parameter as the thread link uses (`?thread=`), since a reply's link must stay in the document and only a fragment change does; and a space separator, which HTML forbids in ids but spells `#items%20b/3` in every hand-written link. Tests: `test_a_url_naming_a_widget_key_reaches_its_part` drives a widget that draws one item at a time through a fresh load, a followed link, Back, Forward, `navigateToDatum` and a reload. It fails on main at the fresh load. Reverting the Back handling or the reload landing each fails it at that step. Runtime tests cover the spelling's round trip and the element-first resolution. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A reload or full-document traversal of a URL naming a widget's key now asks the widget to draw the key's part, as a fresh load does, but keeps the browser's restored offset rather than landing on the part. The offset was read over the item the URL names, so drawing that item puts the user back where they were. Landing on the part, the previous commit's rule, would also move a user who had scrolled away from it, and would override the reading place a live revision's reload hands over. The test now reloads at the part `navigateToDatum` reached. Making the reveal depend on a fresh load fails it at the reload, where the widget draws its first item instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
leaf-agent
reviewed
Nov 2, 2026
leaf-agent
left a comment
Collaborator
There was a problem hiding this comment.
Back/Forward can still show the wrong widget item when returning across root tabs.
# Conflicts: # dist/kernel/kernel.json # dist/kernel/runtime/bundle-data.js
Reloading `#review-patch:["…/config.md","file"]` on an `lf-diff view="file"` drew the diff's first file, not the picked one. The arrival asked the widget for the part only where no node answered the key, and a one-file view keeps every unselected file's node in the page, hidden until found. A fresh load worked only because its landing's reveal fired `beforematch`. `fragmentShown` (anchor-travel.js) is now the one test of whether the page shows the place a fragment names: a node that answers the key and shows its contents. Back and Forward and the arrival both ask the widget for the part where it is false. The prepaint script now also reads a key fragment's widget id, the text before the first colon, when it picks a tab set's opening view. A fresh load of `#tabbed:20-22` into a non-default tab showed the default tab until widgets upgraded (226 ms in Chromium, up to 369 ms in Firefox). Probed with the reviewer's fixture, the named tab now shows from the first frame in both engines, as it does for a plain `#tabbed`. Prepaint runs before any module loads, so it carries its own copy of the split rule, and its comment points to `fragmentKey` as the rule's home. module-reading.md no longer says a reload and Back or Forward land on the part: they draw it and keep the restored offset. Tests: `test_reloading_a_picked_file_reopens_it_in_a_one_file_view` picks a file through `lf-file-tree`, reloads, and expects the picked file shown and the first file hidden. With the old condition, the reload leaves the picked file's lines undrawn. Probing examples/developer/file-tree.html, the picked file reads 233 px and the first file 0 px after a reload, in Chromium and Firefox. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # dist/kernel/runtime/bundle-data.js # dist/kernel/runtime/bundle-errors.js
max-sixty
marked this pull request as ready for review
November 2, 2026 06:10
# Conflicts: # dist/kernel/kernel.json # dist/kernel/runtime/bundle-content-layout.js # dist/kernel/runtime/bundle-data.js
# Conflicts: # dist/kernel/runtime/bundle-data.js # dist/kernel/runtime/bundle-errors.js
Back to `#items:b/3` from another root tab opened the first tab but left the widget on the item the user had picked since, so the window showed part 3 of item a under item b's URL. `mountHistory` let a traversal go to one owner: the claimant, a root tab set opening the view the entry names, or travel (`returnToFragment`), never both. A traversal now runs the claimant first and then asks travel about the page the claimant leaves. Travel takes over only where the entry's fragment still names a place that isn't shown (`fragmentShown`), so a plain id inside the view a tab set has just opened keeps the tab set's placement, as before. Either step places the viewport unless it resolves to false, and the entry's checkpoint offset applies only when neither did. Behavior that moved: Back or Forward into another root tab whose entry names an element still hidden inside that view, such as one in a closed disclosure, now opens it and lands there, as the same traversal does without a tab set. Test: `test_back_across_root_tabs_draws_the_key_the_entry_names`, in Chromium and Firefox, follows `#items:b/3` inside the first of two root tabs, picks item a inside the widget, switches to the second tab, and goes Back. Without this change it fails in both engines with item b undrawn. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # dist/kernel/kernel.json
leaf-agent
previously approved these changes
Nov 2, 2026
…still isn't shown The package-author reference said a claim handler that places the viewport owns placement. Since the claimant now runs first and travel follows it where the entry's fragment still names a place the page doesn't show, the reference says so. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # dist/kernel/runtime/bundle-content-layout.js
leaf-agent
approved these changes
Nov 2, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 3, 2026
…er applies the traversal (#5196) In Firefox, Back or Forward to a place the page had hidden since, such as an element in a tab the user closed, left it at the offset the entry had been saved at. On a fixture with a disclosure opened above the tab set, Back put a plain `#tabbed` target 471 px down in Firefox, where Chromium lands it at 59 px. Main has the same bug, and #5034's widget-key links, such as `#tabbed:20-22`, go through the same path. **Cause.** Firefox applies a same-document traversal some milliseconds after its `navigate` event. As it does, it fires `popstate` and then restores the destination entry's saved offset, even though Leaf intercepted the traversal with `scroll: "manual"`: `nsDocShell::HandleSameDocumentNavigation` never reads the suppression flag that `Navigation.cpp` sets. Leaf's handler has usually landed the place by then, so Firefox overwrote the landing. WebKit 27.2 reveals the fragment's target and scrolls to it as it applies a traversal, which overwrites Leaf's placement the same way. **Fix** (`browser/runtime/history.js`). The traversal handler places the page as before: the claimant, travel or the entry's checkpoint, each reading the page before the browser applies the traversal and reveals what it names. The handler then notes where the first block on screen stands, waits for the rendering update after the traversal's `popstate` (`traversalApplied`), and scrolls the page back by however far that block moved. Scroll anchoring holds that block still through a layout change above it. A traversal Leaf leaves to the browser, one with no checkpoint, is unchanged. Review turned down three other designs, each with a probe. Placing only after the browser applied the traversal let Firefox and WebKit reveal the target before travel read the page, so a root-tab entry whose target sat in a disclosure closed since stayed at the stale offset, and a rapid second Back saved the wrong offset for the entry in between. Putting back the handler's own offset undid legitimate scroll anchoring in Chromium. `history.scrollRestoration = "manual"` stops the browser's restore in both engines, but Firefox then put a Forward that Leaf had no checkpoint for at the top of the page, and every traversal after a reload has none. **Measured** with `leaf-dev probe --base` on fixtures covering plain-id and widget-key entries, an entry whose target is still shown, root tabs, and a target in a disclosure closed since, in Playwright's Chromium 156, Firefox 157 and WebKit 27.2: - Chromium: identical to main at every step, including probes where content grows above the reader during the traversal. - Firefox: Back and Forward to a since-hidden place now land where Chromium does (59 px against 471 px on main), including a root-tab target in a closed disclosure with the page above it grown (59 px against 1,329 px). - WebKit: the same landings. Back to a fragment entry the user had scrolled past now returns to their reading offset, where main scrolled back to the fragment. - A rapid Back from inside the first Back's `popstate` keeps the intermediate entry's offset, as on main. **Left as it was.** Firefox blurs the focused element as it applies a traversal, so focus still ends on `body` after Back there, as on main. Content growing inside the first block on screen in the frame after Back, or a pinned (fixed or sticky) first block, defeats the measurement; the first scrolls that block back as on a browser move, the second leaves Firefox at its restored offset as on main. Back pressed while Leaf's own landing is still scrolling can let Firefox reveal a root-tab target before travel reads the page; main fails that case too. **Test.** `test_back_to_a_fragment_the_page_has_hidden_since_lands_on_it` now runs in Chromium and Firefox, opens a disclosure above the tab set before going Back, and checks that the target lands at the scroller's landing edge rather than only somewhere in view. Its Firefox cases fail on main (the target at 2,480 px and 202 px against 59 px) and fail with the step after `popstate` removed. The browser tests that go Back or Forward pass (51 cases), as do `pnpm run test:runtime` and `pnpm run check:browser`. `notes/browser-support.md` records the Firefox and WebKit behaviour and how to recheck it. > _This was written by Claude Code on behalf of max-sixty_
max-sixty
added a commit
that referenced
this pull request
Nov 3, 2026
…d reference (#5232) After `t` to a thread and `m` to an obligation, browser Back skipped the thread and went to where the user was before `t`: consecutive navigation steps shared one history entry while the last landing still showed, whatever trip each was. Rather than add a `g b` key with its own record of where the user had been, Back itself now returns to the item, and the `?` reference lists it. ## Back returns to the item each step left Every navigation step that arrives and moves the page adds an entry where the user stood, as a followed link does. The navigation group is gone: its state, the reading-input listener that ended it, the `landing` and `intent` arguments every caller passed, the replace path in `prepareEntry`, and `openingPassage`. `browser/runtime/anchor-travel.js`'s header records the decision and the alternative it rejected. A first version kept one entry per run of one walk, on the grounds that Shift retraces a walk. Review found two cases it still got wrong: answering an obligation takes it out of On me, so neither Back nor Shift+m returned to it, and an `lf-tally` Next on me merged with `m` though its stops differ. Both come from sharing an entry, so no steps share one. `navigateToDatum` keeps main's #5034 behaviour: its entry names the widget key, and a step that doesn't move renames the current entry to that URL. A Back stop records where the page is headed. With an entry per step, `m m` typed quickly left a stop wherever the first `m`'s glide had reached when the second left: Back put the page at 42px with focus on the first obligation 3,100px below. Following #5227's rule that keys pressed while Leaf moves the page act as if the motion had landed, `readPlace` (`history.js`) records the offset as `scrollGoal(pageScroller)`, so Back returns to the obligation the first `m` landed on, as typed slowly (3146px in Chromium and Firefox). Behavior that changed: - `t` then `m`, then Back, returns to the thread's place, and Back again to where the user was reading. Main returned straight to the reading place (measured with `leaf-dev probe` in Firefox and Chromium). - A run of `m` or `t` takes one Back per stop to undo, where it took one. Back after answering an obligation and stepping on returns to it. ## The command reference lists Back and Forward `keyboard/page.js` declares a run-less page row beside caret browsing's F7, in the platform's spelling: ⌘[ and ⌘] on a Mac, Alt+← and Alt+→ elsewhere. A run-less row never matches in the dispatcher, so the press still reaches the browser. Back's description reads "Return to the place the last walk, Go-to or link left". `bindings.js` exports its `MAC` check so the row uses the platform reading the key spelling already does. ## Tests - `test_back_returns_from_an_obligation_the_walk_travelled_to` covers `t` then `m`, and an `m` walk across an answered obligation; it fails on main (one entry where it asserts two). - `test_back_returns_from_a_thread_the_walk_travelled_to` asserts a `t` walk adds an entry per thread and Back and Forward retrace it. - `test_a_new_reading_passage_ends_a_travel_group` is now `test_back_returns_the_passage_chosen_between_trips`, with the same assertions. - `test_same_passage_and_controls_keep_a_mixed_travel_group` is deleted: it held clicks and controls from ending a group that no longer exists. - `test_keys_pressed_while_the_page_moves_act_as_if_it_had_landed` adds Back after a quick `m m`; it fails with the checkpoint reading `scrollY` (Back lands at 0). - `test_an_option_that_runs_from_nowhere_still_says_its_keys_and_why` also checks that Back is a disabled option whose accessible description gives its key and description. - `pnpm run check:browser` and `pnpm run test:runtime` (754) pass, as do the Back, keys-during-motion, widget-key URL and hidden-fragment browser tests. `docs/ui.html` "Back and Forward" states the rule; the glossary drops Navigation group. Inherited: six keyboard tests fail locally on main's own tree as on this branch (checked by node id with this branch's files checked out from main): `test_the_reference_runs_available_commands_and_explains_the_rest` and `test_the_reference_keeps_local_search_state_on_one_lit_surface` in `navigation/test_command_reference.py`; `test_a_command_button_owns_activation_and_the_native_form_default`, `test_a_text_box_keeps_its_keys_from_the_widget_around_it` and `test_a_focused_scope_owns_its_declared_key_while_the_command_is_unavailable` in `navigation/test_key_scopes.py`; and `test_route_corner_hint_overrides_the_rows_face_in_obligation_and_widget` in `controls/test_command_routes.py`. > _This was written by Claude Code on behalf of max-sixty_
leaf-agent
added a commit
that referenced
this pull request
Nov 4, 2026
…URL (#5341) #5034 made `navigateToDatum` write the key it travels to into the URL (`#<widget-id>:<key>`), so a reload or a copied URL reaches the same part. Following the PR walkthrough's `src/summary.rs:259` call location now leaves the URL at `#pr-exact-patch:["src/summary.rs","source","new",259]` (percent-encoded). The nightly journey `test_pr_walkthrough_moves_from_semantic_call_to_exact_patch_comment` still expected the bare `#pr-exact-patch`, so it failed before reaching the line comment it exists to check. It now expects the line's source key in the URL. This keeps #5034's intended behavior and changes no product code. The test failed locally on current main with `Actual value: …/#pr-exact-patch:[%22src/summary.rs%22,%22source%22,%22new%22,259]`, matching the scheduled [run 41432142330](https://github.com/max-sixty/leaf/actions/runs/41432142330), and it passes with this change (`--run-main --run-nightly`). Closes #5127 — automated triage Co-authored-by: leaf-agent <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A URL fragment can now name a part of a widget:
#<widget-id>:<key>, such as#build-log:3-5for lines 3 to 5 of a code block, or#items:b/3for part 3 of item b in a widget that draws one item at a time. Loading, following, reloading, or going Back or Forward to that URL draws the part through the hooks the widget already answers for threads andnavigateToDatum(lfRevealDatum,lfElementsFor, registered visual parts). A load or a followed link then lands on the part, or on the widget where the key names nothing.navigateToDatumwrites this spelling, andfragmentUrl(widget, key)builds it for a copy-link control.What changed
fragmentAddress(anchor-resolution.js) reads the whole fragment as an element id first, as before. Failing that, it reads a widget id up to the first colon and a key after it.fragmentTargetreturns the part the widget has drawn for the key, else the widget, so the readers that only need an element (a reply link's liveness check, a tab set choosing its panel, the?thread=precedence rule) work on the new form unchanged.fragmentShown(anchor-travel.js) is the one test of whether the page shows the place a fragment names: a node answers the key and shows its contents. A node that merely exists isn't enough, since a one-filelf-diffkeeps every unselected file's node in the page, hidden until found.revealAddressed), then lands on it. Back or Forward does the same wherefragmentShownis false, as for an entry whose item the user has since left, and otherwise restores the entry's offset as before.mountHistoryused to give a traversal to one owner: a claimant, such as a root tab set opening the view the entry names, or travel, never both. So Back from another root tab opened the first tab and left the widget on the item the user had picked since. Now the claimant runs first, and travel takes over afterwards only where the entry's fragment still names a place the page doesn't show. A plain id inside the view a tab set has just opened keeps the tab set's placement, as before. Either step places the viewport unless it resolves to false, and the entry's checkpoint offset applies only when neither did. One behavior moves for plain ids: Back or Forward into another root tab whose entry names an element still hidden inside that view, such as one in a closed disclosure, now opens it and lands there, as the same traversal already does without a tab set.fragmentShownis false once widgets upgrade, and its answer counts as adeferredArrival. A fresh load then lands on the part once it is drawn. A reload or full-document traversal keeps the browser's restored offset, as it does for every fragment, and that offset now sits over the item or file the URL names rather than the widget's first one.fragmentKeyin anchor-coordinate.js as the rule's home.navigateToDatumwrites the key's URL. When the part is already readable where the user is, the step adds no history entry (unchanged), but it now renames the current entry to the key. Before, the URL kept naming the previous place, and a reload went back there.fragmentUrl(element, key)in widget-api.js is the one builder of the spelling. The heading link's copy of the id spelling now calls it.module-reading.md("Following a reference") documentsfragmentUrland links to parts;module-scroll-and-motion.mdcoversfragmentTargeton the new form;threads.mdgives agents the reply-link form for code lines,[the retry](#client:12-18).Choices Max may reverse
#<id>:<key>, element id first.anchor-coordinate.jsrecords the rejected options. A query parameter like the thread link's?thread=was rejected because a reply's link has to stay in the document, and only a fragment change does. A space separator, which HTML forbids in ids, was rejected because every hand-written link would spell#items%20b/3.fragmentUrlpercent-encodes a colon in the widget id, so URLs built byfragmentUrlread back exactly. The one case left ambiguous: a dead link to a removed authored id that contains a colon (#a:bwith noa:bleft) lands on a live elementainstead of reporting the link missing.navigateToDatumthat doesn't move the user renames the current entry (above).Not changed
The issue mentions a check that a reply's fragment link is live. That check exists only in the browser (
anchor-controls.js,paintMessageReferences), which readsfragmentTarget, so it accepts the new form and no Python changes. Python never splits a fragment, so the split rule lives inanchor-coordinate.js, with the one copy prepaint needs.Evidence
tests/browser/navigation/test_reading_place.py::test_a_url_naming_a_widget_key_reaches_its_partuses a fixture widget that draws one item at a time (parts keyedb/3, item drawn after a 50 ms fetch) and a referrer callingnavigateToDatum. The test covers a fresh load of#items:b/3, a followed link to#items:a/2, Back, Forward,navigateToDatumtob/1(URL and focus), and a reload. On main it fails at the fresh load (item b is never drawn). Two mutation checks: putting back the oldreturnToFragmentcheck fails the test at Back, and limiting the load-time request for the part to fresh loads fails it at the reload.tests/browser/test_render_diff_controls.py::test_reloading_a_picked_file_reopens_it_in_a_one_file_viewpicks a file inlf-file-treebeside anlf-diff view="file", reloads, and expects the picked file shown and the first file hidden. With the arrival asking only where no node answered the key, the reload leaves the picked file's lines undrawn and the test fails.test_reading_place.py::test_back_across_root_tabs_draws_the_key_the_entry_names, in Chromium and Firefox, follows#items:b/3inside the first of two root tabs, has the widget draw item a throughlfRevealDatum, switches to the second tab, and goes Back. Before the change it fails in both engines with item b undrawn, as Tend's review reported.examples/developer/file-tree.html, probed withleaf-dev probein Chromium and Firefox: after pickingconfig.mdthe URL reads#review-patch:["plugins/worktrunk/skills/worktrunk/reference/config.md","file"], and after a reload the picked file is 233 px high and the first file (benches/CLAUDE.md) 0 px, the same as before the reload.lf-codesits in a second tab: every frame the probe recorded, from the first one, during a fresh load or reload of#tabbed:20-22shows the second tab, as for#tabbed, and line 20 ends up 59 px from the window's top. Before this change the default tab showed until 226 ms (Chromium) or up to 369 ms (Firefox).lf-codeblock and a reply reading[the retry](#client:4-8)and[missing block](#gone:2). The first link is live (title "Jump to § client:4-8"), and pressing it lands focus on line 4 at the top of the window. The second link shows as detached ("§ gone:2 isn't in the version shown").tests/runtime/addressed-parts.test.mjs: the URLfragmentUrlbuilds reads back to the same id and key, including a JSON diff key, a key that contains%, and a widget id that contains:. Element-first resolution: an authoreda:bwins, an undrawn key names the widget, a drawn key names its part.pnpm run test:runtime: 744 pass.tests/browserforgo_back/go_forward), plus the side-list history test, the tab-fragment tests, the file-view reload test, the addressed-link test and the fresh-load journey: 57 pass at-n 2on the final head. On an earlier run,navigation/test_tabs.py::test_overflowing_section_tabs_reveal_and_open_their_sectionserrored once at teardown with a recorded page problem I didn't capture. It passed in four reruns, and it loads only a plain fragment and makes no traversal.-n 2) of the tests that read the changed paths, run on an earlier head (main merged at 1f49b64): fragment links and history (test_reading_place.py,test_render_navigation.py), tab fragments and tab sets that reload (widgets/test_tabs.py,navigation/test_tabs.py),navigateToDatumthrough the file tree and call diff (test_render_diff_controls.py, all oftest_code_review.py), heading links, thread URLs, reply-link liveness, fresh-load arrival (test_reading_position.py, and the journeytest_a_followed_link_arrives_as_a_fresh_load_of_it_does). 55 passed and 2 failed. Both failures fail the same way with this change absent, on this branch's original base (2a9d00d) and on main at 1f49b64:test_code_review.py::test_datum_travel_resolves_the_destination_after_reveal(the first press reportsapp.py:2missing) andtest_render_options.py::test_a_group_of_bare_labels_reads_as_a_question_about_the_page(line 1449 reads""where it expects"✓").presentation.js, whichleaf.jsalready loads). Against main, the eager kernel bundles grow by 1.9 KB uncompressed (bundle-data.js+910 B,bundle-content-layout.js+541 B,bundle-errors.js+488 B), and the prepaint script inlined in every page by 466 B. Not compared with a served preview.Closes #4993