Skip to content

Keep the user's place across the reload a restarted server's runtime asks for - #6778

Merged
max-sixty merged 15 commits into
mainfrom
agent-a9841f1915305a698
Nov 23, 2026
Merged

max-sixty merged 15 commits into
mainfrom
agent-a9841f1915305a698

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

When a page's server restarts under a Leaf whose browser runtime differs, the open tab reloads itself (reloadNow in layer-client.js), and since #6765 that happens once per Leaf update for every page a session holds, often seconds after the user sent something from the tab. That reload dropped the user's place: a margin card or the panel's view closed under the reply being written in it, the panel's field lost focus and caret, a reader below a disclosure they had opened landed 1800px off, and the panel's Threads and On Me lists closed. Keys the user typed on with as the tab reloaded ran Leaf's single-key commands in the new document; probed at a key every 60ms, they opened another thread, showed Go-to hints and resolved a thread in the log, and a Space typed first scrolled the page and turned on design mode. Words typed as the server restarted put the browser's "Changes you made may not be saved" prompt in front of the reload.

Every reload Leaf asks for now goes through reloadDocument, and the document writes, as it goes (pagehide), the one-use handoff a revision whose executable changed already used (handOff in version.js), so no second restore mechanism is added. What the handoff carries grows where the reload showed gaps: the reader a reply was written in (readerOf), so a reply typed in the panel's thread view comes back there rather than in the thread's margin card, and the panel's open list with its row and scroll (captureCurrentLocation in floating-panel.js).

Keys typed through the reload go into the restored box. prepaint reads the handoff once for a reload of its own address (lfStorage.handoff), so the bootstrap knows before any module loads that a place is coming back. Until the new document has handed it back, no key is ready (placeHandedBack) and the held keys replay only afterwards, wherever focus is. Meanwhile a key the hold keeps, or a bare modifier such as a capital's Shift, is no input, so it doesn't stop the hand-back, while a key that acts, such as Tab or PageDown, does, and drops the held keys. Where the user was writing (typing in the handoff), a Space starts a held run as a letter does, and the hold takes keys whatever the single-key preference. drafts.js skips its leave prompt only for the beforeunload Leaf's reload raises (takeLeafUnload), so after a page's own prompt keeps the document, a later departure asks again.

To weigh: the handoff and the panel's location also serve a revision's fresh document and a Back to a working place (history.js), so those now reopen a panel list and return a panel reply to the panel too. Ordinary loads keep counting held keys: probed against main, a load at a URL fragment and a Back to the page with keys typed during startup land and act the same; uncounting held keys there let an unsent comment's box reopen under the keys and lost some of them, so it applies only to Leaf's reloads. Still lost: a disclosure with no id, and focus on a widget's generated control with no data-lf-carry, since carry.js matches by authored id.

Probed on main and here with leaf-dev probe --base on the real path: card reply, panel thread reply, panel page comment, passage comment, a just-sent reply in card or panel, Threads on a row, On Me scrolled, a scrolled reader with an open disclosure, and typing through the reload (a capital first, a Space first, into a passage comment, with single-key commands off) each come back as they stood, the typing cases also in Firefox; on main each lost its place. Three fresh-context reviews used the change and read the diff, and Tend's review found the Shift case; their findings are fixed here.

