Problem/Motivation
When adding new items to the DOM, its possible to add multiple adjacent elements as part of a DocumentFragment. This allows adding to a list of items, for example, without complicating DOM sibling traversal with "previousElementSibling", et al.
However, the once function does not allow the use of DocumentFragments as the "context" from which to select elements.
Steps to reproduce
1. Create a new DocumentFragment()
2. Attempt to select items with the new fragment as the context
3. Get new type error: "The element must be an instance of Element"
Proposed resolution
We don't actually want to check if context is an element. Instead we can check one of two things:
1. if the item is an instance of Document, DocumentFragment, or Element. (classes with a querySelectorAll method)
2. if the typeof item.querySelectorAll is a function
Remaining tasks
- Select a solution
- Do it
User interface changes
None
API changes
The API would allow more data types to be used as "context" without impacting backwards compatibility
Data model changes
None
Issue fork once-3320496
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
andy-blumupdate IS
Comment #3
andy-blumTwo issue branches are open, but I can't figure out how to make MRs out of them.
Comment #4
nod_Ok with option 1
Comment #6
nod_Comment #7
nod_To be in line with the rest of the code we should throw an error as well
Comment #8
andy-blumComment #9
nod_few things to fix.
Ideally we'd have tests to make sure calls on documentFragment keep working over time
Comment #10
andy-blumComment #11
andy-blumI've been unable to run the tests locally
Comment #12
nod_was able to run the tests with
yarn web-test-runner, they pass.I'll commit next week if justafish doesn't beat me to it :)
Thanks!
Comment #14
nod_Thanks :)