mirror of
https://github.com/Kpa-clawbot/meshcore-analyzer.git
synced 2026-11-22 12:27:59 +00:00
fix(nodes): light-mode map follows tile picks, key and theme changes
(#1470/#1420)
## Problem
The node-detail maps (`#/nodes/<pubkey>` full page + side pane — and
their
reusers `node-reach-map.js`, `rx-coverage.js`) pick a different basemap
in
**light mode** than the rest of the app:
- hardcode Carto Positron: the user's *Light Mode Provider* customizer
pick
and the operator's `map.tiles.lightDefault` are ignored
- render Carto's `API KEY REQUIRED` watermark when `/api/config/client`
lands after the map is created — the tile requests stay keyless until a
remount (they come back HTTP 200, so nothing surfaces as an error)
- never react to a theme flip or provider change while the page is open
Dark mode is unaffected, which is why it only shows up in light mode.
Reproduce on `master`: open `#/nodes/<id>` in light mode with
`mc-light-tile-provider = carto-voyager` — the inset requests
`light_all`
while the main map requests `rastertiles/voyager`.
## Root cause
`_applyTilesToNodeMap` (`public/nodes.js`) asked `window.getTileUrl()`
for a
single URL string, and roles.js's light branch returned the frozen
`TILE_LIGHT` scalar — the dark branch was the only one that consulted
the
runtime registry (`public/map-tile-providers.js`), which is what owns
localStorage picks, server defaults, the Carto key, and per-provider
attribution/maxZoom/refUrl/invertFilter. map.js and live.js keep the
only
other registry-aware resolvers of the same logic.
## What this PR does
- adds one resolver, `MC_resolveTile(isDark)`, in map-tile-providers.js,
returning the full descriptor
`{ type, id, url, attribution, maxZoom, refUrl, invertFilter }`:
- `url` is always a resolved string — function-typed providers are
invoked at call time (contract of #1614)
- one precedence rule everywhere: explicit operator overrides
(`cfg.tiles.dark|light`, `map.tiles.darkUrl|lightUrl`, tracked via
`MC_LEGACY_TILE_OVERRIDE`) > user/server registry pick >
`TILE_DARK`/`TILE_LIGHT` constants — **this is a deliberate behavior
change on map.js/live.js, see below**
- fully lazy: registry rebuilds / pick changes are picked up by the next
resolve, so config landing after page load fixes itself
- roles.js `getTileUrl()` becomes a thin wrapper over it; the public API
and
the #1614 sandbox contract are unchanged; `getActiveTileProvider()`
keeps
its documented null-in-light contract
- `nodes.js _applyTilesToNodeMap` resolves through the descriptor and
stays
reactive: one shared `mc-tile-provider-changed` listener + one
`data-theme`
MutationObserver re-sync every registered map in place — old layers
removed
before the new ones are added, never stacked; maps whose container left
the
DOM are pruned at sync time, so SPA navigation cannot leak listeners
- map.js `_resolveTileUrl` / live.js `_liveResolveTile` delegate to the
shared resolver (their legacy bodies remain only as sandbox fallbacks)
- provider `maxZoom` replaces the hardcoded 18/19 caps (OpenTopoMap 17
and
USGS 16 used to 404 above their max zoom)
- analytics.js subpath minimap gets provider `maxZoom` as well
## Behavior change (deliberate): operator URL overrides now win on every
surface
On `master`, the two tile-selection mechanisms conflicted and each
surface
resolved the conflict differently:
- `map.js` / `live.js`: user/server **registry pick won** — an
operator's
`tiles.dark|light` / `map.tiles.darkUrl|lightUrl` was effectively dead
config on those pages
- the legacy roles.js path (nodes page, reach map, rx-coverage,
analytics
minimap): **operator override won**
This PR unifies on **operator-override-wins**, because that is the only
reading that gives live operator config a consistent meaning:
- these keys are still applied today. The deprecation warning says they
would "be ignored in v3.5.0", and v3.5.0 shipped 2026-04-08 — the
instance line is now at v3.16.0 and the keys still take effect, so they
are live configuration, not dead letters. An explicit operator pin
should not be silently defeated by a per-user pick on some pages and
honored on others; whichever way the mechanism eventually goes, it must
behave identically everywhere until it is actually removed.
- user choice is not reduced in the general case: picks remain
authoritative for every provider the registry offers, and overrides
only exist where an operator explicitly wrote a literal URL.
If maintainers would rather have pick-wins (operator URL acts only as a
fallback default), flipping the precedence in `MC_resolveTile` is a
small,
well-tested change — say so in review and it will be reworked.
Related cleanup, out of scope here: the stale "ignored in v3.5.0"
deprecation warning in `cmd/server/config.go` should either be honored
or
reworded now that the project is past v3.16.0.
## No change without operator overrides or picks
## Verification
Unit (all deterministic, `vm`-sandbox based):
- new `tests/unit/test-tile-resolver.js` — 22 cases: light/dark pick
honored,
operator `lightDefault`, disabled-provider fallback, override
precedence,
lazy function-URLs, key-after-async-config, in-place swap without
stacking,
detached-map prune, multi-map single-listener sync, provider maxZoom;
listed in `test-all.sh`
- existing suites green: `test-issue-1420-tile-providers` (47),
`test-issue-1470-node-tile-helper` (6),
`test-issue-1614-tile-url-function`
(3), `test-frontend-helpers` (79), `test-settings-sync`,
`test-packet-filter` (105), `test-aging`
- every one of the 227 suites listed in `test-all.sh`, run individually:
all green except `test-manage-workflow` (2 failures that are local-env
only — CRLF bootstrap artifact — and pass in CI; `sh test-all.sh` aborts
there locally under `set -e`, which is why the suites were run one by
one this time; the scripted pipeline runs fully in CI)
- `eslint` on all six touched files: 0 errors
Browser (headless Chromium against this branch, `/api/config/client`
delayed
~800 ms to force the config race):
- light + `/#/nodes/<key>`: 12 keyless tile requests before config, 12
keyed
re-requests after — no reload, no stacked layer
- light pick `carto-voyager`: inset requests `rastertiles/voyager` from
the
start (parity with the main map)
- theme flip on an open node page: `dark_all` swaps in in place
- dark defaults unchanged (`dark_all`, keyed after config)
The Playwright E2E suite was not run locally — no Go toolchain on the
workstation to serve the backend — CI will cover it.
## Scope / follow-ups (intentionally not here)
- `home.js` mini-map (OSM only) and the geo-filter mini-maps in the
customizers are untouched on purpose: they are outside this bug's path,
and migrating them to `MC_resolveTile` later is mechanical
## Performance
Not a hot path: one registry lookup + string build per map creation and
per
provider/theme-change event (each is rare); no per-packet or per-render
work;
the listener footprint is O(1) app-wide (single shared listener pair + a
pruned registry), so there is no growth across SPA navigations.
Co-authored-by: OpenCode <git-llm@trix.moe>
Co-authored-by: OpenCode:GLM-5.3-Flash <git-llm@trix.moe>
Assisted-by: OpenCode:GLM-5.3-Flash eslint
---------
Co-authored-by: OpenCode <git-llm@trix.moe>