Commit d50f376
fix(youtube-video-element): destroy the player on disconnect
The YouTube iframe API keeps every player it creates in module-scoped
registries, so removing the element is not enough to release the
<iframe>: it stays detached but reachable from `window.YT`, along with
everything the player's event handlers close over. `api.destroy()` is
currently only reachable from `load()` when `src` is cleared, and the
element defines no `disconnectedCallback`, so every mount/unmount cycle
leaks a player. In React this shows up as `Detached HTMLIFrameElement`
nodes accumulating across route changes with `window.YT` as the retainer.
Add `connectedCallback`/`disconnectedCallback` following the pattern
already used in vimeo-video-element: destroy the player and reset the
load state on disconnect, and reload on reconnect so a DOM move still
works (`load()` is otherwise only triggered by attributeChangedCallback,
which does not fire on a move).
Guard the load itself. `load()` awaits the API script and then
`loadComplete`, so an element disconnected while either is in flight
would still attach a player, or start pollers for one, afterwards. A
#loadId generation counter, bumped on disconnect and on each load, makes
the superseded attempt bail out at both points.
Track and clear the two polling intervals started at the end of load().
Neither timer id was stored, so the 50ms seek poller was never cancelled
and the 100ms progress poller only cancelled itself once fully buffered.
Both closures capture `this`, which kept the element (and through it the
player and its iframe) alive independently of the registry, and with
reload-on-reconnect each remount would stack another pair.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>1 parent b5221ee commit d50f376
2 files changed
Lines changed: 97 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
250 | 250 | | |
251 | 251 | | |
252 | 252 | | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
253 | 295 | | |
254 | 296 | | |
255 | 297 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
150 | 153 | | |
151 | 154 | | |
152 | 155 | | |
| |||
172 | 175 | | |
173 | 176 | | |
174 | 177 | | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
175 | 184 | | |
176 | 185 | | |
177 | 186 | | |
| |||
223 | 232 | | |
224 | 233 | | |
225 | 234 | | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
226 | 239 | | |
227 | 240 | | |
228 | 241 | | |
| |||
328 | 341 | | |
329 | 342 | | |
330 | 343 | | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
331 | 350 | | |
332 | | - | |
| 351 | + | |
333 | 352 | | |
334 | 353 | | |
335 | 354 | | |
| |||
341 | 360 | | |
342 | 361 | | |
343 | 362 | | |
344 | | - | |
| 363 | + | |
345 | 364 | | |
346 | 365 | | |
347 | 366 | | |
| |||
355 | 374 | | |
356 | 375 | | |
357 | 376 | | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
358 | 411 | | |
359 | 412 | | |
360 | 413 | | |
| |||
0 commit comments