Skip to content

fix(home, analytics): a stale detail load no longer draws over a newer one (#2461) - #2462

Merged
efiten merged 2 commits into
Kpa-clawbot:masterfrom
zfouts:fix/stale-detail-load-2461
Nov 25, 2026
Merged

efiten merged 2 commits into
Kpa-clawbot:masterfrom
zfouts:fix/stale-detail-load-2461

Conversation

@zfouts

@zfouts zfouts commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Closes #2461.

Problem

The Home health card (loadHealth) and the Analytics route detail (loadSubpathDetail) drew whichever answer arrived. If you clicked A and then B, and A answered last, A (or A's error) replaced B.

Fix

Each view keeps a generation counter: _healthGen in public/home.js, _subpathGen in public/analytics.js.

  • A load bumps the counter and captures it.
  • After the await, in both the success and the error path, the load returns without touching the DOM if the counter has changed.
  • destroy() also bumps it, as do the functions that replace the container the detail lives in (renderHome and showChooser on Home, renderTab on Analytics). A load that lands after a teardown or re-render is therefore dropped too.

No other behaviour changes.

Tests

  • tests/unit/test-issue-2461-stale-detail-load.js (new, 17 cases, registered in test-all.sh) runs the real functions in a vm sandbox with an api stub that the test settles by hand. For each view it covers:

    • A then B, with B answering first: B stays;
    • A rejecting last: B stays and no error is shown;
    • an answer after destroy(), or after a re-render: nothing is drawn;
    • Home: exactly one mini-map for the card that is shown.

    On the old code: 4 passed, 13 failed (the 4 are single-load sanity cases).

  • tests/unit/test-secondary-map-tile-builder.js extracts loadHealth on its own into a sandbox, so it now seeds _healthGen.

Checks

  • sh test-all.sh: all standalone frontend suites pass.
  • eslint: 0 errors.

Performance

No change: one integer increment and compare per load.

Note

#2446 has a unit suite that also extracts these functions into a sandbox. When the two PRs meet, that suite needs the same seed (_healthGen, _subpathGen).

🤖 Generated with Claude Code

zfouts and others added 2 commits November 23, 2026 14:16
…r one (Kpa-clawbot#2461)

The Home health card (loadHealth) and the Analytics route detail
(loadSubpathDetail) drew whatever answer arrived. Click A, then B: if A
answered last, A (or A's error) replaced B.

Each view now keeps a generation counter (_healthGen, _subpathGen). A load
bumps it and, after the await, returns without touching the DOM when it has
changed, in the success path and in the error path. destroy() and the
functions that replace the container (renderHome, showChooser, renderTab)
bump it too, so a load that lands after a teardown or re-render is dropped.

Tests: tests/unit/test-issue-2461-stale-detail-load.js runs the real
functions in a vm sandbox with an api stub settled by hand (17 cases; 13
fail without the fix).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…pa-clawbot#2446's remove helpers

When Kpa-clawbot#2446 is merged, loadHealth and loadSubpathDetail call removeMiniMap /
removeSubpathMap; the suite now extracts them when they exist, so it passes
on either side of that change.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@n30nex

n30nex commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

I tested 943071381 together with the one-click fix in #2474 (060905906). After three Route Patterns renders, I clicked A then B and released A’s response last. Two clicks made two detail calls. B remained selected and the same B panel stayed visible after A completed.

With #2474 alone, the click count was correct and the late A response still replaced B. The two fixes merge cleanly and cover separate behaviors.

efiten pushed a commit that referenced this pull request Nov 24, 2026
Red commit: `bf835b794` ([failing
workflow](https://github.com/Kpa-clawbot/CoreScope/actions/runs/45301799438)).

Fixes #2465. Route Patterns now attaches its row-click handler to the
list created by each render. Changing the theme or tab replaces that
list and its handler together. One click opens the selected route once.

After three renders, the original UI called the detail loader three
times on the first click and six times across two clicks. The shared API
cache combined requests for the same route. The fix produced one call
per click and preserved the selected row. No additional requests or
per-row listeners are needed.

Browser verified: `http://localhost:15265/#/analytics?tab=subpaths`. All
256 standalone suites passed. The VM test and the browser regression
reproduced the duplicate calls on the tests-only revision.

E2E assertion added: `tests/e2e/test-e2e-playwright.js:1237`. In a
combined browser check with #2462, two clicks opened two details and a
late response for the first route preserved the second route’s panel.

---------

Co-authored-by: n30nex <6686206+n30nex@users.noreply.github.com>
@efiten
efiten merged commit b17947e into Kpa-clawbot:master Nov 25, 2026
17 checks passed
zfouts added a commit to zfouts/CoreScope that referenced this pull request Nov 26, 2026
Conflicts:
- CHANGELOG.md: the Kpa-clawbot#2434 entry this branch amended shipped in 3.19.0;
  this PR's change is now its own entry under a new [Unreleased].
- public/home.js, public/analytics.js: keep both Kpa-clawbot#2462's generation
  counters and this branch's removeMiniMap/removeSubpathMap. In the
  health card's catch the stale check runs first, so a stale failure
  never removes the newer load's map.
- test-all.sh: run both new suites.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
efiten pushed a commit that referenced this pull request Nov 27, 2026
… waits on state (#2446)

Closes #2444. Follow-ups from the review of #2434.

## What changes

> **Master merged in** for v3.19.0 (`986bc45e`, master at `7beed94a`).
It conflicted in `CHANGELOG.md` (this PR's line is now its own
`[Unreleased]` / Fixed entry), in `test-all.sh`, and in `public/home.js`
/ `public/analytics.js`, against #2462's generation counters. Both sides
are kept, and in the health card's `catch` the stale check runs before
`removeMiniMap()`. Re-tested: `test-all.sh` (#2444 tile sync 23/23,
#2461 17/17) and lint, 0 errors. CI is green.
>
> Earlier merge (`16300744`, master at `007ba78a`, with #2442 and
#2450): no conflicts. Re-tested: `test-all.sh` and lint.
>
> Earlier merge (`c4da7137`, master at `6ab97f52`, with #2429 and
#2451–#2454): no conflicts, the three commits below are unchanged.
Re-tested on the merge: `test-all.sh` green (map tile pin 31/31); E2E
against a local server: map providers 28/28, providers harness 16/16,
map teardown races 19/19, vector zoom 3/3, map modal 10/10.

Three commits, one per point in the issue, plus `1a8dcbda` for the
review (section 4) and `7ef2d744` and `0cc89290` from an internal review
(section 5).

### 1. `68dc7e27` No Auto tile burst on a load with a saved pick

On a map with a picker that loads with a valid saved pick,
`MC_attachAutoTiles` used to add the theme's Auto group to the map
first. The control then swapped in the pinned layer straight away, so
the Auto tiles were started only to be cancelled.

Now, when the map has a picker and a valid saved pick at attach time
(`public/map-tile-providers.js:1639`), the Auto group stays off the map.
Its layer is built only when the group first joins the map, which
happens in two cases:
- the user picks **Auto**;
- config arriving later turns the pinned group off, so the pin reads as
Auto.

Maps without a picker, and loads without a pin, are unchanged.

Measured on a pinned reload (light theme, pin `osmfr-hot`, CI fixture
server, Chromium), counting tile images started:

| Page | Before: Auto / pinned | After: Auto / pinned |
|------|-----------------------|----------------------|
| `#/map` | 15 / 15 | 0 / 15 |
| `#/live` | 18 / 24 | 0 / 24 |

Chromium had already sent 0 network requests to the Auto host before
this change: an image aborted in the same task never goes out. So the
waste was DOM and JS work, not network. Other browsers were not
measured.

Remaining case: when config arrives after the map is created and the
pinned group is opt-in, the pin is not valid yet at load, so Auto still
shows first.

Tests:
- Unit (`tests/unit/test-map-layer-builder.js`):
- a pinned picker-map load starts no Auto tile; on the old code it
failed with `Auto tiles started: …cartocdn…light_all…`;
  - picking Auto afterwards shows the theme's map;
- config turning the pinned group off and back on starts the Auto tile
exactly once.
- E2E `7d` (`tests/e2e/test-map-providers-e2e.js:453`) counts both
`<img>` src assignments and network requests to each host. On the old
code:
`{"autoStarted":15,"pinStarted":15,"autoRequested":0,"pinRequested":15}`.

### 2. `23acaa15` A pick made in another tab reaches open maps

The cross-tab `storage` handler only covered the two theme keys. It now
also handles `mc-tile-pinned` and a cleared storage (`key === null`)
(`public/map-tile-providers.js:1750`).

- **Validation.** The new value goes through `getPinnedId` as usual.
Empty or removed means Auto. An unregistered id reads as no pin, so a
map without a picker drops to the theme's map, the same as after a
reload.
- **Maps without a picker** re-sync and follow the pin when it fits the
theme, without a reload.
- **Maps with a picker** keep their layer and radio, and their Auto
still ignores the pin. An explicit pick in that tab stands until the
next load.
- **No write-back.** The handler never writes, so tabs can't echo picks
between each other.
- **Unsaved picks.** A newer value from another tab replaces this tab's
in-memory copy of a pick it failed to save (quota full). The existing
rule still holds: a failed write never brings back an older stored pin.
- **No mid-click deferral.** A `storage` event runs as its own task, so
it can't arrive during a layer-control click handler. This re-sync also
never adds or removes a layer the picker lists.

Tests:
- Unit (`tests/unit/test-map-tile-pin.js`): a pick dispatches one event;
clearing it, an empty value, an unregistered id and a cleared storage
each behave as above; other keys are ignored; nothing is written back; a
newer value supersedes an unsaved pick.
- E2E `7e` (`:518`, `:523`, `:531`) uses three tabs in one browser
context, with real `storage` events:
  - tab A picks and tab B's node map switches without a reload;
  - Auto in tab A returns tab B to the theme's map;
- tab C, on the map page, keeps its layer and radio, and no tab writes
the pick back. Since `1a8dcbda`, C first waits for its own
`mc-tile-pinned` storage event.

  On the old code the pick checks time out.
- Race stress scenario `h` (`tests/e2e/test-map-race-stress-e2e.js`,
local only like the rest of that suite) has two tabs make rapid
alternating picks. They must converge, with no page errors and bounded
writes. It failed 4 of 6 iterations on the old code.

One line each in `docs/user-guide/map.md`, `docs/deployment.md` and the
CHANGELOG now describes the cross-tab behaviour. Since `1a8dcbda` that
includes the Home and Analytics maps (section 4).

### 3. `6fda048f` `4b` waits on state, not a fixed 300 ms

Both `waitForTimeout(300)` calls in check `4b` (`:263`) are replaced
with `waitForFunction` on the write count and the checkbox state. After
the wait the check confirms the count has not gone past the expected
value. It still fails with the `0506fc1d` deferral disabled (`eox-labels
box not ticked after the first click`). No `waitForTimeout` is left in
either providers E2E file.

### 4. `1a8dcbda` Review follow-ups

- **Home and Analytics follow the pick.** The Home mini-map and the
Analytics route map used to resolve their tiles once, when built, so a
pick in another tab (or a theme flip) did not reach them, although the
docs said it did. Both now go through the shared `_applyTilesToNodeMap`
helper (`public/nodes.js`), the same one the node, reach and RX coverage
maps use. The provider's own `maxZoom` (OpenTopoMap 17, USGS 16) and
dark filter carry over.
- **Teardown.** Each page drops its map through one function that
unregisters it from the tile-sync registry before removing it:
`removeMiniMap` (`public/home.js:275`) and `removeSubpathMap`
(`public/analytics.js:27`). That includes paths that used to replace the
map's container without removing the map: `showChooser` and `renderHome`
on Home, `renderTab` on Analytics.
- **Other storage areas.** The `storage` handler ignores events from
another storage area (`_otherStorageArea`,
`public/map-tile-providers.js:1745`). A `sessionStorage.clear()` in a
same-origin iframe (`key === null`) no longer drops an unsaved pick. An
event with no `storageArea`, or a `localStorage` that throws when
accessed, is treated as `localStorage`.

Tests:
- `tests/unit/test-issue-2444-secondary-map-tile-sync.js` (new, 18
cases) covers each map's build, a pick, a cross-tab storage event, a
theme flip, destroy, replace, re-render and the fallback with no helper.
On the old code: 4 passed, 12 failed.
- `test-map-tile-pin.js` adds cases for a foreign storage area, an
absent one and a throwing `localStorage`. On the old code the
foreign-area case fails with "the unsaved pick was dropped".
- E2E `7e` (`:551`): the Home and Analytics maps follow a pick in tab A,
and its Auto. On the old code it times out.

### 5. `7ef2d744`, `0cc89290` Internal review follow-ups

- **Lazy Auto tests.** These tests now pin the lazy Auto path:
- on a pinned picker load, the Auto group stays empty, also after a
theme flip and a cross-tab pin;
- a vector theme default is not built, so there is no MapLibre download,
until Auto is picked.

Each test was checked by deleting the line it guards. The unreachable
`lazy && !lc` fallback is removed: the control is null only without
Leaflet.
- **Home mini-map timer.** The resize timer now captures its own map, so
a card replaced within 100 ms no longer throws on a null map.
- **Overlapping and failed loads.** Tests cover overlapping Home loads
and a failed load: the earlier map is removed and unregistered.
- **Cleared storage.** A cleared `localStorage` in another tab now
re-syncs the ticked overlays too.
- **Unsaved overlay tick.** An overlay tick whose save failed now gives
way to a newer value from another tab, or to storage cleared there, as
the pin already did (`0cc89290`).

A slower, older Home or Analytics load drawing over a newer one was
fixed on `master` by #2462 (for #2461), which is now merged in here.

## Performance

Commit 1 removes work: no Auto tile layer and its tile images on a
pinned load of a picker map (table above). The `storage` handler runs
only when another tab changes the pin: one validated read and one event
dispatch, which each map handles with its existing `sync()`.

## Testing

| Check | Result |
|-------|--------|
| `sh test-all.sh` | all standalone frontend suites pass (on `0cc89290`:
layer builder 35/0, tile pin 34/0, secondary map tile sync 23/0,
overlays + vector 34/0; on `1a8dcbda`: tile pin 34/0, layer builder
32/0, secondary map tile sync 18/0, secondary map tile builder 10/0) |
| `npx eslint public/*.js` | 0 errors, 87 warnings, unchanged from
`master` |
| `test-map-providers-e2e.js` | 28 passed, 0 failed; on `1a8dcbda` 29
passed, 0 failed |
| `test-map-providers-harness-e2e.js` | 16 passed, 0 failed |
| Race stress, seeds 20261118, 4242, 777 and 31337 | all scenarios pass
(the cross-tab one was called `g` in those runs) |
| Race stress, cross-tab scenario only, seed 909, 20 iterations | passes
|

The E2E and stress suites ran against the CI fixture, freshened and
migrated, on a local server. The engineer ran two of the seeds and I
re-ran everything with the other two.

**Scenario name and the other open PRs.** The cross-tab stress scenario
is `h`, not `g`. #2436 (the ducting overlay) adds its own scenario `g`.
With both named `g`, git merged the two branches silently into a file
with two `scenarioG` declarations, and only one of them would have run.
`h` also runs outside the scenario table, so the line #2436 changes
there stays untouched. I checked on `master` with #2436, this PR and
#2445 merged together:

- all three merge with no conflicts, in each of three orders;
- `test-all.sh`, lint and the Go suites pass;
- the providers E2E passes 28/28, the harness 16/16 and the ducting E2E
28/28;
- the race stress suite passes scenarios a–h on seeds 20261118 and 5150.

No screenshots: nothing visual changes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

Home health card and Analytics route detail: a slower, older load draws over the newer one

3 participants