Skip to content

Browser mode: Infinite 'Unknown event: response:response:...' loop when running multiple click tests #9379

@simshanith

Description

@simshanith

Describe the bug

When running multiple browser tests that involve click events on anchor elements, thousands of "Unknown event: response:response:response:..." errors occur. The response: prefix accumulates recursively, suggesting an infinite feedback loop in iframe communication.

Reproduction

External reproduction repo: simshanith/lit-ui-router#69

Steps:

  1. Clone https://github.com/simshanith/lit-ui-router
  2. Checkout commit 9d116d4
  3. Run pnpm install
  4. Run: pnpm --filter lit-ui-router test ui-sref.spec -t "click modifiers" --browser=chromium

Expected behavior

Tests pass with no errors.

Actual behavior

Tests pass but with thousands of errors:

Error: Unknown event: response:response:response:response:response:execute
Error: Unknown event: response:response:response:response:response:cleanup

Analysis

Looking at packages/browser/src/client/tester/tester.ts lines 94-97:

channel.postMessage({
  event: `response:${data.event}`,
  iframeId: getBrowserState().iframeId!,
})

When an unknown event arrives:

  1. It logs "Unknown event: {eventName}" via unhandledError()
  2. It still sends a response with response:${data.event}

If responses somehow get echoed back (iframe routing issue with click events?), this creates a feedback loop:

  • executeresponse:executeresponse:response:execute → ...

Hypothesis

Click events on anchors with target="_blank" or navigation-triggering attributes may cause iframe communication that echoes responses back to the handler.

Proposed Fix

Add a guard to prevent responding to events that already start with response::

// Before sending response, check if this is already a response event
if (data.event.startsWith('response:')) {
  // Don't respond to response events - this would create infinite loop
  return
}

Key Details

  • Issue only occurs when multiple tests run (individual tests pass)
  • Tests involve click events on anchor elements
  • Anchors may trigger navigation
  • Some tests use target="_blank" or rel="external" attributes
  • Error count grows exponentially with test count

Environment

  • vitest: 4.0.16
  • @vitest/browser-playwright: 4.0.16
  • playwright: 1.54.1
  • macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: browserIssues and PRs related to the browser runnerp3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    Projects

    Status

    Approved

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions