Repository navigation
feat(region-filter): honor ?region= in the URL on every page (#2255) - #2256
Conversation
Only the packets page read ?region= from the hash, with its own one-off code. Live, nodes, observers, channels, analytics and scope audit ignored it, so a link like #/live?region=SJC opened with whatever region the visitor last picked. RegionFilter now applies the param itself. It overrides the saved selection and is saved like a click in the control, as packets did. On a fresh load it's applied when region-filter.js runs, before any page reads the selection (live fetches nodes before calling init). On in-app navigation init() applies it and, if that changed the selection, notifies listeners once regions load, so a page that already fetched reloads. Unknown codes are dropped by the existing cleanup in fetchRegions(). packets.js drops its own ?region= handling, and now removes its region and area listeners in destroy(). They outlived the page, so after visiting packets a region change on any other page reloaded packets and replaceState'd the URL to #/packets.
efiten
left a comment
There was a problem hiding this comment.
Thanks, this fixes #2255 the way the issue describes. The packets cleanup also stops packets reloading and rewriting the URL from other pages.
Checked on 477dc531:
test-region-filter-url-param.js(14/14),test-region-filter-setselected.js(4/4) andtest-issue-2012-clear-filters-selection.jspass.- CI is green.
- The
RegionFilter.onChangelisteners on the other pages (analytics, channels, live, nodes, observers, scope audit) already keep a handle and remove it indestroy(), so packets was the only one left over.
One change before merge:
1. Unknown codes are only dropped on the first init() of a page load. fetchRegions() returns early once _loaded is set (region-filter.js:48), so on in-app navigation applyUrlRegion() keeps codes that are not configured. I ran region-filter.js from this branch in a vm context with regions SJC and SFO:
init()on#/packets, then hash#/nodes?region=XXXandinit()again:getSelected()is['XXX'],regionQueryString()is®ion=XXX, and["XXX"]is saved tolocalStorage.- The same with
region=SJC,XXX:regionQueryString()is®ion=SJC%2CXXX.
On a fresh load the existing cleanup does drop them, which is what the unknown-codes test covers. Could applyUrlRegion() keep only the codes in _regions when _loaded is true, with a test for the in-app case? The PR body line "Unknown codes are dropped by the existing cleanup" would then hold for both paths.
One question, not blocking:
2. Two loads on in-app navigation to a page that fetches after init(). From reading the code (not measured in a browser): nodes calls loadNodes() in its init (nodes.js:584), and analytics calls loadAnalytics() (analytics.js:307). Both already use the new selection, because applyUrlRegion() runs before the await. The notify after fetchRegions() then runs their listener, which loads again. For nodes that is a second full paginated /api/nodes fetch, because the listener clears _allNodes. Only live needs the notify, because it fetches before init(). This only happens when a link inside the app changes the region, not on the directory links from #2255. Which do you prefer:
- (a) leave it as is,
- (b) move live's
RegionFilter.init()before its firstloadNodes()and drop the notify, or - (c) something else you had in mind?
fetchRegions() only cleans the selection on its first call, so after regions had loaded, applyUrlRegion() kept codes that aren't configured. Filter them against the loaded regions; with none left, that's all regions, the same as the cleanup on a fresh load. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for checking this so carefully. 1. Fixed in 9c2ea45. Once regions have loaded, 2. I'd prefer (a) for this PR. Only in-app links that change the region trigger the second load. Doing (b) means moving live's |
efiten
left a comment
There was a problem hiding this comment.
Checked 9c2ea45a: applyUrlRegion() now drops unknown codes once regions have loaded. The url-param tests pass 16/16, and with the filter line reverted both new in-app tests fail. (a) for point 2 is fine, a follow-up issue for it is welcome. Thanks.
Fixes #2255.
Only the packets page read
?region=from the hash, with its own one-off code. Live, nodes, observers, channels, analytics and scope audit ignored it, so a link like this opened with whatever region the visitor last picked:We link into our instance from a community directory (one link per region), and wanted those links to land on the live map or node list already filtered, not only on packets.
What changes
public/region-filter.js?region=(comma-separated, trimmed) overrides the saved selection and is saved like a click in the control, the same as packets did throughsetSelected().RegionFilter.init().init()applies it before itsawait, so a page that loads afterinit()uses it. If it changed the selection, listeners are told once regions load, so a page that already fetched (live) reloads instead of showing the old region's data under the new region's label.fetchRegions(). No param, or an empty one, leaves the saved selection alone.public/packets.js_pendingUrlRegionhandling;RegionFiltercovers it.destroy(). They were registered without a handle and outlived the page: after visiting packets, a region change on any other page reloaded packets andreplaceState'd the URL to#/packets?...while you were on another page. That already happened with the dropdown on master; the in-app notify above would make it happen on every region link.Tests
tests/unit/test-region-filter-url-param.js, 14 assertions:init()is called, andinit()doesn't notifylocalStoragedestroy()With
region-filter.jsfrom master, 5 of the first 8 assertions fail.How I checked:
test-all.shsuites all pass excepttest-issue-1956-release-routing.jsandtest-preflight-xss-gate.js. Both also fail on unmodified master on macOS: they shell out to bash-4 features (mapfile, and a syntax error incheck-xss-sinks.shunder bash 3.2).eslint@8.57.1on the two files: 0 errors, 3 warnings, the same as master.public/locally with/apiproxied to a live instance and checked the requests each page made:#/nodes?region=AUS,#/live?region=DFW,#/packets?region=HOU: the first request carries the URL's region and the dropdown shows it#/live?region=DFW: live fetches with the old region, then reloads with DFW; the dropdown shows DFW#/nodes?region=AUS: no packets requests, and the URL stays on#/nodesI couldn't run the Playwright E2E suite locally (no Go toolchain on this machine).