Skip to content

fix(clustermap): stop EventSource reload from hijacking navigation in Firefox#24

Merged
FreekBes merged 1 commit into
codam-coding-college:masterfrom
CheapFuck:fix/firefox-clustermap-navigation
Jun 9, 2026
Merged

fix(clustermap): stop EventSource reload from hijacking navigation in Firefox#24
FreekBes merged 1 commit into
codam-coding-college:masterfrom
CheapFuck:fix/firefox-clustermap-navigation

Conversation

@CheapFuck

Copy link
Copy Markdown
Contributor

Problem

On Firefox, while on the live clustermap page, navigating away is broken:

  • Typing a different URL (e.g. nu.nl) and pressing enter snaps back to the clustermap instead of navigating.
  • Clicking external links such as the CONTRIBUTE link (to GitHub) appears to "just refresh" the page.

This does not reproduce on Chromium-based browsers.

Cause

static/js/clustermaps/live.js opens a Server-Sent Events stream (EventSource) and its error handler calls window.location.reload() unconditionally.

When the page starts unloading during navigation, Firefox tears down the SSE connection and dispatches an error event. The handler then reloads the page, cancelling the in-progress navigation and returning the user to the clustermap. Chromium does not dispatch this error during unload, so the bug is Firefox-only.

Fix

  • Add a pagehide / beforeunload flag (isUnloading) so the reload never fights the browser's own navigation.
  • Only reload on a permanent failure (readyState === EventSource.CLOSED) instead of on every transient error, letting EventSource perform its normal automatic reconnection.
  • Apply the same unload guard to the close handler.

Testing

  • Firefox: from /clustermap/live, navigate to an external URL and click the CONTRIBUTE link — both now work as expected.
  • Confirmed live location updates still stream and recover after a dropped connection.

… Firefox

The live clustermap's EventSource error handler called window.location.reload()
unconditionally. In Firefox, navigating away (or clicking external links such as
CONTRIBUTE) tears down the SSE connection during page unload and dispatches an
'error' event, so the handler reloaded the page and cancelled the navigation,
snapping the user back to the clustermap.

Guard the reload with a pagehide/beforeunload flag so it never fights the
browser's own navigation, and only reload on a permanent failure
(readyState === CLOSED) instead of on every transient error, letting
EventSource perform its normal automatic reconnection.

@FreekBes FreekBes left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@FreekBes FreekBes merged commit eb62a7a into codam-coding-college:master Jun 9, 2026
1 check passed
@Codam-IT

Codam-IT commented Jun 9, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 2.3.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@FreekBes FreekBes added the bug Something isn't working label Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants