WICG / virtual-scroller

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Removing iframes from the DOM has unfortunate consequences

domenic opened this issue · comments

Consider a virtual scroller containing items, every 10th one of which is an iframe. When that iframe falls out of the scroller's viewport, the iframe element will get removed from the DOM. Because of how iframes work, this will completely unload it. Similarly, if it scrolls back into view, the iframe will get reloaded from its src="" URL.

This isn't really acceptable behavior for a lot of use cases, e.g. ads or stateful widgets.

Some solution ideas:

  • Special case iframes?
  • Mark certain elements as "don't remove from the DOM", e.g. using an attribute virtual-scroller-dont-remove or similar?

The demo with headers, also shows how you can handle elements so that they don't get removed.

Since the new approach (detailed in the newly-updated explainer) doesn't recycle/remove elements anymore, this should be a non-issue as the iframe would just stay where it was!