From 7b4b4d4184da7e53d7b5e8d6ef50fc4c9fd48031 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Sat, 14 Nov 2026 16:56:09 -0800 Subject: [PATCH] fix(cyclones): cards leave the map with their storms; null advisory values are left out The world overlay drew on desynchronized 2D contexts. After a frame that only clears, Chrome could present an earlier buffer, so storm cards and forecast lead-hour labels stayed on screen when a snapshot without storms (or an unavailable one) replaced them, although the overlay held no entries and cleared every frame. Both overlay surfaces now use ordinary contexts. The storm readout no longer prints "Unavailable" for a null value: an advisory without pressure shows only its maximum sustained wind, one without wind only its pressure, and one without either has no intensity line. The advisory link stays hidden when an advisory has no link. --- src/i18n/locales/ar.json | 2 ++ src/i18n/locales/de.json | 2 ++ src/i18n/locales/es.json | 2 ++ src/i18n/locales/fr.json | 2 ++ src/i18n/locales/he.json | 2 ++ src/i18n/locales/it.json | 2 ++ src/i18n/locales/ja.json | 2 ++ src/i18n/locales/pt.json | 2 ++ src/i18n/locales/ru.json | 2 ++ src/i18n/locales/sv.json | 2 ++ src/i18n/locales/uk.json | 2 ++ src/i18n/locales/zh-CN.json | 2 ++ src/i18n/locales/zh-Hant.json | 2 ++ src/layers/cyclones/index.js | 29 ++++++++++------ src/layers/cyclones/index.test.mjs | 53 ++++++++++++++++++++++++++++++ src/overlays/worldOverlay.js | 10 +++--- src/overlays/worldOverlay.test.mjs | 26 ++++++++++++++- 17 files changed, 128 insertions(+), 16 deletions(-) diff --git a/src/i18n/locales/ar.json b/src/i18n/locales/ar.json index 14dd5d734..7ccc204e4 100644 --- a/src/i18n/locales/ar.json +++ b/src/i18n/locales/ar.json @@ -1496,6 +1496,8 @@ }, "Position as of {time}": "الموضع عند {time}", "Maximum sustained wind: {wind} · Pressure: {pressure}": "أقصى سرعة للرياح المستمرة: {wind} · الضغط: {pressure}", + "Maximum sustained wind: {wind}": "أقصى سرعة للرياح المستمرة: {wind}", + "Pressure: {pressure}": "الضغط: {pressure}", "{name} · {classification} · Advisory {number} · issued {time}": "{name} · {classification} · النشرة رقم {number} · صدرت {time}", "No active NHC/CPHC systems": "لا توجد أنظمة مدارية نشطة لدى NHC/CPHC", "Advisories unavailable": "النشرات غير متاحة", diff --git a/src/i18n/locales/de.json b/src/i18n/locales/de.json index 096ea616b..b23d680c8 100644 --- a/src/i18n/locales/de.json +++ b/src/i18n/locales/de.json @@ -1432,6 +1432,8 @@ }, "Position as of {time}": "Position, Stand {time}", "Maximum sustained wind: {wind} · Pressure: {pressure}": "Maximaler Dauerwind: {wind} · Luftdruck: {pressure}", + "Maximum sustained wind: {wind}": "Maximaler Dauerwind: {wind}", + "Pressure: {pressure}": "Luftdruck: {pressure}", "{name} · {classification} · Advisory {number} · issued {time}": "{name} · {classification} · Lagebericht {number} · ausgegeben {time}", "No active NHC/CPHC systems": "Keine aktiven NHC/CPHC-Systeme", "Advisories unavailable": "Lageberichte nicht verfügbar", diff --git a/src/i18n/locales/es.json b/src/i18n/locales/es.json index 8d238676f..84b1f477e 100644 --- a/src/i18n/locales/es.json +++ b/src/i18n/locales/es.json @@ -1333,6 +1333,8 @@ }, "Position as of {time}": "Posición a las {time}", "Maximum sustained wind: {wind} · Pressure: {pressure}": "Viento máximo sostenido: {wind} · Presión: {pressure}", + "Maximum sustained wind: {wind}": "Viento máximo sostenido: {wind}", + "Pressure: {pressure}": "Presión: {pressure}", "{name} · {classification} · Advisory {number} · issued {time}": "{name} · {classification} · Aviso {number} · emitido {time}", "No active NHC/CPHC systems": "Sin sistemas activos del NHC/CPHC", "Advisories unavailable": "Avisos no disponibles", diff --git a/src/i18n/locales/fr.json b/src/i18n/locales/fr.json index 5e196c251..773a0f95a 100644 --- a/src/i18n/locales/fr.json +++ b/src/i18n/locales/fr.json @@ -648,6 +648,8 @@ }, "Position as of {time}": "Position au {time}", "Maximum sustained wind: {wind} · Pressure: {pressure}": "Vent maximal soutenu : {wind} · Pression : {pressure}", + "Maximum sustained wind: {wind}": "Vent maximal soutenu : {wind}", + "Pressure: {pressure}": "Pression : {pressure}", "{name} · {classification} · Advisory {number} · issued {time}": "{name} · {classification} · Bulletin {number} · émis le {time}", "No active NHC/CPHC systems": "Aucun système actif NHC/CPHC", "Advisories unavailable": "Bulletins indisponibles", diff --git a/src/i18n/locales/he.json b/src/i18n/locales/he.json index 01403f179..d52265837 100644 --- a/src/i18n/locales/he.json +++ b/src/i18n/locales/he.json @@ -553,6 +553,8 @@ }, "Position as of {time}": "מיקום נכון ל-{time}", "Maximum sustained wind: {wind} · Pressure: {pressure}": "רוח מתמשכת מרבית: {wind} · לחץ: {pressure}", + "Maximum sustained wind: {wind}": "רוח מתמשכת מרבית: {wind}", + "Pressure: {pressure}": "לחץ: {pressure}", "{name} · {classification} · Advisory {number} · issued {time}": "{name} · {classification} · עדכון {number} · פורסם {time}", "No active NHC/CPHC systems": "אין מערכות NHC/CPHC פעילות", "Advisories unavailable": "עדכונים אינם זמינים", diff --git a/src/i18n/locales/it.json b/src/i18n/locales/it.json index ff2139902..7eb03a710 100644 --- a/src/i18n/locales/it.json +++ b/src/i18n/locales/it.json @@ -648,6 +648,8 @@ }, "Position as of {time}": "Posizione aggiornata al {time}", "Maximum sustained wind: {wind} · Pressure: {pressure}": "Vento massimo sostenuto: {wind} · Pressione: {pressure}", + "Maximum sustained wind: {wind}": "Vento massimo sostenuto: {wind}", + "Pressure: {pressure}": "Pressione: {pressure}", "{name} · {classification} · Advisory {number} · issued {time}": "{name} · {classification} · Bollettino {number} · emesso {time}", "No active NHC/CPHC systems": "Nessun sistema NHC/CPHC attivo", "Advisories unavailable": "Bollettini non disponibili", diff --git a/src/i18n/locales/ja.json b/src/i18n/locales/ja.json index b99f6e1f4..fe108d6a8 100644 --- a/src/i18n/locales/ja.json +++ b/src/i18n/locales/ja.json @@ -626,6 +626,8 @@ }, "Position as of {time}": "{time}時点の位置", "Maximum sustained wind: {wind} · Pressure: {pressure}": "最大持続風速:{wind} · 気圧:{pressure}", + "Maximum sustained wind: {wind}": "最大持続風速:{wind}", + "Pressure: {pressure}": "気圧:{pressure}", "{name} · {classification} · Advisory {number} · issued {time}": "{name} · {classification} · 第{number}報 · {time}発表", "No active NHC/CPHC systems": "NHC/CPHCが監視中のサイクロンはありません", "Advisories unavailable": "サイクロン情報を取得できません", diff --git a/src/i18n/locales/pt.json b/src/i18n/locales/pt.json index 1d5fb18ac..ddceca56d 100644 --- a/src/i18n/locales/pt.json +++ b/src/i18n/locales/pt.json @@ -648,6 +648,8 @@ }, "Position as of {time}": "Posição em {time}", "Maximum sustained wind: {wind} · Pressure: {pressure}": "Vento máximo sustentado: {wind} · Pressão: {pressure}", + "Maximum sustained wind: {wind}": "Vento máximo sustentado: {wind}", + "Pressure: {pressure}": "Pressão: {pressure}", "{name} · {classification} · Advisory {number} · issued {time}": "{name} · {classification} · Boletim {number} · emitido em {time}", "No active NHC/CPHC systems": "Nenhum sistema ativo do NHC/CPHC", "Advisories unavailable": "Boletins indisponíveis", diff --git a/src/i18n/locales/ru.json b/src/i18n/locales/ru.json index 38ef39931..69da590fc 100644 --- a/src/i18n/locales/ru.json +++ b/src/i18n/locales/ru.json @@ -1355,6 +1355,8 @@ }, "Position as of {time}": "Положение на {time}", "Maximum sustained wind: {wind} · Pressure: {pressure}": "Макс. устойчивый ветер: {wind} · Давление: {pressure}", + "Maximum sustained wind: {wind}": "Макс. устойчивый ветер: {wind}", + "Pressure: {pressure}": "Давление: {pressure}", "{name} · {classification} · Advisory {number} · issued {time}": "{name} · {classification} · Сводка № {number} · выпущена {time}", "No active NHC/CPHC systems": "Нет активных систем NHC/CPHC", "Advisories unavailable": "Сводки недоступны", diff --git a/src/i18n/locales/sv.json b/src/i18n/locales/sv.json index 481db3abb..d82929d9d 100644 --- a/src/i18n/locales/sv.json +++ b/src/i18n/locales/sv.json @@ -1354,6 +1354,8 @@ }, "Position as of {time}": "Position per {time}", "Maximum sustained wind: {wind} · Pressure: {pressure}": "Högsta medelvind: {wind} · Lufttryck: {pressure}", + "Maximum sustained wind: {wind}": "Högsta medelvind: {wind}", + "Pressure: {pressure}": "Lufttryck: {pressure}", "{name} · {classification} · Advisory {number} · issued {time}": "{name} · {classification} · Bulletin {number} · utfärdad {time}", "No active NHC/CPHC systems": "Inga aktiva NHC/CPHC-system", "Advisories unavailable": "Bulletiner otillgängliga", diff --git a/src/i18n/locales/uk.json b/src/i18n/locales/uk.json index d7687ce4d..c3f36b4e6 100644 --- a/src/i18n/locales/uk.json +++ b/src/i18n/locales/uk.json @@ -659,6 +659,8 @@ }, "Position as of {time}": "Положення на {time}", "Maximum sustained wind: {wind} · Pressure: {pressure}": "Макс. середня швидкість вітру: {wind} · Тиск: {pressure}", + "Maximum sustained wind: {wind}": "Макс. середня швидкість вітру: {wind}", + "Pressure: {pressure}": "Тиск: {pressure}", "{name} · {classification} · Advisory {number} · issued {time}": "{name} · {classification} · Зведення № {number} · випущено {time}", "No active NHC/CPHC systems": "Немає активних систем NHC/CPHC", "Advisories unavailable": "Зведення недоступні", diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.json index fdcd260b6..72ee79dd9 100644 --- a/src/i18n/locales/zh-CN.json +++ b/src/i18n/locales/zh-CN.json @@ -625,6 +625,8 @@ }, "Position as of {time}": "位置(截至 {time})", "Maximum sustained wind: {wind} · Pressure: {pressure}": "最大持续风速:{wind} · 气压:{pressure}", + "Maximum sustained wind: {wind}": "最大持续风速:{wind}", + "Pressure: {pressure}": "气压:{pressure}", "{name} · {classification} · Advisory {number} · issued {time}": "{name} · {classification} · 第 {number} 号公告 · 发布于 {time}", "No active NHC/CPHC systems": "当前没有活跃的 NHC/CPHC 气旋", "Advisories unavailable": "公告不可用", diff --git a/src/i18n/locales/zh-Hant.json b/src/i18n/locales/zh-Hant.json index 2257cf861..4b3a467a4 100644 --- a/src/i18n/locales/zh-Hant.json +++ b/src/i18n/locales/zh-Hant.json @@ -624,6 +624,8 @@ }, "Position as of {time}": "位置(截至 {time})", "Maximum sustained wind: {wind} · Pressure: {pressure}": "最大持續風速:{wind} · 氣壓:{pressure}", + "Maximum sustained wind: {wind}": "最大持續風速:{wind}", + "Pressure: {pressure}": "氣壓:{pressure}", "{name} · {classification} · Advisory {number} · issued {time}": "{name} · {classification} · 第 {number} 號公告 · 發布於 {time}", "No active NHC/CPHC systems": "當前沒有活躍的 NHC/CPHC 氣旋", "Advisories unavailable": "公告不可用", diff --git a/src/layers/cyclones/index.js b/src/layers/cyclones/index.js index 55449ba94..02c3b5cad 100644 --- a/src/layers/cyclones/index.js +++ b/src/layers/cyclones/index.js @@ -59,8 +59,22 @@ const classificationName = (code) => Object.hasOwn(CLASSIFICATION_NAMES, code) ? t(CLASSIFICATION_NAMES[code]) : code; -const number = (value, unit) => - value === null ? t('Unavailable') : formatQuantity(value, unit); +// A value the advisory leaves out (null) is left out of the line too. +const intensityText = (storm) => { + const has = (value) => value !== null && value !== undefined; + const wind = has(storm.windKt) ? formatQuantity(storm.windKt, 'kt') : null; + const pressure = has(storm.pressureHpa) + ? formatQuantity(storm.pressureHpa, 'hPa') + : null; + if (wind && pressure) + return t('Maximum sustained wind: {wind} · Pressure: {pressure}', { + wind, + pressure, + }); + if (wind) return t('Maximum sustained wind: {wind}', { wind }); + if (pressure) return t('Pressure: {pressure}', { pressure }); + return ''; +}; /** Advisory status and coherent forecast geometry; selected through the shared row list. */ export function createCyclonesLayer({ @@ -424,12 +438,7 @@ export function createCyclonesLayer({ const position = storm ? t('Position as of {time}', { time: utc(storm.positionAt) }) : ''; - const intensity = storm - ? t('Maximum sustained wind: {wind} · Pressure: {pressure}', { - wind: number(storm.windKt, 'kt'), - pressure: number(storm.pressureHpa, 'hPa'), - }) - : ''; + const intensity = storm ? intensityText(storm) : ''; const detail = storm ? t('{name} · {classification} · Advisory {number} · issued {time}', { name: storm.name, @@ -479,7 +488,7 @@ export function createCyclonesLayer({ text: intensity, }, { id: 'geometry', text: geometry, muted: true }, - ] + ].filter((line) => line.text) : [], detail, status, @@ -511,7 +520,7 @@ export function createCyclonesLayer({ ] : [], info: storm - ? `${detail}\n${position}\n${intensity}\n${geometry}${status && status !== geometry ? '\n' + status : ''}\n${coverageText(snapshot.coverage)}` + ? `${detail}\n${position}\n${intensity ? intensity + '\n' : ''}${geometry}${status && status !== geometry ? '\n' + status : ''}\n${coverageText(snapshot.coverage)}` : `${detail}${status ? '\n' + status : ''}\n${coverageText(snapshot?.coverage)}`, infoTitle: t( 'Select a storm on the map, or choose a storm in the list to select it and move the camera. Click empty map space to clear the selection. NOAA NHC/CPHC advisory context. The cone describes forecast center-track uncertainty, not storm size or the full hazard area. Forecast point labels are source lead hours, not times computed from advisory issuance. Geometry follows the surface; height is not weather altitude. Consult the official advisory.', diff --git a/src/layers/cyclones/index.test.mjs b/src/layers/cyclones/index.test.mjs index 6238eac50..a053531dc 100644 --- a/src/layers/cyclones/index.test.mjs +++ b/src/layers/cyclones/index.test.mjs @@ -824,6 +824,59 @@ test('classification display expands known codes without altering the source or } } }); +// Quantities join number and unit with a no-break space. +const plain = (text) => text?.replace(/\u00a0/g, ' ') ?? null; +test('an advisory without pressure, movement or link leaves those values out', async () => { + const record = { + ...storm(), + windKt: 85, + pressureHpa: null, + movement: { directionDegrees: null, speedKt: null }, + advisoryUrl: null, + }; + const h = harness({ getSnapshot: async () => snapshot([record]) }); + try { + h.layer.enable(); + await h.layer.update(); + const { summary, info } = h.layer.getRowControls(); + const intensity = summary.lines.find((line) => line.id === 'intensity'); + assert.equal(plain(intensity.text), 'Maximum sustained wind: 85 kt'); + assert.deepEqual( + summary.lines.map((line) => line.id), + ['position', 'intensity', 'geometry'], + ); + assert.deepEqual(summary.actions, [], 'no advisory link to open'); + assert.ok(plain(info).includes('Maximum sustained wind: 85 kt\n')); + for (const text of [info, ...summary.lines.map((line) => line.text)]) + assert.doesNotMatch(text, /Unavailable|Pressure/); + } finally { + h.layer.destroy(); + } +}); +test('an advisory with only one of wind and pressure shows that one alone', async () => { + for (const [values, expected] of [ + [{ windKt: null, pressureHpa: 990 }, 'Pressure: 990 hPa'], + [ + { windKt: 60, pressureHpa: 990 }, + 'Maximum sustained wind: 60 kt · Pressure: 990 hPa', + ], + [{ windKt: null, pressureHpa: null }, null], + ]) { + const h = harness({ + getSnapshot: async () => snapshot([{ ...storm(), ...values }]), + }); + try { + h.layer.enable(); + await h.layer.update(); + const { summary, info } = h.layer.getRowControls(); + const intensity = summary.lines.find((line) => line.id === 'intensity'); + assert.equal(plain(intensity?.text), expected); + assert.doesNotMatch(info, /Unavailable|\n\n/); + } finally { + h.layer.destroy(); + } + } +}); test('advisory selection uses accessible row descriptors and shared camera handoff', async () => { const h = harness( { getSnapshot: async () => snapshot([storm(), storm('ep162026')]) }, diff --git a/src/overlays/worldOverlay.js b/src/overlays/worldOverlay.js index e65d45e93..d0dc9698b 100644 --- a/src/overlays/worldOverlay.js +++ b/src/overlays/worldOverlay.js @@ -1307,11 +1307,11 @@ function ensureOverlayDom() { // ignored. if (!_actions) presentActions({ owner: {}, items: [], status: '', announced: 0 }); - _ctx = _canvas.getContext('2d', { alpha: true, desynchronized: true }); - _detectionCtx = _detectionSurface.getContext('2d', { - alpha: true, - desynchronized: true, - }); + // Synchronized contexts: on a desynchronized one Chrome can present an + // earlier buffer after a frame that only clears, so cards that left stay + // on screen until something paints over them. + _ctx = _canvas.getContext('2d', { alpha: true }); + _detectionCtx = _detectionSurface.getContext('2d', { alpha: true }); } function sizeCanvasSurface(canvas, ctx, width, height, dpr) { diff --git a/src/overlays/worldOverlay.test.mjs b/src/overlays/worldOverlay.test.mjs index 8765e7e83..4b27e73ae 100644 --- a/src/overlays/worldOverlay.test.mjs +++ b/src/overlays/worldOverlay.test.mjs @@ -110,6 +110,7 @@ function installMockEnvironment({ } = {}) { const byId = new Map(); const paintTrace = []; + const contextRequests = []; const ctx = mockContext('shared', paintTrace); const detectionCtx = mockContext('detection', paintTrace); const layoutReads = { canvasWidth: 0, canvasHeight: 0, boundingClientRect: 0 }; @@ -184,8 +185,9 @@ function installMockEnvironment({ return this._rect; } - getContext() { + getContext(type, options) { if (this.tagName !== 'CANVAS') return null; + contextRequests.push({ id: this.id, type, options }); return this.id === 'world-overlay-detection-surface' ? detectionCtx : ctx; } @@ -400,6 +402,7 @@ function installMockEnvironment({ ctx, detectionCtx, paintTrace, + contextRequests, document, window, postRender, @@ -2623,3 +2626,24 @@ test('the queued-card index stays bounded while card identities churn', () => { env.cleanup(); } }); + +test('both overlay surfaces draw on synchronized 2D contexts', () => { + // A desynchronized context can show an earlier buffer after a frame that + // only clears: a card removed from its source stayed on screen until + // something painted over it. + const env = installMockEnvironment(); + try { + initWorldOverlay(env.viewer); + const ids = env.contextRequests.map((request) => request.id).sort(); + assert.deepEqual(ids, [ + 'world-overlay-canvas', + 'world-overlay-detection-surface', + ]); + for (const request of env.contextRequests) { + assert.equal(request.type, '2d'); + assert.notEqual(request.options?.desynchronized, true, request.id); + } + } finally { + env.cleanup(); + } +});