Skip to content

Deprecate which property of the event object #2337

Closed as not planned
Closed as not planned

Description

@markelog

In the https://api.jquery.com/category/events/event-object/, we have

The following properties are also copied to the event object, though some of their values may be undefined depending on the event:

altKey, bubbles, button, cancelable, charCode, clientX, clientY, ctrlKey, currentTarget, data, detail, eventPhase, metaKey, offsetX, offsetY, originalTarget, pageX, pageY, relatedTarget, screenX, screenY, shiftKey, target, view, which

which property is deprecated by the DOM specification - https://w3c.github.io/uievents/#widl-KeyboardEvent-which, it seems we need to add a note about it (and possible for the other properties too), deprecated it and show message in the migrate?

/cc @dmethvin

Activity

  1. timmywil commented on May 20, 2015

    @timmywil
    Member

    Hmm, I'm not sure that's necessary. Doesn't hurt to copy it if it's there.

  2. timmywil commented on May 20, 2015

    @timmywil
    Member

    Or should this be moved to tickets in api/migrate?

  3. dmethvin commented on May 20, 2015

    @dmethvin
    Member

    Remember there is a which for both KeyboardEvent and MouseEvent. Both are pretty screwy.

    For a keyboard event you're supposed to use key instead of which but for a long time the preferred property was keyCode. We copy both of them over to the normalized event if they are present, but neither will be there in IE8.

    The W3C created another confusing set of button and buttons properties for MouseEvent that also took a few years for browsers to get right. IE8 only supports which natively. At the time the other two properties were screwed up with other browsers we decided to normalize which. The docs say that we don't copy buttons but we do, so a lot of people may be using button and buttons already if they don't care about IE8.

    We could deprecate which in 3.0 and have Migrate warn about the better choices here. The problem would be in the compat branch where IE8 needs it and we never normalized button, buttons, keyCode, and/or key. Also note that there may be a high perf penalty for that, we'll have to see. Events like mousemove or mouseover happen a lot.

  4. mgol commented on May 20, 2015

    @mgol
    Member

    The copying already causes performance penalty in Firefox in some cases, see mozilla/treeherder-ui-deprecated#486 that @fitzgen made me aware of. I didn't have time to measure what's exactly slowing everything down but in the linked PR the jQuery is patched to use getters instead of copying as it significantly speeds up Firefox from what I understand.

  5. dmethvin commented on May 20, 2015

    @dmethvin
    Member

    It's probably the calculation of pageX and pageY because they can force layout. Changing to a getter avoids this as long as the user's event handler doesn't ask for them. Since they're deprecated properties nobody should use them but we've supported them because they were present in IE8 and are handy. From a perf standpoint it would be best to deprecate these as well, because even if we shim them with a getter they're poison when you use them.

  6. mgol commented on May 20, 2015

    @mgol
    Member

    Well, if they're deprecated and they may cause performance penalty, could we remove them in 3.0? I'd be in favor in just keeping deprecated but perf issues are a bad thing to have, especially if it's so bad that 3rd parties have to patch our code to make it palatable.

  7. jbedard commented on May 20, 2015

    @jbedard
    Contributor

    Normally the copying is only bad when it forces a style recalculation and layout such as offset/position properties (see #1746). Although for very frequent events (mousemove) the copy loop can be pretty significant even without a re-layout.

  8. timmywil commented on May 20, 2015

    @timmywil
    Member

    I think the most we'll do for 3.0 is deprecate. I'd feel more comfortable removing once IE8 market share is low enough and we can drop it.

  9. mgol commented on May 20, 2015

    @mgol
    Member

    Although for very frequent events (mousemove) the copy loop can be pretty significant even without a re-layout.

    Right, but what PR https://github.com/mozilla/treeherder-ui/pull/486/files does is just changing the copying to multiple defineProperty so from a purely-JS stand point the replacement should be slower. It seems actually reading the property must be causing the perf penalty then.

    I think the most we'll do for 3.0 is deprecate. I'd feel more comfortable removing once IE8 market share is low enough.

    Yeah, but if we're causing perf issues there we might for example change copying to using getters in some cases where supported. This would require some actual examples we can test on, though, for now we're just guessing.

  10. dmethvin commented on May 20, 2015

    @dmethvin
    Member

    If all our 3.0 browsers truly support Object.defineProperty() it seems like we could define jQuery.Event.prototype at load time to lazy-copy and lazy-evaluate everything? That removes all the copy overhead from event delivery. There are some complications because other code may define jQuery.event.fixHooks at any time during execution and expect the next event delivery to reflect their changes. It would be good to deprecate that behavior as well so we could optimize in the future.

  11. jbedard commented on May 20, 2015

    @jbedard
    Contributor

    Like @dmethvin said the definePropertys could be on the prototype so it moves all performance issues (slow getter, style recalc) to get-time and also removes the fix loop. This makes e.hasOwnProperty('which') false though, didn't think of that before...

    See jbedard@fd61774 for a POC from #1746. This commit handled the fixHooks issue you mentioned @dmethvin.

  12. dmethvin commented on May 21, 2015

    @dmethvin
    Member

    Hey @jbedard, this @jbedard guy had something there. 😸 I love the way it handles the dynamic adds of fixHooks! Would you be able to add a perf test on #1746? I'm wondering if defineProperty is fast enough now.

  13. added this to the 3.1.0 milestone on Jan 15, 2016
  14. modified the milestones: 3.3.0, 3.2.0 on Mar 6, 2017
  15. dmethvin commented on Jan 9, 2018

    @dmethvin
    Member

    This is a docs-only action for 3.3, see jquery/api.jquery.com#821 .

    The actual removal will occur with gh-3235.

  16. locked as resolved and limited conversation to collaborators on Jul 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions