0.10.0: destroy() can leave an IntersectionObserver on a detached element (idle callback re-arms observePosition)
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 75/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- javascript, typescript
- 領域
- frontend
調査の方向性
index.mjsを読み、特に102行目付近のobservePosition()と、issueで説明されているdestroy()およびupdatePos()の処理を確認してください。既存のテストでobserverのクリーンアップがどのようにカバーされているかを確認し、キューに入ったidle callbackのケースを再現して、破棄後に切り離された要素が再び監視対象にならないことを検証してください。
索引モデルが issue の本文から書いたものです。
説明
Summary
In 0.10.0, an element's subtree can stay alive after destroy(). This also happens when useAutoAnimate unmounts. A low-priority position update that was queued before destroy() runs after it, and observePosition() then creates a new IntersectionObserver on the now-detached element. Its root is document.documentElement, so the observer, and the detached subtree its callback closes over, live for the rest of the page session. Nothing disconnects it again.
This is related to #180 (timers in older versions), but it is a separate path that destroy() doesn't cover.
How it happens (0.10.0, index.mjs)
poll(el)(around line 178) runssetInterval(() => lowPriority(updatePos.bind(null, el)), 2000).lowPriority()(around line 187) queues arequestIdleCallback.- The component unmounts while the main thread is busy, e.g. a route change.
destroy()(around line 776) clears intervals, debounces, intersections and coords, but an idle callback that is already queued still runs. - That callback calls
updatePos(el). After its debounce,updatePoscallsobservePosition(el)(around line 102), which disconnects the old observer (already gone) and creates a new one on the detached element.
Repro
- Scenario: in Chromium, a parent with 10 animated children; unmount it during a ~600 ms busy main-thread window; force GC.
- 0.10.0 as published: the detached subtree survived GC in 11 of 12 trials. All leaked observers were created 200–600 ms after an idle callback that was queued before
destroy()and ran after it. - In a real app: we saw a steady leak of one timeline subtree every few navigations. 0.8.2 leaked on every navigation.
Suggested fix
In observePosition(), right after the old observer is disconnected:
if (!el.isConnected) {
intersections.delete(el)
return
}
Every path that re-creates an observer goes through this function (idle callbacks, the root resize update, observer and animation callbacks), so one guard covers all of them.
- 0.10.0 with the guard: 0 of 12 trials leaked, even though idle callbacks still ran after
destroy(). - Over 60 navigations in our app: DOM nodes and event listeners stayed flat.
Observing a disconnected element measures nothing, so no animation behaviour is lost. Happy to open a PR if that's useful.
- 主要言語
- TypeScript
- スター
- 13.9k
- フォーク
- 266
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
formkit/auto-animate のほかの issue
-
`auto-animate/nuxt`: Module causes 'is not wrapped in defineNuxtPlugin' warning since v0.10.0対応中かも @ExEr7um が 101 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
formkit/auto-animate#240 · リアクション 6 件 ·
-
Child added animation is not working in react StrictMode (or in any other case where autoAnimate() is called twice)対応中かも @kaigritun が 258 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
formkit/auto-animate#232 · コメント 1 件 ·
-
WebKit: removing an animating table row throws in deletePosition()対応中かも @thavguard が 4 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 36/100
formkit/auto-animate#248 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
formkit/auto-animate#235 · コメント 1 件 · リアクション 1 件 ·
-
Image to Videoオープン
難易度 5/5 1週間以上 初心者へのやさしさ 15/100
formkit/auto-animate#233 ·
formkit/auto-animate の issue をすべて見る
似ている issue
-
a10y a10y-audit ai-driven-qa claude
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
linagora/twake-directory-manager#219 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
type: bug
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
メンテナーはふだん 1 日以内に返信
-
0️⃣ phase/new
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
Pulse v7: buildPreferencesFromTelos() bypasses telosSectionOrFile(), renders empty on unified-TELOS installs対応中かも @zephyr91 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
danielmiessler/LifeOS#2393 ·
メンテナーはふだん 4 日以内に返信