Keep element state when the runtime moves a node (`moveBefore()` and not detaching what is re-inserted)
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ệ
- javascript, typescript
- Lĩnh vực
- frontend
Hướng nghiên cứu
Start by reading the keyed reconcile and insert paths, then trace the swap path that uses replaceChild and how removals are ordered against inserts when nodes migrate between parents. Benchmark moveBefore() against insertBefore on those hot paths and measure the cost of deferring removals; performance is the decision gate. Done means deciding the scope and fallback behavior, then validating the behavior and performance against the stated acceptance scenario.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
When a DOM node changes position, @solidjs/web moves it with
insertBefore / replaceChild, and in some cases removes it first and
inserts it afterwards. The browser treats each of these as a removal and an
insertion, so state that lives on the element's connection to the document is
reset: focus, CSS animations and transitions, iframes (they reload), popover
and fullscreen state, and so on.
Element.moveBefore() moves a connected node without that reset. Adopting it
would let Solid 2.0's "one element, several positions" behaviour keep that
state too. This issue is to track it. It needs performance vetting before
any decision.
Where it shows up
- Keyed lists. A focused row that is reordered loses focus.
- An element referenced from more than one position (the
migrating-elementexample; a card created once and referenced from
whichever list holds it). The node keeps its identity, listeners, value and
selection, but loses focus, and an<iframe>or a running CSS animation
would restart. - In an app this reads as: an editor that stays open with its draft intact
but has to be clicked again after someone else moves its card, and a
keyboard "move this item" shortcut that works once and then has nothing
focused.
What was measured
Chromium 152, dev build, origin/next at 2322d6407. One board-level
mapArray creates each card element; three lists' <For>s reference the
elements of the cards they hold; a store write moves a card. DOM calls on the
card element were logged by patching the prototypes.
| Case | Calls the runtime made |
|---|---|
| Card moves to a list that updates before the one it leaves | one insertBefore on the connected node |
| Card moves to a list that updates after the one it leaves | remove(), then insertBefore on the detached node |
| Reorder toward the front of a list | one insertBefore on the connected node |
| Reorder toward the end of a list | replaceChild, then insertBefore on the detached node |
With a focused <input> inside the moved element:
| Same element, value, selection | Focus | |
|---|---|---|
| As shipped | kept in every case | lost in every case |
Connected-node insertBefore routed through moveBefore() (patched in the page) |
kept | kept in the single-insert cases only |
A raw-DOM baseline agrees: moveBefore() on a focused input keeps focus, and
appendChild loses it.
So there are two separate parts:
- Use
moveBefore()when the node being inserted is connected (same
document, and the other preconditions the method has). - Do not detach a node that the same flush re-inserts. Today about half
of the moves above detach first, and no move API can help a node that is
already disconnected when it is inserted.
Part 2 is the larger change. It touches the reconcile's swap path
(replaceChild then re-insert) and the ordering of one position's removal
against another position's insert when a node migrates between parents.
Open questions
- Performance.
moveBefore()on the hot paths (keyed reconcile, the
insert path) againstinsertBefore, in the usual benchmarks, plus the cost
of the feature check and of any deferral of removals for part 2. This is
the gate. - Support. Not in every browser yet (Chromium and Firefox have it,
Safari does not, as far as we know at the time of writing; versions to be
confirmed against MDN). Feature-detect and fall back; a browser without it
behaves as today. - Preconditions.
moveBefore()throws whereinsertBeforedoes not (a
disconnected node, a different document, some shadow-root cases). Each
call site needs the check or a fallback. - Custom elements. With
moveBefore()an element gets
connectedMoveCallbackif it defines one; otherwise the disconnected and
connected callbacks still run. Worth stating in the docs. - Scope. Reorders within one parent only, or migration between parents as
well (which is where part 2 matters most). - Semantics to document. What survives a move today (identity,
listeners, value, selection, canvas bitmap) and what would be added (focus,
animations, iframes, popover and fullscreen state).
Not measured
Firefox and Safari. <iframe>, <video>, CSS animations and popovers (the
migrating-element README's open question about media). Focus was set from
script, and moveBefore() was simulated by patching insertBefore in the
page, not by changing the runtime.
Acceptance test this would unblock
In a board example that is in progress: open a card's title editor in one tab and type half a
word; move that card to another list from a second tab. Today the editor
stays open with the draft and selection intact, and focus is gone. With this
work the next keystroke lands in the editor. The example also carries a
one-line refocus after keyboard moves that could then be deleted.
- Ngôn ngữ chính
- TypeScript
- Star
- 36.2k
- Fork
- 1.1k
- Merge trung bình
- 10 giờ 34 phút
- Pull request đã merge (30 ngày)
- 364
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của solidjs/solid
-
`lazy()`: remounting an already-loaded component renders empty (or the Suspense fallback) since 1.9.14Có thể đã có người làm @itisrmk đã nhận 5 ngày trước. Đang mở1.x
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[2.0] Event handlers fired synchronously from an effect (focus(), showModal()) inherit the effect's strict-read windowCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 44/100
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 1 ngày
-
`createRoot`'s dispose function keeps `fn` alive, so `<For>`/`<Index>` rows retain removed list itemsCó thể đã có người làm @boombang đã nhận 8 ngày trước. Đang mở1.x
Độ khó 4/5 1-2 ngày Mức phù hợp với người mới 45/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Per-scope takeover for live nodes whose server value is still streaming (D8 follow-up to #3817)Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của solidjs/solid
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
db-ux-design-system/core-web#8613 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
foxglove/mcap#1907 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug internal-plugin pr-welcome upstream
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
dsh-tauri-desk/deepseek-harness-desktop#1225 · 1 bình luận ·
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
unjs/unhead#1027 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày