Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

feat(jqLite): use querySelectorAll instead of getElementsByTagName in jqLite.find #3598

Closed
wants to merge 1 commit into from

Conversation

jankuca
Copy link
Contributor

@jankuca jankuca commented Aug 15, 2013

Addresses #3586

@mary-poppins
Copy link

Thanks for the PR!

  • Contributor signed CLA now or in the past
    • If you just signed, leave a comment here with your real name
  • PR's commit messages follow the commit message format

If you need to make changes to your pull request, you can update the commit with git commit --amend.
Then, update the pull request with git push -f.

Thanks again for your help!

@IgorMinar
Copy link
Contributor

is there a queryselectorall polyfill? I found https://gist.github.com/branneman/1200441

qsa is supported on IE8+ so that's good

I'm happy to merge this in after 1.2

@jankuca
Copy link
Contributor Author

jankuca commented Aug 15, 2013

The gist is just using the plain old Sizzle, just like jQuery does. Do we want to include Sizzle somehow or should we leave this up to the app to handle?

On Thursday, August 15, 2013 at 10:33 AM, Igor Minar wrote:

is there a queryselectorall polyfill? I found https://gist.github.com/branneman/1200441
qsa is supported on IE8+ so that's good
I'm happy to merge this in after 1.2


Reply to this email directly or view it on GitHub (#3598 (comment)).

@ledbettj
Copy link

👍 Thanks for implementing.

@leesei
Copy link
Contributor

leesei commented Aug 23, 2013

Sizzle may be too large (minified@18k) for AngularJS.

@hallister
Copy link

18k seems expensive, given that the only browsers that don't support it is IE 6 and 7. And that problem is solved by calling element.getElementsByTagName() when element.querySelectorAll() doesn't exist.

@mgol
Copy link
Member

mgol commented Sep 4, 2013

If jqLite continues to grow, at one point it might be better to replace it with custom jQuery 2.x build. You can even exclude Sizzle there! jQuery handles lots of cross-browser problems so that would be a plus. I'd be monitoring the situation about when it would be a good moment to switch (as jqLite grows and jQuery gets more & more componentized, we e.g. switched internally to AMD recently).

I am a jQuery Core team member, though, so I might be a little biased. :)

@expando
Copy link

expando commented Sep 21, 2013

return (element.querySelectorAll || element.getElementsByTagName).call(element, selector);

The conditional will cause silent errors for IE<8 if the selector is not a tag name. It's better to only use querySelectorAll so that users on IE<8 get an error, rather than not see an error, but don't get the expected result either.

I'd rather have conditional code blocks for IE<8 if they work as expected, even though we don't official support it, rather than conditional code blocks that may or may not work everytime.

Or alternatively, explicitly state that the function only accepts tag names and not full CSS queries. In that case, the function would run faster if it used getElementsByTagName over querySelectorAll under certain scenarios and would be the same in the rest of the scenarios.
http://jsperf.com/access-to-nodes-via-queryselectorall-vs-getelementsbyta/6

@hswolff
Copy link

hswolff commented Sep 21, 2013

Instead of Sizzle perhaps look at https://github.com/ded/qwery as a querySelectorAll polyfill?

I only just came across it (don't know anything about it), however it looks much slimmer than the polyfill linked to above.

@petebacondarwin
Copy link
Contributor

@mzgol - I am pretty sure that at some point we will do exactly that. The question is as you say when the optimal moment arrives.

@clakech
Copy link
Contributor

clakech commented Sep 25, 2013

👍 would love to get this in ng

@hsablonniere
Copy link
Contributor

If we get this in 1.2 this way we'll have this problem #4120. Don't forget to verify if there's no text nodes.

@teddyhwang
Copy link

👍

1 similar comment
@nosideeffects
Copy link
Contributor

👍

@IgorMinar
Copy link
Contributor

@mzgol we tried building a custom jquery2 build but it was still huge.

@IgorMinar
Copy link
Contributor

@mzgol quite frankly, I'd love to throw jqLite away if we could get a jQuery build of comparable size and functionality.

@malsup
Copy link

malsup commented Dec 12, 2013

@IgorMinar In the meantime, why not just merge this pull request? It makes "find" significantly more useful.

@dtabuenc
Copy link
Contributor

+1

7 similar comments
@OverZealous
Copy link

+1

@malsup
Copy link

malsup commented Dec 15, 2013

+1

@sbruchmann
Copy link

+1

@mofas
Copy link

mofas commented Dec 15, 2013

+1

@jorgenfb
Copy link
Contributor

+1

@tbertenshaw
Copy link

+1

@codef0rmer
Copy link
Contributor

+1

@wilsonjackson
Copy link

This is a great addition, but I'm a little concerned about the unintuitive scoping behavior of querySelectorAll. This would be easy to patch for browsers that support the :scope pseudo element, but sadly that leaves IE8 out in the rain — and maybe more, I haven't researched :scope support thoroughly.

@just-boris
Copy link
Contributor

+1

2 similar comments
@GabrielDelepine
Copy link

+1

@flekschas
Copy link

+1

@IgorMinar
Copy link
Contributor

fixing this properly is non trivial and won't happen in 1.3. moving this back to backlog.

@dhzhuo
Copy link

dhzhuo commented Nov 10, 2014

+1

@ilanbiala
Copy link

Any plans on merging this in time for 1.4 or 2.0?

@caitp
Copy link
Contributor

caitp commented Dec 19, 2014

@ilanbiala --- the main reason we don't is because we wouldn't be able to provide the expected results (although we could provide very similar results to jquery 2.x).

There are polyfills available for some of the missing features, (like https://github.com/termi/CSS_selector_engine), so it's probably possible for us to do it.

Leave that up to @petebacondarwin though

@ilanbiala
Copy link

@caitp thanks for the update.

@mgol
Copy link
Member

mgol commented Jan 1, 2015

If we were to use an external CSS selector engine, we might as well use the
most popular & battle-tested one in the world: Sizzle that is included in
jQuery... 18 KB minified. The one @caitp linked to is 10 KB, so also not
extremely small.

BTW, Sizzle will be dropping support for browsers not supported by jQuery
which will decrease its size.

I feel that escapes jqLite's goal, though - if we want to be more
feature-complete & stable even if that sacrifices the size, we have jQuery
for that.

@mgol
Copy link
Member

mgol commented Jan 1, 2015

Correction: since only gzipped sizes matter; here they are:

Sizzle: 6.9 KB
CSS_selector_engine: 4.6 KB

And note that the next Sizzle version will be smaller.

@bzitzow
Copy link

bzitzow commented Jan 8, 2015

+1

1 similar comment
@starzou
Copy link

starzou commented Jan 15, 2015

+1

@petebacondarwin petebacondarwin modified the milestones: 1.4.x, Backlog Jan 15, 2015
@daniellmb
Copy link
Contributor

+1

@caitp
Copy link
Contributor

caitp commented Jul 29, 2015

fixing this properly is non trivial and won't happen in 1.3. moving this back to backlog.

I think it's time for this one to be closed. we can take another attempt at this in the future (with the next level of DOM), but I don't think there's much hope for the aspirations of this right now.

@caitp caitp closed this Jul 29, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.