Skip to content
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

Fix #10814. Make support tests lazy and broken out to components. Fix #14084: attach the test div to documentElement, not body. #1342

Merged
merged 2 commits into from
Sep 6, 2013

Conversation

mgol
Copy link
Member

@mgol mgol commented Aug 27, 2013

Support module broken up.

Things still to do:
(1) 3 tests are failing, I need to figure why (documenElement issues?)

Analogous PR for 1.x-master: #1353.

@mgol
Copy link
Member Author

mgol commented Aug 27, 2013

This seems more-or-less ready except points written in description.

@mgol
Copy link
Member Author

mgol commented Aug 27, 2013

The errors are weird, nothing breaks purely in tests, they even can't get to the expect invocation. Problem concerns only iframe tests and only 3 of them. Weird...
test-errors

@timmywil
Copy link
Member

This is a great start. I have a suggestion though. We can still attach support properties to jQuery.support, but module-specific support properties only show up if you're including that module. For instance, instead of a separate object for support in CSS, include a dependency from css/support, which depends on var/support and attaches properties to that object for use in the CSS module. CSS would still reference properties off of jQuery.support. Adversely, if CSS were removed, those properties on jQuery.support would no longer be present. This keeps all of our features tests still gathered into one object for inspection, but tied to modules.

@mgol
Copy link
Member Author

mgol commented Aug 27, 2013

@timmywil Such a tactic would make it easier for us to test support but it leaves us with a problem of exposing support properties. This is a problem as we have it harder to drop properties from jQuery.support when a particular test is no longer needed somewhere. That's why we wanted to get rid of exposing all that stuff per my talk with @dmethvin amongst others.

One solution I proposed in description would be to create a separate build option exposing the properties so that we can test it. Seems a little ugly, though. Any better suggestions? @timmywil, @dmethvin, @Orkel, @gibson042?

@scottgonzalez
Copy link
Member

I really don't think we need to protect ourselves here by actually hiding the support properties. We've been pretty clear about the fact that these are not public. If people continue to use them and then complain when they go away, we can just continue to point out that they're private. One big step in that direction would be to remove all details on http://api.jquery.com/jQuery.support/ and just have a page that says jQuery.support is not a public API. I'm still not sure why this page was created in the first place.

The bottom line is that if we're willing to drop all support properties today, then there's no reason we shouldn't be willing to drop individual properties at will.

@timmywil
Copy link
Member

It does seem like a drastic change. I missed the conversation, but I don't think we need to make it completely private. It can certainly be useful if I know that the version of jQuery I am using already implements the exact feature test that I need. It's nice not to have to do it again, but I just know not to complain if that feature test goes away and I need to implement it myself in the future. Whatever we decide, I think we should still gather all of our features tests on var/support, whether or not it is exposed.

@markelog
Copy link
Member

If we don't expose support object you could test support elements indirectly by interaction with methods that depend on them. Which is hard thing to do and it looks like it would be hard thing to maintain.

Another hard thing to do is to demonstrate that we actually improve page initialization and did not heavily injured module performance.

BTW, you changing a lot, so it might be good idea to fix code style issues on the lines that you touch and follow the code style in new files.

All and all that's a good start.

/cc @mikesherov @paulirish

@dmethvin
Copy link
Member

One big step in that direction would be to remove all details on http://api.jquery.com/jQuery.support/ and just have a page that says jQuery.support is not a public API. I'm still not sure why this page was created in the first place.

I'm good with that, and created a ticket. We can leave an entry saying it shouldn't be used. As for why, I think the logic was that others might need some of this info. However, it was definitely a mistake to expose things like this that cause forced layouts and then guarantee they are always present.

Seems like this is a question of how much we're going to break things. We can stuff the results we do create into jQuery.support as before, but that will only happen when a magic API is called that needs the info. Any external user won't know that ... and I don't want to document it! Plus we've already left several of these behind since they weren't needed for the 2.x branch anymore. So isn't the situation already so broken that putting the properties in jQuery.support won't help that much?

@scottgonzalez
Copy link
Member

I don't care if the properties stay in jQuery.support, but it sounded like leaving them there (at a minimum exposing somehow) made testing saner.

@timmywil
Copy link
Member

If we don't expose support object you could test support elements indirectly by interaction with methods that depend on them.

As you probably realise, this is true for some, but not all, support tests. Sometimes the test indicates the the code should take a different path to the same result. In those cases, it's about performance. You get the correct test result either way.

The only reliable way to test them without their exposure is to test for both correct results and performance regressions, both of which could be tricky and probably too much work right now. @scottgonzalez is right that the sanest way to test this stuff is to have it exposed somehow. Maybe jQuery._support? That's kind of the semantics we're talking about anyway.

@ghost
Copy link

ghost commented Aug 27, 2013

You get the correct test result either way

Do you have an example? But even if such test does not exist it might be in future.

@scottgonzalez is right that the sanest way to test this stuff is to have it exposed somehow

Yes, by this remark:

Which is hard thing to do and it looks like it would be hard thing to maintain

I was implying the same thought :-).

@markelog
Copy link
Member

Sorry, wrong account :-(, "markelog" is me

@timmywil
Copy link
Member

Do you have an example?

Sure, support.getSetAttribute and support.input. Theoretically, those could have the wrong values (i.e. they could be false when they should be true), but attr itself would still return the right values for attributes. attr would be taking a longer path to get there and thus hurt performance.

@markelog
Copy link
Member

Sure, support.getSetAttribute and support.input
beautiful :-), which is interesting given that before 1.8 jQuery did not have such tests and they briefly disappear in 2.0 rewrite

@mgol
Copy link
Member Author

mgol commented Sep 2, 2013

I implemented requested changes. I'm using ./var/support for keeping support properties instead of jQuery.support and I attach them to the jQuery object in one place: core.js. In this way, should we remove jQuery.support or move it to somewhere else, it will be much easier.

I still have these 3 strange test errors, I could use some help tracking them out.

Besides these errors, is it OK to merge or is there anything else I need to fix?

input.type = "radio";
support.radioValue = input.value === "t";
})();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, but you could return support here and just include ./attributes/support as the support var. The build will handle removing the return statement.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually had sth like that at one point but I changed it not aware of the fact the build step will remove the return statement, good to know! I'll change that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timmywil Should it be ./attributes/support or ./attributes/var/support?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like you figured it out already, but ./attributes/support is right because you're not adding another var, just adding to an existing one.

@timmywil
Copy link
Member

timmywil commented Sep 2, 2013

This is great, by the way.

@mgol
Copy link
Member Author

mgol commented Sep 2, 2013

I added a test for http://bugs.jquery.com/ticket/14084 but it doesn't run for some reason. When I put it in unit/support.js it does run and passes while in unit/css.js it doesn't show up on a test list. Any ideas why that happens?

expected = {
"checkOn":true,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is lots of line changes but I figured out since this diff will be large anyway...

We have a mess in lists of support properties here, they're in a completely random order. I made it alphabetical, it'd be good if we kept it that way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mikesherov
Copy link
Member

@Orkel, we should be able to prove speed improvements with a couple of jsperfs showing results.

@mzgol, this PR gets us separated out by module, which is awesome, but theoretically actually slows us down until we implement lazy loading strategy, right?

@timmywil @scottgonzalez @dmethvin, in the past we documented jQuery.support and have had "trouble" deprecating these, like what happened when we tried to remove our broken quirks mode feature detect. Now that we have AMD, we no longer need to be burdened by the "public but not documented" conundrum. My vote would be to deprecate jQuery.support in the next release, with a path to removal. Besides, if we want lazy initialization (I.e. do the support test right before we need it), we'll likely need to change the jQuery.support object anyway.

@timmywil
Copy link
Member

timmywil commented Sep 2, 2013

@mikesherov this does implement lazy loading. We only need to lazy load tests that require doc ready or a body.

@mgol
Copy link
Member Author

mgol commented Sep 2, 2013

IMHO if we have to expose jQuery.support, e.g. for unit/support, I'd prefer it to sit under jQuery._support so that it's more clear we don't want users to rely on that.

I'd still love to get this hidden (esp. that we have all of that under /var/support so internally it's easy to access) but it can wait after this PR gets merged.

@mikesherov I only lazy-load tests that might trigger layout, i.e. those operating on elements attached to documentElement.

I'm working on an analogous PR for 1.x-master currently.

@markelog
Copy link
Member

markelog commented Sep 2, 2013

@mikesherov we can't do that, because this change will actually decrease speed of some methods but i yet would like to know by how much. @mzgol?

Speed improvements might be considerable on page initialization time, at empty page with only jQuery included it's a 0.056 ms on my machine in Chrome. For 1.10.2 on some "heavy" page it's a ~150 ms. To know by exactly how much we could win i cc you and @paulirish. Because it's a main reason why support tests should became lazy-load.

@mzgol i mention before

BTW, you changing a lot, so it might be good idea to fix code style issues on the lines that you touch and follow the code style in new files.

Like here and there?

@@ -797,6 +797,11 @@ test("css('width') and css('height') should respect box-sizing, see #11004", fun
equal( el_dis.css("height"), el_dis.css("height", el_dis.css("height")).css("height"), "css('height') is not respecting box-sizing for disconnected element, see #11004");
});

testIframeWithCallback( "css('width') should works correctly before document ready", "css/cssWidthBeforeDocReady.html", function( cssWidthBeforeDocReady ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you mention ticket number here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, any ideas, @Orkel, why this test does not fire unless I move it from here to unit/support?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmm, it does work in my browsers

@mgol
Copy link
Member Author

mgol commented Sep 2, 2013

@Orkel I corrected some style issues but not all. I looked over the files now and corrected the rest. Let me know if I missed anything.

@mgol
Copy link
Member Author

mgol commented Sep 2, 2013

@Orkel how many tests current Chrome fire on this branch in the css module for you? I have 256.

@markelog
Copy link
Member

markelog commented Sep 2, 2013

257 :-), in what browsers do you get such results?

@mgol
Copy link
Member Author

mgol commented Sep 2, 2013

@Orkel It seems only in Chrome stable, works in Firefox, Safari, Opera Presto & Blink, Chrome Canary...

EDIT: meh, that'll teach me to run tests ALWAYS in incognito mode, works there. :D

@markelog
Copy link
Member

markelog commented Sep 2, 2013

:-)))

@mgol
Copy link
Member Author

mgol commented Sep 2, 2013

Just to stress it, those 3 test failures exist in incognito mode as well. This is extremely weird as it seems it can't even get to the expect( n ) invocation. Any ideas?

@mgol
Copy link
Member Author

mgol commented Sep 6, 2013

I've just created an analogous pull request for 1.x-master: #1353. Enjoy. :)

@mgol
Copy link
Member Author

mgol commented Sep 6, 2013

Since I don't experience the same failures on the 1.x-master refactor as I do here, I suspect using documentElement might be the issue. Strange, though, since the body -> docElem switch by itself didn't introduce these errors, only subsequent "lazification" caused that effect.

Need to investigate more.

@timmywil timmywil merged commit bbbdd94 into jquery:master Sep 6, 2013
@mgol mgol deleted the lazy_support branch September 6, 2013 15:33
@mgol
Copy link
Member Author

mgol commented Sep 6, 2013

BTW, this saves 19 bytes minified & gzipped. :)

@lock lock bot locked as resolved and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

9 participants