Tests: test_a_reload_into_another_runtime_keeps_the_user_where_they_were (card, card at a version's address, panel), ..._keeps_the_panel_s_list_open (Threads, On Me), test_keys_typed_through_the_reload_go_into_the_reply_it_hands_back (a capital first, a Space first, a passage comment, single-key commands off), test_words_typed_as_the_server_restarts_go_with_the_reload_unasked and test_a_page_s_own_prompt_the_user_stays_at_leaves_leaf_asking_before_they_leave fail without the change, except the passage-comment case, which guards a loss that depends on the replay's timing. The 24 startup key tests, the 28 tests that press Back, 27 revision-continuity tests, pnpm run test:runtime and pnpm run check:browser pass.

This was written by Claude Code on behalf of max-sixty

…asks for

When a page's server restarts under a Leaf whose browser runtime differs,
the open tab reloads itself (`reloadNow`, layer-client.js), and since
#6765 that happens once per Leaf update for every page a session holds.
The reload dropped the user's place: a margin card closed with the reply
being written in it, the panel's field and the panel's thread view lost
focus, a passage comment's caret jumped to the end of its words, and a
reader scrolled below a disclosure they had opened landed 1800px off as
it closed. Drafts survived, since the page's server keeps them.

The reload now writes the same one-use handoff a revision whose
executable changed already writes before its fresh document
(version.js, `handOff`, factored out of `reloadInto`): reading place,
margin and panel location, editing continuity with its caret, carry for
authored ids (values, disclosures, focus, scroll), comparison, pointer
and obligation location. The version controller hands layer-client.js
the capture (`handOffReloads`), since layer-client.js can't import it.
The arrival now accepts a handoff at the revision it was written at,
which only this reload writes, and at any page address rather than only
the live root, since a stamped version's address reloads the same way;
consumed on arrival, it still can't replay on an ordinary reload.

Tests: the new `test_a_reload_into_another_runtime_keeps_the_user_where_they_were`
(live and version address) drives the real path, a server whose answers
name another runtime, and checks the card's reply keeps focus, words and
selection and an opened disclosure stays open; it fails on main.
…after a fresh document

A reply the user was writing in the floating panel's view of a thread
about a passage came back, after a fresh document, in the thread's
margin card: its words, focus and caret held, but the panel's view
closed. The reply's continuation opened the thread by the default route,
which puts such a thread beside its passage. This held for a revision
that needs a fresh document and, since the previous commit, for a reload
into another runtime.

The editing continuity now records the reader the reply was written in
(`replyReader`, from the thread destinations' new `readerOf`) and opens
the thread there again, as a settlement's Undo returns the user to the
reader it was made in. A reply in a margin card records none and takes
the default route as before.

Tests: the reload test gains a `panel` case, which fails without this
commit (the panel's view is gone after the reload) and passes with it;
27 revision-continuity tests selected by `-k`, the owner-index test,
`pnpm run test:runtime` and `pnpm run check:browser` pass.
leaf-agent
leaf-agent previously approved these changes Nov 22, 2026
…e a reload Leaf asks for

A fresh-context review found two faults on the reload path. The restarted
server refuses the old tab's draft writes, so words typed as it restarts
are stranded and drafts.js's `beforeunload` put the browser's "Changes
you made may not be saved" prompt in front of a reload the user never
asked for (also on main); a user who stayed was left on a tab that
refuses every answer. And because the handoff was written before
`location.reload()`, a reload the user stayed through left it behind for
a later manual reload, which reopened the card and moved the page.

Every reload Leaf asks for now goes through `reloadDocument`
(layer-client.js), and `leafReloads` says one is under way. drafts.js
skips its prompt then, since the tab carries the waiting words to the
reload. The version controller writes the handoff from `pagehide` while
Leaf's reload is under way (`reloadInto` now records only where its
reload lands), so the handoff describes the moment the document went,
keys typed while the reload loaded included, and whichever reload ends
the document carries the place the user then left. The capture callback
layer-client.js held (`handOffReloads`) is gone, and the arrival drops a
comparison the revision check already implies.

Tests: the new `test_words_typed_as_the_server_restarts_go_with_the_reload_unasked`
fails on main's drafts.js ("navigation cancelled by beforeunload dialog")
and passes here; the restart helper now rewrites every answer, as a real
restart does. The reload tests, 27 revision-continuity tests by `-k`,
`pnpm run test:runtime` and `pnpm run check:browser` pass, and the
reviewer's cancel journey now reloads with no prompt, keeps the words
typed through the restart, and leaves a later manual reload alone.
leaf-agent
leaf-agent previously approved these changes Nov 22, 2026
…n the panel's lists, and keep the leave prompt for later departures

Three gaps a second review round found in the reload path:

- Keys the user typed on with as the tab reloaded ran Leaf's single-key
  commands in the new document before the reply box came back: probed at
  60 and 150 ms a key on main and on the previous commit, the rest of
  the sentence opened a thread in the panel, resolved a thread in the
  log, and went into a stray comment box. The bootstrap held the keys,
  but the input clock counted them, so they cancelled the hand-back, and
  then replayed as commands. Now, while the arriving document hands a
  place back, no key is ready (`placeHandedBack`, keyboard/bindings.js),
  so the bootstrap keeps holding printed keys, and the hand-back's
  intent counts only inputs that take the user elsewhere (a press,
  wheel, touch or leaving the window; `moves` in document-inputs.js,
  `keys: false` in user-intent.js). Once the place is back the held
  keys replay into the restored box.
- The panel's lists closed across the reload: its location named only a
  thread view. It now names an open list a door opens by name (Threads,
  On Me with its tab, the menu, All pages, Versions), the row the user
  was on and the list's scroll, which comes back once what the list
  holds has drawn (`afterSettling`). A return to a working place
  (history.js) reopens such a list too.
- The flag that silenced drafts.js's leave prompt for Leaf's reload
  stayed set once asked, so after a page's own prompt kept the document
  a later close with words the restarted server refused dropped them
  unasked. drafts.js now skips only the `beforeunload` Leaf's reload
  raised (`leafUnloads`, marked by layer-client.js's own listener, which
  runs first); the pagehide handoff still reads the lasting flag.

Tests: `test_a_page_s_own_prompt_the_user_stays_at_leaves_leaf_asking_before_they_leave`,
`test_a_reload_into_another_runtime_keeps_the_panel_s_list_open` (Threads,
On Me) and `test_keys_typed_through_the_reload_go_into_the_reply_it_hands_back`
each fail on the previous commit and pass here. The reload and held-key
tests, the 28 tests that press Back, 27 revision-continuity tests, the
owner-index test, `pnpm run test:runtime` and `pnpm run check:browser`
pass.
…rt during a hand-back

A fresh-context review of the previous commit found that its hand-back
clock (`moves`, `keys: false`) ignored every key, so a user who moved by
keyboard during the reload had focus taken back: one Tab into the
panel's field was undone, and "abcdefghij" typed after it split between
the field and the restored reply. PageDown during startup was overridden
the same way.

What shouldn't stop a hand-back is a key that hasn't acted yet. The
bootstrap's early hold now answers whether it takes a key (`holds`), and
the input clock asks it first and leaves such a key uncounted until the
hold replays it (`holdKeys` in document-inputs.js). A key that acts
natively, as Tab, an arrow, Space or typing into a field does, still
counts and still stops the hand-back, and `moves` and `keys: false` are
gone. Probed again: Tab then typing leaves all ten letters in the panel's
field, as on main; two PageDowns scroll from where the browser put the
page and the hand-back doesn't move it; typing through the reload still
lands whole in the reply, in Chromium and Firefox.

Also from the review: the hand-back no longer waits on the panel's
restore (it held keys on promises with no bound), held keys are dropped
rather than replayed as commands when an input of the user's stopped the
hand-back, the drafts prompt's reload check is a flag drafts.js takes in
its own listener (`takeLeafUnload`) instead of a second listener and an
event identity, `NAMED_LISTS` derives from the panel's `doors`, and the
comments in history.js and leaf.js name the panel's lists beside its
thread view.

Tests: the reload tests, the 24 startup key tests, the 28 tests that
press Back, 27 revision-continuity tests, the owner-index test,
`pnpm run test:runtime` and `pnpm run check:browser` pass.
…' names

Main's On view now has an `agent` door, which names no view, so deriving
the lists a location carries from the doors' keys mixed door names with
view names. A list comes back where its route is the view's name alone,
as Threads, On Me, the menu, All pages and Versions are; a route a
qualifier carries, as a menu group or Errors does, still stays shut.

Tests: the panel-list reload test (Threads, On Me), the other reload
tests and the 28 tests that press Back pass.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A real user typing through the reload will usually press Shift, and in this version that press cancels the hand-back and throws away the keys the hold kept. The input clock counts every keydown that holds doesn't take. holds returns false for a key in HALF_PRESSES, so a bare Shift keydown increments inputs (document-inputs.js, the new holdsKey?.(event) check). After that, currentIntent() in landArrival reads a different inputCount(), the restore skips everything, and the .finally sees inputCount() !== 0 and calls letHeldKeysGo(). So any capital letter, ? or ! typed during the reload loses both the reply box and the words, which is the central case this PR fixes. The hold already treats a half press as neutral (it doesn't letGo), so the clock should agree. test_keys_typed_through_the_reload_go_into_the_reply_it_hands_back misses this because page.keyboard.type sends a capital without a Shift keydown. Typing part of the text with page.keyboard.press("Shift+H") would cover it.

Comment thread browser/runtime/bootstrap.js Resolved
…ld the typed-through test's state answer

Tend's review found that a Shift pressed before a capital typed through
the reload counted as input, so it stopped the hand-back and the held
keys were dropped: any capital, `?` or `!` typed during the reload lost
the reply and its words. A bare modifier acts on nothing and the hold
already treats it as neutral, so the input clock now leaves it uncounted
while the hold stands, as it does a key the hold keeps back.

`test_keys_typed_through_the_reload_go_into_the_reply_it_hands_back`
failed in CI on a key lost between the two documents, which no page code
can receive. It now holds the new document's first state answer while it
types, so the keys reach that document before the hand-back however fast
the machine is, and it types a capital with its Shift; it fails without
this commit's change. A Space typed first in the new document still
scrolls the page, as on any page still loading, and ends the hand-back.

Tests: the reload tests and the startup key tests pass.
leaf-agent
leaf-agent previously approved these changes Nov 23, 2026
…dinary loads' held keys counted

A Space typed as the first key the reloaded page heard was let through,
since on a page still loading Space scrolls. Probed with the reply
holding "Hold the resend" and " until it drains" typed through the
reload: the Space scrolled the page 762px and counted as input, so the
hand-back stopped, the held letters were dropped, and "tr" typed once the
page was ready walked to a thread and resolved it in the log. A user
typing a reply presses Space about one key in six, so this was often the
first key.

The bootstrap now knows before any module loads that the document is a
reload Leaf asked for: the navigation is a reload and the page's tab
store holds the handoff the last document wrote as it went (`handedBack`,
reading version.js's `HANDOFF_KEY`). There a Space starts a held run as a
letter does, and the keys the hold keeps stay uncounted. Probed again,
in Chromium and Firefox: the reply comes back holding "Hold the resend
until it drains", "tr" goes on into it, and the log gains nothing.

Only there: on an ordinary load the input clock counts held keys as it
did before this branch. Probed against main, a load at a URL fragment
lands the same with "tm", "xyz" or "g" typed during startup, but a Back
to a page with an unsent passage comment differed: with held keys
uncounted the comment box reopened under the keys and "xyz" left only
"z" in it, where main keeps the box shut and runs the keys as it always
did. With the uncounting narrowed to Leaf's reloads, every ordinary load
probed matches main.

Tests: `test_keys_typed_through_the_reload_go_into_the_reply_it_hands_back`
now runs a capital first and a Space first, and types on once the page
is ready; the Space case fails without this commit. The reload tests and
the startup key tests pass.
…user was writing, and replay none before the hand-back

A fresh-context review of the previous commit found:

- Keys typed into a passage comment were often lost (3 of 5 runs). The
  page reopens an unsent comment as it starts, so focus was in a box
  before the hand-back; the replay of held keys ran there at once, each
  `insertText` counted as input, the hand-back stopped, and its cleanup
  dropped the keys still being replayed. The replay now waits for the
  hand-back wherever focus is.
- With single-key commands turned off, the hold took no keys, so the
  first key typed through the reload stopped the hand-back and the words
  were gone. Where the user was writing, the hold now takes keys whatever
  the preference, and with the preference off a held key only ever types
  into a box (the replay used to drop every held key then).
- A Space was held on every Leaf reload, even with no box coming back,
  where the panel said "Space run when the page is ready" and nothing ran.
- The bootstrap read version.js's tab-store key as a copied literal and
  worked out a second time whether a handoff was coming.

prepaint now takes the handoff from the tab once as the document starts
(`lfStorage.handoff`, only on a reload) and owns its key, which version.js
writes through (`lfStorage.handOff`) and reads from rather than reading
the tab itself. The handoff records whether the user was writing in a box
(`typing`), and the bootstrap holds a Space, and holds keys with the
preference off, only then (`typingBack`); any handoff still leaves held
keys uncounted (`handedBack`).

Probed again: a passage comment keeps " and more" and the "tr" typed
after it, 3 of 3; with single-key commands off the reply comes back with
" until it drains" and "tr" in it, in Chromium and Firefox; a reader
pressing Space through the reload sees the same as on main.

Tests: `test_keys_typed_through_the_reload_go_into_the_reply_it_hands_back`
gains a passage-comment case and a single-keys-off case; the latter fails
without this commit, and the former passes either way, since the loss it
guards against depends on the replay's timing. The reload tests, the
startup key tests, the 28 tests that press Back, 27 revision-continuity
tests, `pnpm run test:runtime` and `pnpm run check:browser` pass.
…s the document arrives

The review of the previous commit found two gaps in prepaint's take of
the handoff. It accepted any parsed handoff on a reload, so one version.js
then rejected still left held keys uncounted: with a junk handoff in the
tab, an F5 with an unsent passage comment and "xyz" typed reopened the
box holding "...lookz", where main keeps it shut. And it cleared the
handoff in every document as it started, so a document that reloaded
again before arriving (a delivery that moved twice, a startup recovery)
lost the user's place for the next.

prepaint now reads the handoff on first use, which comes after the
bootstrap has taken Leaf's marks off the address, and accepts it only
for a reload of the address it was written for, so the bootstrap and
version.js agree on whether a place is coming back. version.js drops it
from the tab as the document arrives, however it arrived, as it did
before the previous commit. Probed: the junk-handoff F5 matches main in
2 of 2 runs, and the passage comment and Space-first cases keep every
key.

Tests: the reload tests, the startup key tests, the 28 tests that press
Back, 27 revision-continuity tests, `pnpm run test:runtime` and
`pnpm run check:browser` pass.
leaf-agent
leaf-agent previously approved these changes Nov 23, 2026
@max-sixty
max-sixty merged commit 7693ff0 into main Nov 23, 2026
6 checks passed
@max-sixty
max-sixty deleted the agent-a9841f1915305a698 branch November 23, 2026 19:23
max-sixty added a commit that referenced this pull request Nov 23, 2026
Takes in #6778, which keeps the user's place across Leaf's own reloads.

- A revision's reload (`reloadAt`, history.js) now reloads through
  #6778's `reloadDocument`, so it skips the leave prompt and writes the
  handoff at `pagehide`, which #6778 writes only for Leaf's reloads.
- The chrome's location keeps #6778's panel list for a revision, and its
  capture keeps this branch's signature, since a return to a working
  place no longer reads the chrome: the URL names the thread view.
- `test_a_reload_into_another_runtime_keeps_the_user_where_they_were`
  no longer expects an ordinary reload after the handoff to close the
  thread card, since the entry's address names that thread and a reload
  reopens it; the closed disclosure still shows the handoff was spent.

> _This was written by Claude Code on behalf of max-sixty_
max-sixty added a commit that referenced this pull request Nov 23, 2026
… its URL (#6799)

Following a link from a thread in the floating panel and then pressing
Back didn't reopen the thread. The cause was wider than that route:
history recorded the open thread view only where a route scrolled the
page, and the panel, thread cards, revisions and Undo each remembered a
thread their own way. An independent review of the Back/Forward design
proposed one place to return to; this is the first of its two pull
requests.

- **A Back step for every stop.** A route that travels adds an entry
where it moves the page or puts focus somewhere the user wasn't
(`anchor-travel.js`, `prepareNavigationStep`). So each `t` and `m` stop,
a followed link, a Threads row and Resolve's move to the next thread are
steps. Only a user's gesture adds one: a refusal's restoration, a
traversal's claim and a reload's arrival don't.
- **`?thread=<id>` names the thread an entry shows**
(`thread/address.js`). History writes it into every entry (`history.js`,
`nameThread`), renames the current entry as a thread view opens or
closes, and a traversal opens or puts away the named thread once the
page is placed. Escape renames the entry and never traverses. A reload,
or Forward into the page, reopens the thread with focus and without
moving the page. The thread opens where #6796's choice of where threads
open puts it, except that history keeps which view the user stood in, so
Back after Show on page returns to the panel's view they left.
- `notes/browser-support.md` corrects Firefox's account: stock Firefox
names Forward's destination, and drops focus as it applies a return,
which this puts back.

To weigh: the address bar now changes as threads open and close; every
`t` and `m` stop adds a step, even one already on screen ("one Back per
stop", #5232), and so does a Threads row that opens a thread the page
already shows, which #6796's test of that case now expects; Back from a
thread opened from Threads closes the panel, as Escape does, and a Back
to a place in the panel's Threads or On Me list, which #6778 reopens on
`main`, leaves the panel shut, until the second pull request records the
panel's view in entry state; a history write the browser refuses past
its rate limit isn't retried.

Max asked for this. Codex reviewed it four times, the merge with #6796
included, and a fresh agent used it in Chromium and Firefox; their
findings are fixed. Tests: new cases in `test_threads`,
`test_reading_place`, `test_obligation_walk`, `test_navigation` and
`test_tabs`; `test:runtime` and `pnpm run check` pass.
`test_render_floating_panel::test_an_open_view_covers_the_page_beneath_it`
fails on `main` too.

> _This was written by Claude Code on behalf of max-sixty_
max-sixty added a commit that referenced this pull request Nov 24, 2026
…old its keys until that return settles

#6778 kept the user's place across the reload a restarted server forces by
growing the reload's handoff (version.js, `handOff`). This branch's entry
record (history.js) now returns the user to every reload, so the copies
#6778 added for the same places go, and each behavior has one owner:

- The reader a reply was written in, the floating panel's view or the
  thread's card: was the handoff's `replyReader`, read through
  `threadReader` and thread/destination.js's `readerOf`; now the record's
  thread view, whose `reader` the claim passes on (thread/address.js).
  This commit removes `readerOf`; the earlier merge of thread-link-back
  removed `threadReader` and `replyReader`.
- The panel's open list, its row and its scroll: was the list branch of
  floating-panel.js's `captureCurrentLocation` and
  `restoreCurrentLocation`, carried in the handoff; now the record's list
  (history.js, `listShown`). The earlier merge removed that branch.
- Keys typed while the reload loads: were released once the handoff's own
  restore finished (`landArrival`); now they wait for the arrival's
  restoration to settle (history.js, `settled`), which includes the
  record's return, so a key such as `r` acts in the thread view the record
  reopens rather than wherever focus stood when the handoff finished.

A restoration now ends at the user's input within the entry
(focus.js, `entryInputCount`): Back and Forward end it as navigations, and
the entry they leave still gets the record the restoration owes it
(`owes`), rather than a reading of a page half put back.

`installArrival` takes the arrival it joins, which every caller has, so
its fallback intent and the composition input it was built from go.

`test_a_key_typed_through_the_reload_acts_where_the_user_is_put_back`
(Chromium and Firefox) presses `r` as the tab reloads with a panel thread
open, and checks that it resolves that thread.

> _This was written by Claude Code on behalf of max-sixty_
max-sixty added a commit that referenced this pull request Nov 24, 2026
… back

A document a reload Leaf asks for loads took the handoff out of the tab as it
arrived, before it had put back what the handoff carries, and held the keys
typed meanwhile only in its own memory. So a second reload Leaf asks for, as a
server restarted twice causes, coming before that arrival settled, lost both:
the values typed into the page's form, wherever its anchoring wasn't ready yet,
since the departure forwarded what the arrival owed only then, and every key
typed for the place being handed back. Both gaps came with #6778 (7693ff0).

One cause covers both: the arriving document held the user's state for its
arrival in places a departure doesn't keep. The handoff now stays in the tab
until the arrival settles (version.js, `installArrival`), and the bootstrap,
which holds the keys, leaves them with it as the document goes while it is
still kept (bootstrap.js); the next document's hold starts with them. So the
departure no longer forwards what the arrival owes: `handOff` loses its owed
branch, and the restoration its `extras`.

Rejected: holding a reload Leaf asks for until the current arrival settles.
The second reload comes from the arriving document's first answer naming
another runtime, and that refused answer is what presentation, and so the
arrival's settling, waits on, so the reload would wait for ever; and keys held
for a hand-back are no input, so they don't end the arrival either.

Values typed into authored controls stay in the handoff rather than the
entry's record: the record is returned to on every reload and traversal of its
entry, so Back to an earlier entry would put back the values it had then,
undoing what the user typed since. They are the page's working state, as
drafts are, not a place in an entry.

`test_a_value_typed_into_the_page_rides_two_reloads_in_a_row` (with the
arriving document's page interface held, so its anchoring isn't ready) and
`test_words_typed_through_two_reloads_in_a_row_reach_the_reply` fail without
this change and pass with it.

> _This was written by Claude Code on behalf of max-sixty_
max-sixty added a commit that referenced this pull request Nov 24, 2026
… reload return there (#6860)

Each history entry now keeps where the user was in the entry's own
Navigation API state: the place on the page, the place read to in an
open thread and the view it was read in (the panel or its card), what
had focus and its caret, the selection, and the panel's list (which
list, On's tab, the row, how far it was read). Back, Forward, a reload,
the reload a new revision or a restarted server asks for, and a return
from another site put the user back there. It is the second of the two
pull requests the Back/Forward design review proposed, after #6799, and
replaces history's map of places, its pixel offsets and its fallbacks
for a missing Navigation API.

- **When the record is written** (`history.js` header): as the user
leaves the entry. A route's push writes it, `beforeunload` writes it for
a reload or another document, and so does hiding the page.
`history.replaceState` drops an entry's state, so `bootstrap.js` renames
the URL through one `rename` that keeps it.
- **One restoration at a time** (`beginRestoration`): a document's
arrival and each same-document traversal return to the destination's
record under one intent, aborted by a newer one or any navigation and
ended by the user's own input within the entry, counted from their
latest step to it (`document-inputs.js`, `entered`). Leaving the window
is no such input, any more than a step Back or Forward is
(`document-inputs.js`, `away`). A departure while one is pending writes
the record it still owes. A Back taken before Leaf starts returns to the
entry it reached.
- **One owner of the user's place across reloads:** #6778's copies (the
panel list's capture, the reply's reader, keys released at
`landArrival`) are gone. A reload Leaf asks for adds a handoff
(`version.js`) of what the record doesn't hold: values typed into the
page's inputs, the words being written, the comparison and the pointer.
Values stay out of the record, since Back to an older entry would put
older values back; the arrival puts them back on every control except
one the user has changed since the document started
(`document-inputs.js`, `edited`), so what the user types while the page
starts stays, and a value the page's own script sets as it loads gives
way to the carried one. The handoff names its entry and applies its
place only there. `prepaint.js` alone writes and reads it (its header):
each document's first script takes it from the tab and keeps it only
where the document stands at the history entry it was written at
(`navigation.currentEntry.id`), as after a reload, a discarded tab's
return or Back to a page the browser didn't keep, so the tab holds one
only while a document that would hand it on is going, hidden or starting
hidden, until the next document starts or the page shows again. What a
document going or hiding hands on is, before the runtime starts, the
handoff it came with, if any, plus the current state of each control the
user changed, with the place only until the user acts within the entry;
once the runtime starts, the handoff it came with while its arrival is
still owed, else, on a reload Leaf asked for, what the document then
holds, else nothing. The arrival puts back what the handoff carries of
the document, the values, the comparison and the pointer, whatever
becomes of its claim on the place. Where the handoff puts the user back
at this entry (`prepaint.js`, `placesUser`), keys typed meanwhile wait
in a queue of their own (`bootstrap.js`), kept in the tab until each is
pressed where the user is put back or let go, so a second reload before
then loses neither. The user's own step Back or Forward lets held keys
go on any load, those Leaf is still pressing included, so they don't run
at an entry they weren't typed at; the user's step is one the Navigation
API marks `userInitiated`, and any other step, such as one the page's
script takes, lets none go. Where the browser can't say who stepped,
held keys stay and run at the entry the step reached: in an opaque frame
such as a live sample, which hears only `popstate`, and in Firefox,
which reports no step as the user's, the toolbar's Back included ([Gecko
bug 1903552](https://bugzilla.mozilla.org/show_bug.cgi?id=1903552)). The
words are kept either way.
- **How each part is named:** focus by carry's keys (`data-lf-carry` on
Leaf's thread controls, `data-lf-key` on Versions rows); a page
selection as a passage; a selection in a message as a quote with the
context that tells it apart (`findQuote`), dropped rather than landing
on another copy. That context widens through one loop (`passages.js`,
`passageContext`) moved out of `anchorForPassage`.

To weigh: Back returns to the view the user read a thread in, whatever
#6796's threads-in-panel choice now says, so Back to an entry read in a
card draws a card under the panel choice (`reader: "card"`), and a
draft's restore goes to whichever view already shows its thread, a card,
the panel or a widget's seat, and follows the threads-in-panel choice
only where none does (`reader: "standing"`). Focus returns to the exact
control left, so Back to a thread put away by Show on page lands on Show
on page. A composer the user put away stays shut on a reload, a widget's
Feed view isn't kept, nor is a caret in a message. A handoff whose
arrival is still owed when the page goes passes whole to the next
reload, the browser's reload button included, so keys typed through the
first reload still land. Since leaving the window ends no return, a
find-in-page search made while one is still under way can be moved off
its match. The runtime grows by about 660 lines of code and 520 of
comments net, and the scripts inlined in every page (`bootstrap.js`,
`document-inputs.js`, `prepaint.js`) by 12.9 KB raw (4.2 KB gzipped);
most of it returns the user after a reload and from another site, which
the plan hadn't covered. In Firefox, CodeMirror's reply editor raises a
scroll-linked warning when the page goes while the travel to a thread
still glides; the test that met it now lets the glide land, so the
warning still fails every test.

Max asked for this on the Back/Forward review page, which lists the card
return as a call he may reverse. Codex reviewed it repeatedly, and each
finding it reproduced has a test that failed first. Tests: new cases in
`navigation/test_arrival_record.py`, `navigation/test_reading_place.py`,
`startup/test_readiness.py`, `threads/test_navigation.py`,
`threads/test_rewrites.py`, `threads/test_seated_threads.py`,
`threads/test_threads_in_panel.py` and `drafts/test_revisions.py`, in
Chromium and Firefox; the focused selections around them, `test:runtime`
and `pnpm run check` pass. A tab the browser discards while hidden has
no test, since the suite can't discard one: the hide tests check what
the tab holds after the hide, and Back to a page the browser didn't keep
stands in for the return. A probe with Chromium's `chrome.tabs.discard`
showed the returning page at the same entry, with the tab's storage
intact; Firefox's discard is unmeasured. A same-page frame, which no
page has, can still remove the page's handoff or write its own over it,
which the page's next document then drops. A page script that steps Back
after the runtime loads but before the first state arrives lets held
keys run in the box they were typed for, and that typing then supersedes
the return to the entry the script reached.

> _This was written by Claude Code on behalf of max-sixty_
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.

2 participants