Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Observe: open one interaction frame per event, so listeners outside the runtime can join it

Đã đóng
#3,754 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
frontend, web-dev

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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 get NavigationEvent.interaction === undefined. This is solidjs/solid-router#643.
  • If it opens its own frame (through addEvent(…, false) or withInteraction), 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 for e, for example in a WeakMap<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 dispatchAsInteraction from @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.
Ngôn ngữ chính
TypeScript
Star
36.1k
Fork
1.1k
Merge trung bình
11 giờ 25 phút
Pull request đã merge (30 ngày)
345

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của solidjs/solid

Tất cả issue của solidjs/solid

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.