Observe: open one interaction frame per event, so listeners outside the runtime can join it
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- typescript
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 36.1k
- Forks
- 1.1k
- Merge medio
- 10 h 7 min
- PR fusionados (30 d)
- 289
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de solidjs/solid
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 58/100
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
Los mantenedores suelen responder en 1 día
Todos los issues de solidjs/solid
Issues similares
-
dx hacktoberfest help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
documentation
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
cloudflare/agents#2498 ·
Los mantenedores suelen responder en 1 día
-
Missing repro Platform: Android
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
software-mansion/react-native-reanimated#10816 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
e2e-failure ready-to-code
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
redhat-developer/rhdh-plugin-export-overlays#4129 ·
Los mantenedores suelen responder en 1 día