observablehq / stdlib

The Observable standard library.
https://observablehq.com/@observablehq/standard-library
ISC License
967 stars 83 forks source link

Don’t generate document fragments. #9

Closed mbostock closed 6 years ago

mbostock commented 6 years ago

Unlike elements, document fragments “dissolve” when they are added to the DOM. Their self-destructive nature makes them difficult to use as stable representations of a fragment of a document; for example, you can add event listeners to a document fragment, but when the document fragment is attached to the DOM, the fragment empties and so the event listeners will never fire.

This restores the previous behavior of the html tagged template literal: if the template literal results in multiple top-level nodes, these nodes are wrapped in an implicit DIV. Likewise, the svg tagged template literal uses an implicit G.