Skip to content

Land Back and Forward in Firefox where Chromium does, after the browser applies the traversal - #5196

Merged
max-sixty merged 3 commits into
mainfrom
firefox-back-stale-offset
Nov 3, 2026
Merged

max-sixty merged 3 commits into
mainfrom
firefox-back-stale-offset

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

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

…er applies the traversal

Firefox restores an entry's saved offset just after a same-document traversal's
popstate, even when Leaf intercepted it with scroll: "manual", and WebKit scrolls to
the fragment as it applies one. Both overwrote Leaf's placement: Back to a place the
user had hidden since landed 471 px down in Firefox against 59 px in Chromium.

The traversal handler still places the page before the browser applies the
traversal, so the claimant and travel read the page while it hides what the user hid.
It then scrolls the page back by however far the first block on screen moved once the
browser has applied it. test_back_to_a_fragment_the_page_has_hidden_since_lands_on_it
now runs in Firefox too and checks the landing edge, which changes what it protects
from "in view" to "landed".
@max-sixty
max-sixty merged commit 1c45dac into main Nov 3, 2026
4 checks passed
@max-sixty
max-sixty deleted the firefox-back-stale-offset branch November 3, 2026 08:18
max-sixty added a commit that referenced this pull request Nov 4, 2026
…weep (#5291)

A sweep on 2026-11-03 found 39 capabilities implemented more than once
in Leaf. Tend's review had approved all 10 of the introducing pull
requests checked, and 15 nightly surveys that carried the instruction to
look for "several implementations of one capability" reported none. This
changes the instructions behind both, and adds a weekly sweep for what
review still misses.

- **Review loads `/developing-leaf`.** running-tend's Review threshold
named that skill's "Weigh what a change adds" without saying to load it,
and none of 11 production reviews on 2026-11-03 did. The section now
opens "Load `/developing-leaf`"; 16 of 16 replayed reviews then loaded
it.
- **"What it repeats"** joins "Weigh what a change adds": search for the
question each new helper, constant, selector, style rule or inline check
answers rather than its name, count a copy whose comment names its
source as a copy, and export, move or generate the owner rather than
copy it. "Regular maintenance" points its "Several implementations of
one capability" bullet at it, since the nightly survey reads one file at
a time.
- **Weekly: duplicate implementations** sweeps one area a week, chosen
by ISO week number modulo 4, searching the whole tree by question. Each
copy's introducing pull request goes in the sweep's description, so the
copies added since the area's last sweep show what review let through.

Replaying four pull requests that each introduced a copy (#3832, #5196,
#2345, #3137), reviewers caught the copy 2 of 9 times with the old text,
3 of 8 when told to load the skill, and 5 of 8 with "What it repeats",
whose wording was revised after the replay. That difference is within
noise at this size, and no arm caught a one-line copy inside a new
helper; the weekly sweep is there for those.

This changes agent instructions, so it lands with the control-plane
owner's approval (running-tend, "Landing").

> _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