-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove querySelector and querySelectorAll from shared/dom.js #1196
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1196 +/- ##
=======================================
Coverage 91.63% 91.63%
=======================================
Files 127 127
Lines 4567 4567
Branches 1503 1503
=======================================
Hits 4185 4185
Misses 160 160
Partials 222 222 Continue to review full report at Codecov.
|
I'm not sure this is something we'd want to do. We do have a |
Wouldn't be an issue if you choose not to accept. I made a small (terrible and untrustworthy) performance test here if you're interested. https://pumped-look.glitch.me/ Chrome 64 Mac
Safari 11 Mac
|
We used to use I'm not too concerned about any performance difference, and the filesize difference is probably acceptable given that it doesn't affect anyone who isn't using selects (and the difference is negligible if it's not a multiple select). That said @Conduitry makes a good point about choosing not to support environments with QS/QSA, as it could prove to be a tricky constraint in future. Out of curiosity have you found any other incompatibilities with your DOM implementation, or is that the only one so far? |
Agree this is a tricky constraint. I haven't found a lot of use for QS/QSA in applications like those written using Svelte. When you have a direct reference to DOM nodes you generate, the need for query selection against them is lessened. However, it's also just as likely others have found great success using them in similar applications.
This is the only one so far, A suggestion perhaps: Strive to not use querySelector when a DOM Level 1 API exists and does the same operation – but use it when it makes sense otherwise. |
worker-dom will be gaining support for |
Hello,
I noticed when exploring examples using HTMLSelectElements that querySelector and querySelectorAll was used to find the options checked. I'm working on a DOM implementation that doesn't currently support these APIs and made changes locally to continue along.
First, this change uses
selectedIndex
when only a single value is allowed in a HTMLSelectElement.selectedIndex
has been present since DOM level 1 and should provide a reasonable replacement. (https://www.w3.org/TR/REC-DOM-Level-1/level-one-html.html#ID-94282980)Secondly, when multiple values are possible, this change moves to iterating over the options and creating an array of values for selected options.
Am slightly unfamiliar with the structure of the project, and wasn't sure where to add tests regarding the performance of these implementations. Happy to do so or make other changes if helpful.
Total change adds 23 bytes to uncompressed (but minified) output of an application leveraging both functions.