Skip to content

Client router click listener is capture-phase: same @click preventDefault hijack as the submit bug #153

Description

@vivek7405

Problem

Follow-up surfaced while fixing #150 (the form-submit capture bug). The client
router's click listener is registered on document in CAPTURE phase
(router-client.js enableClientRouter: addEventListener('click', onClick, true)), and onClick has the same if (e.defaultPrevented) return guard as
onSubmit did. A component's @click handler is bound per-element (at-target),
so it runs AFTER the document capture listener. So a JS-handled link, e.g. a
custom element rendering <a href="..." @click=${e => { e.preventDefault(); doSomethingInJs(); }}> (an in-component menu toggle, a JS-driven action link),
would be hijacked by the router and navigated, before the component's
preventDefault runs. Same class of bug as #150, for clicks instead of submits.

It does not bite the demo blog (its nav is plain <a href> and its
interactivity is forms), which is why #150 fixed only submit and left click
capture. But the asymmetry is real and will bite an app with a JS-handled link.

Design / approach

Moving click to bubble (like #150 did for submit) would honor a component's
@click preventDefault. Needs care: the click path has more cases than submit
(modifier keys, middle-click, download, cross-origin, hash links, the existing
capture-phase tests). Verify nothing relies on capture ordering before flipping.

Acceptance criteria

  • A component <a @click=preventDefault> is NOT intercepted/navigated by the router
  • Plain <a href> links still SPA-navigate; modifier/middle clicks, downloads, cross-origin, hash-only still behave
  • Browser/e2e regression for a JS-handled link

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions