Skip to content

Flaky: router-js-handled positive-control test escapes interception on Firefox #1053

Description

@vivek7405

Problem

The Browser CI job failed once on PR #1052 (run 29947749350) with Tests were interrupted because the page navigated to http://localhost:8000/plain-link-target (failed on Firefox). The failing test is the positive control in packages/core/test/routing/browser/router-js-handled.test.js (~L74): it renders <a href="/plain-link-target">, clicks it, and expects the client router to intercept and fetch. On Firefox the click occasionally escapes interception and performs a REAL navigation, which aborts the whole web-test-runner session (every remaining test in the file is lost, the job reds).

Flake evidence: the identical check passed on the same PR's previous commit and passed on a plain rerun of the same head SHA (3878df7); the PR's diff (a mergeHead meta guard + a dev-only console warn) does not touch anchor interception.

Design / approach

Likely a startup race: the test clicks before the router's document-level click listener is effectively active in Firefox, or the stubbed window.fetch swap races. Two directions, pick whichever proves stable: (a) make the test deterministic, await a signal that enableClientRouter()'s listener is installed (or dispatch a synthetic cancelable click first and assert defaultPrevented) before the real click; (b) make the escape non-destructive, give the anchor a target the runner tolerates or intercept beforeunload in the test so a missed interception fails THAT test with a clear assertion instead of killing the session. The current failure mode (whole session interrupted) is the worst outcome because it hides which expectation actually failed.

Implementation notes (for the implementing agent)

  • Where: packages/core/test/routing/browser/router-js-handled.test.js ~L74-82 (the positive control test). The suite's setup() calls enableClientRouter(); the router adds its click listener at module import / enable (see packages/core/src/router-client.js enableClientRouter).
  • Landmines: enableClientRouter() is idempotent across tests in one page session; the listener may already exist from an earlier test file, which is why this flake is rare and Firefox-specific (event timing differs). Do not add arbitrary sleeps; make it event-deterministic. Reproduce locally with npx wtr packages/core/test/routing/browser/router-js-handled.test.js in a loop (the repo runs Chromium + Firefox + WebKit).
  • A missed interception must FAIL the one test, not interrupt the runner.

Acceptance criteria

  • The positive-control test is deterministic across repeated Firefox runs (e.g. 20x loop locally)
  • A genuinely-missed interception fails with a clear assertion, not a session interruption
  • No behavior change to the router itself

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status
Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions