Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 0 additions & 42 deletions web/deferredredraw.js

This file was deleted.

85 changes: 0 additions & 85 deletions web/deferredredraw.test.js

This file was deleted.

66 changes: 35 additions & 31 deletions web/e2e/ui.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,54 +496,58 @@ test('the site is installable: manifest is linked and valid, no service worker (
expect(regs).toHaveLength(0)
})

// #271: every redraw path clears its layer, and removing a marker closes its
// popup — so a name resolving in the background used to shut a popup the user
// had just opened. The redraw is held until the popup closes.
test('an open popup survives a name-resolution redraw, and the redraw still happens after', async ({ page }) => {
await page.route('**/api/observer-points*', (route) => {
const src = new URL(route.request().url()).searchParams.get('src')
const pts = src === 'rxlog'
? [{ lat: 51, lon: 4, rssi: -100, snr: -5, heard_key: '1d6f', src: 'rxlog', observer: 'Erwin Mobile', rx_at: '2026-06-30T15:00:00Z' }]
: []
route.fulfill({ json: { points: pts } })
})
// #271 held name-resolution redraws while a popup was open, because on
// Leaflet removing a marker closed its popup. On MapLibre the popup is not tied
// to a feature and a redraw only replaces source data, so the hold went (#763).
// What is left to guard: the redraw runs while the popup is open, and the
// popup stays.
test('a name-resolution redraw runs under an open popup and leaves it open', async ({ page }) => {
const sender = 'ab'.repeat(32)
await page.route('**/api/points*', (r) => r.fulfill({ json: { points: [{
lat: 51, lon: 4, rssi: -90, snr: -8, sender_id: sender, sender_kind: 'advert_pubkey', sender_label: '',
hunter_pubkey: 'h1', hunter_name: 'Hunter 1', channel_name: '', packet_type: 'Advert', hops: 0,
rx_at: new Date(Date.now() - 3600000).toISOString(),
}] } }))
// Map draws page /api/points by 5000; the ticker asks with its own limit.
// A range that has already ended is not live, so neither the range refresh
// nor the ticker poll runs: a map draw after the name lands is that redraw
// and no other.
let mapDraws = 0
page.on('request', (r) => { if (r.url().includes('/api/points') && r.url().includes('limit=5000')) mapDraws++ })
// The resolver answers only when the test lets it (#761), so the popup is
// open and waiting when the name lands. A fixed delay raced everything the
// test does before the click, and lost under load.
// open before the name lands.
let release
const gate = new Promise((res) => { release = res })
await page.route('**/api/resolve*', async (r) => {
await gate
r.fulfill({ json: { name: 'BE-HSS-DinX', ambiguous: false } })
r.fulfill({ json: { name: 'Named Node', ambiguous: false } })
})
await page.goto('/')
await setNodePos(page, 'positions')
await expect.poll(() => page.evaluate(() => window.__featureCount('observer-rxlog')), { timeout: 10000 }).toBe(1)
const local = (d) => new Date(d.getTime() - d.getTimezoneOffset() * 60000).toISOString().slice(0, 16)
const from = local(new Date(Date.now() - 86400000)), to = local(new Date(Date.now() - 120000))
await page.goto(`/?mode=points&lat=51&lon=4&z=15&from=${from}&to=${to}`)
await expect.poll(() => page.evaluate(() => window.__featureCount('points')), { timeout: 10000 }).toBe(1)
await mapSettled(page)

// Open the popup while the lookup is still in flight. Pinned as "not yet
// resolved", not merely "contains the id": the id line is present either
// way, so on a slow machine the redraw could already have happened and every
// later assertion would pass for the wrong reason.
const popup = page.locator('.maplibregl-popup:not(.ch-hover)')
await expect(async () => {
await clickMapAt(page, 51, 4)
await expect(page.locator('.maplibregl-popup-content')).toContainText('relay 1d6f', { timeout: 1000 })
await expect(popup).toBeVisible({ timeout: 1000 })
}).toPass()
await expect(page.locator('.maplibregl-popup-content')).not.toContainText('BE-HSS-DinX')
await expect(popup).not.toContainText('Named Node')

// Let the name land. The popup is still there afterwards: this is the
// regression.
const answered = page.waitForResponse((r) => r.url().includes('/api/resolve'))
// The name lands and the layer redraws: a fresh map draw proves the redraw
// ran, rather than waiting a fixed time and hoping it did.
const before = mapDraws
release()
await answered
await page.waitForTimeout(600)
await expect(page.locator('.maplibregl-popup-content')).toBeVisible()
await expect.poll(() => mapDraws, { timeout: 10000 }).toBeGreaterThan(before)
await expect(popup).toBeVisible()

// ...and the held redraw runs on close, so the name is not lost either.
// The name is there for the next popup (read from the resolver cache when
// it opens; the redraw is proved by the draw counter above).
await page.locator('.maplibregl-popup-close-button').click()
await expect(async () => {
await clickMapAt(page, 51, 4)
await expect(page.locator('.maplibregl-popup-content')).toContainText('BE-HSS-DinX', { timeout: 1000 })
await expect(popup).toContainText('Named Node', { timeout: 1000 })
}).toPass({ timeout: 10000 })
})

Expand Down
46 changes: 11 additions & 35 deletions web/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { unclutteredLabels, createLabelMeasurer, screenObstacles } from './nodel
import { fetchPointsPaged } from './pagedpoints.js'
import { windowKey, createWindowCache } from './windowpoints.js'
import { latestWins } from './latestwins.js'
import { deferWhile } from './deferredredraw.js'
import * as urlstate from './urlstate.js'
import { startBarWatch, onBarChange } from './barwatch.js'
import { initAuthBar } from './login.js'
Expand Down Expand Up @@ -134,22 +133,6 @@ const csRelayLayer = 'observer-rxlog'
// this covers what is drawn from the current state rather than a fetch.
wm.onOverlaysReady(() => { refresh() })

// A name-resolution redraw clears its layer, and removing a marker closes its
// popup — so a popup opened just before a background lookup finished would
// vanish under the cursor (#271). Hold those redraws while a popup is open and
// run the last one when it closes. Only automatic redraws go through this: a
// redraw the user asked for (filter, pan, layer toggle) closing a popup is
// expected behaviour.
let popupOpen = false
const nameRedraw = deferWhile(() => popupOpen)
wm.onPopup((open) => {
popupOpen = open
// Deferred a tick, and flush() re-checks: opening a popup from another
// closes the first one before the next is open, so a synchronous flush on
// close would clear the layer out from under it — this bug, one
// interaction later.
if (!open) setTimeout(() => nameRedraw.flush(), 0)
})
// Target-list picker (#223), created near the end of this file once its DOM
// exists; refreshPickerCandidates() (called from refresh()) feeds it on every
// redraw in all modes, guarded since it's still null during the handful of
Expand Down Expand Up @@ -413,10 +396,11 @@ async function drawPoints() {
const cover = { truncated: capped, coversFrom: oldestRxAt(points) }
setStatus(coverageLabel(points.length, 'points', cover) + ignoreSuffix(), coverageTitle(POINTS_CAP, cover))
// Look up unknown full-pubkey senders once each; redraw if any resolved to a
// name — but not out from under an open popup (#271).
// name. An open popup stays open: since MapLibre (#763) a redraw replaces
// source data and never closes it.
if (unresolved.size) {
Promise.all([...unresolved].map((k) => resolveName(k))).then((names) => {
if (names.some((n) => n)) nameRedraw.run('points', () => refresh())
if (names.some((n) => n)) refresh()
})
}
}
Expand Down Expand Up @@ -773,7 +757,7 @@ function renderPickerRows(points) {
targetPicker.render(points, Date.now())
if (!misses.size) return
Promise.all([...misses].map((k) => resolveName(k))).then((names) => {
if (names.some((n) => n)) nameRedraw.run('picker', () => renderPickerRows(points))
if (names.some((n) => n)) renderPickerRows(points)
})
}

Expand Down Expand Up @@ -1306,16 +1290,9 @@ async function drawObserverPoints(src, layer, ring) {
if (unresolved.size) {
Promise.all([...unresolved].map((k) => resolveName(k))).then((names) => {
// Same guard as above: don't redraw for a layer that's been switched off
// (or gone into Locate focus) while the names were resolving. The guard
// moved inside the callback because the redraw can now be held until a
// popup closes (#271) — by then, either may have changed.
// (or gone into Locate focus) while the names were resolving.
if (!names.some((n) => n)) return
// Keyed per source: the advert and relay layers redraw independently and
// are never redrawn by a pan or a filter change, so sharing one slot
// would drop one of them silently rather than defer it.
nameRedraw.run(`cs:${src}`, () => {
if (csOn.checked && !locateActive) drawObserverPoints(src, layer, ring)
})
if (csOn.checked && !locateActive) drawObserverPoints(src, layer, ring)
})
}
}
Expand Down Expand Up @@ -1427,12 +1404,11 @@ function nodePosPopup(name, id, p, est, { reachOn = false, selected = false, hea
// trigger one). Without this the later pass clears the layer and both then add their
// markers, leaving duplicates behind.
let nodePosGen = 0
// Signature of what is currently drawn. Rebuilding the layer destroys every
// marker, which silently closes any popup the user has open — and this layer
// redraws on each refresh (pan, zoom, filter change, the name-resolution
// pass), so an unguarded rebuild can yank a popup away mid-read. Skip the
// rebuild when the rendered content is identical, mirroring targetlist.js's
// _lastSig guard in the app.
// Signature of what is currently drawn. This layer redraws on each refresh
// (pan, zoom, filter change, the name-resolution pass), so the rebuild is
// skipped when the rendered content is identical, mirroring targetlist.js's
// _lastSig guard in the app. It no longer guards an open popup: on MapLibre a
// redraw leaves it open (#763).
let nodePosSig = null
// The repeater whose popup comes back after a selecting press or tap (#623).
// A selection redraws the node layer, so the popup is reopened with the
Expand Down
16 changes: 7 additions & 9 deletions web/mapcore.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,19 +419,17 @@ export function createWebMap(containerId, { center, zoom, theme = 'dark', mode =
}

// ---- popups ----
// One open popup at a time, as on Leaflet: opening another closes it, and
// the 'open'/'close' events reach map.js so a name-resolution redraw can be
// held while a popup is under the cursor (#271).
// One open popup at a time, as on Leaflet: opening another closes it. It is
// not tied to a feature, so a redraw (setData) leaves it open (#763).
let popup = null
const popupCbs = []
function closePopup() { if (popup) { const p = popup; popup = null; p.remove() } }
function openPopup(lngLat, html, { closeButton = true, closeOnClick = true, className = '' } = {}) {
closePopup()
popup = new maplibregl.Popup({ closeButton, closeOnClick, maxWidth: '280px', className })
const p = new maplibregl.Popup({ closeButton, closeOnClick, maxWidth: '280px', className })
.setLngLat(lngLat).setHTML(html).addTo(map)
for (const cb of popupCbs) cb(true)
popup.on('close', () => { if (popup) { popup = null; for (const cb of popupCbs) cb(false) } })
return popup
popup = p
p.on('close', () => { if (popup === p) popup = null })
return p
}
// A hover line for the hex cells: MapLibre has no tooltip, so it is a small
// closeless popup that follows the pointer and goes on mouseleave.
Expand Down Expand Up @@ -552,7 +550,7 @@ export function createWebMap(containerId, { center, zoom, theme = 'dark', mode =
onOverlaysReady(cb) { readyCbs.push(cb); if (overlaysReady) cb() },
isReady() { return overlaysReady },
setData, setHeat, syncSize, setHexSizes,
openPopup, closePopup, onPopup(cb) { popupCbs.push(cb) }, hoverText, onLayerClick, onEmptyClick, onGlyphTap,
openPopup, closePopup, hoverText, onLayerClick, onEmptyClick, onGlyphTap,
// Test hook (#632): where a glyph paints, in page px, for a real click on it.
glyphPagePoint(key, kind) {
const src = kind === 'advert' ? NODE_GLYPH_SOURCE : NODE_DOT_SOURCE
Expand Down
Loading