Skip to content

LiveReload EventSource.onerror reload breaks frontend navigation in Firefox #42

@gebeer

Description

@gebeer

Hi Bernhard,

we ran into a Firefox-specific issue with RockFrontend LiveReload in a local DDEV / ProcessWire setup.

Observed behavior:

  • only when logged in as a superuser/admin, because LiveReload is injected in that context
  • in Firefox, navigating from one frontend page to another can appear to jump back to the previous page after about 1.5s
  • example:
    • start on /video-courses/
    • navigate to /online-shop/
    • /online-shop/ loads
    • shortly after, /video-courses/ is loaded again
  • Chromium did not show this behavior in the same environment
  • Tracy showed no HTTP redirect, because this is client-side, not a server redirect

Firefox console output:

  • The connection to https://.../?rockfrontend-livereload=... was interrupted while the page was loading.
  • Error occurred in EventSource, reloading window.

Root cause:

  • in livereload.js, evtSource.onerror triggers window.location.reload() after 1500ms
  • Firefox seems to interrupt or reconnect the SSE request more aggressively during navigation
  • that turns a transient LiveReload stream error into a full page reload, which makes normal navigation look broken

There is also a second fragility:

  • in LiveReload::validSecret(), the secret is deleted on first successful validation
  • if the SSE request reconnects, the reconnect can fail because the token is effectively one-shot

What fixed it for us locally:

  1. change livereload.js so onerror retries the stream instead of reloading the whole page
  2. keep the LiveReload secret valid for its cache lifetime instead of deleting it on first successful validation

Why this seems reasonable:

  • a dropped SSE connection should not force a page reload
  • EventSource already has reconnect semantics
  • retrying the stream keeps LiveReload working without breaking navigation
  • keeping the secret valid for its TTL makes reconnects less brittle

If this sounds reasonable, we can prepare a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions