Observe: open one interaction frame per event, so listeners outside the runtime can join it
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- typescript
Research direction
Start with the existing internal dispatchAsInteraction implementation and the observe export surface in @solidjs/web; no specific files or tests are named. Compare the proposed per-event frame lifetime and public export against native and synthetic dispatch behavior, and consider the listed re-dispatch, timing, and preload-listener questions; done means one interaction record per event with outside listeners able to join.
Written by the indexing model from the issue text.
Description
Observed with solid-js / @solidjs/web 2.0.0-rc.13 (observe build) and @solidjs/router next. Context: solidjs/solid-router#643.
Problem
An interaction frame is opened per listener, not per event. dispatchAsInteraction wraps each runtime-attached handler in its own withInteraction call, and the frame is recorded (as "idle" if nothing was written) as soon as that handler returns.
That leaves code outside the runtime with no good option when it reacts to the same event:
- If it uses plain
addEventListener, its work runs outside any frame. Today, router navigations from anchor clicks and form submits getNavigationEvent.interaction === undefined. This is solidjs/solid-router#643. - If it opens its own frame (through
addEvent(…, false)orwithInteraction), the click produces two records. The render root's delegated listener has already opened and closed a frame for that click, recorded as idle. The second record carries the navigation.
What I saw clicking one <a> inside a rendered root:
| Router listener | Interaction records | NavigationEvent.interaction |
|---|---|---|
plain addEventListener (today) |
1: click a#go, idle |
undefined |
through addEvent(document, "click", h, false) |
2: the same idle record, then a second click a#go that owns the navigation |
the second record |
If the anchor also has an onClick that does work, that work lands on the first record and the navigation on the second. One user click shows up as two interactions, which skews INP-style numbers and the click spans that consumers display.
Attaching per root container instead of on document doesn't help, because it is still a second listener and a second frame. Neither does looking up the anchor's container first: frames aren't tied to containers, and by the time the event bubbles to a later listener, the delegated frame has already closed.
Proposal: one frame per event
- Runtime:
dispatchAsInteraction(e, fn)remembers the frame it opened fore, for example in aWeakMap<Event, Frame>. A later call for the same event re-enters that frame instead of opening a new one. - Engine: the frame is finalized (recorded, or marked idle) after the event's dispatch, not when the first handler returns. All listeners for one dispatch run within a single task, so closing at the next task works for both native and synthetic events. A microtask is too early: browsers run microtasks between listeners for native events.
- Surface: export
dispatchAsInteractionfrom@solidjs/web. It already exists internally and is the only new public entry point. Like every other observe hook, it folds out of production builds.
The router would then just wrap its click and submit bodies, dispatchAsInteraction(e, () => …), and keep listening on document. That gives one record per click, with both the onClick work and the navigation in it, and NavigationEvent.interaction set.
Why this belongs in core, not the router
Only the runtime knows that a frame already exists for an event. Any library that listens at the document level hits this: routers, analytics, drag-and-drop, focus/a11y helpers. The router could call OBSERVE.attribution.withInteraction itself, but that opens the duplicate frame above and copies the runtime's target-description and privacy logic.
That said, a public API that mainly serves this case is a fair concern. The alternative I'd weigh is the delegated-handler route: a frame-aware way for a second handler to join the delegated dispatch on an element. The delegated slot ($$click) is single-handler today, and the author's onClick already fills it. That fixes compiler-claimed anchors but not elements outside a root or unclaimed anchors, which is why I lean towards the per-event frame.
Open questions
- A listener running after its event's frame has closed (for example a re-dispatched event): should it open a fresh frame? I'd say yes.
- Records arrive one task later. Timing still comes from
e.timeStamp, so measurements don't change. Is the delay acceptable for consumers? - Should the preload-style listeners (
mousemove,focusin) stay outside frames? For the router, yes: wrapping them would flood the records with idle interactions. That's a usage guideline, not something the runtime needs to enforce.
- Dominant language
- TypeScript
- Stars
- 36.1k
- Forks
- 1.1k
- Avg merge
- 9h 33m
- Merged PRs (30d)
- 262
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from solidjs/solid
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 58/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
solidjs/solid#3766 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
bug:new
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
callstackincubator/simlock#350 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
openwatersio/maritime-zones#33 ·
Maintainers usually reply within 1 day
-
Booking email verification fails for plus aliases with impersonation protection enabledPossibly taken @kankadev claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
calcom/cal.diy#30293 · 1 comment ·
Maintainers usually reply within 5 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
AOSSIE-Org/DebateAI#611 ·
Maintainers usually reply within 3 days