JosephMCasey February 2016

How should you handle jQuery utilizing soon-to-be deprecated methods on the Chrome browser?

I have some NPMs which have dependencies that are using jQuery to make selections on SVG Elements. Below is the warning I receive when my NPMs use jQuery to make SVG selections.


'SVGElement.offsetWidth' is deprecated and will be removed in M50, around April 2016. See https://www.chromestatus.com/features/5724912467574784 for more details. locuslabs.js:6635 'SVGElement.offsetHeight' is deprecated and will be removed in M50, around April 2016. See https://www.chromestatus.com/features/5724912467574784 for more details.

Chrome had suggested the following:

"These attributes should only be supported on HTMLElement, but have been supported on all Elements in WebKit and Blink. getBoundingClientRect() can typically be used as a replacement." -philipj@opera.com

Here is the section of jQuery code that creates this particular warning.

function getWidthOrHeight( elem, name, extra ) {
// Start with offset property, which is equivalent to the border-box value
var valueIsBorderBox = true,
    val = name === "width" ? elem.offsetWidth : elem.offsetHeight,
    styles = getStyles( elem ),
    isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
...

The Question:

Does NPM provide a way to modify which version of jQuery a NPM uses as a dependency? Is that the best approach to this problem, or should I be going about a resolution for this differently? To clarify, this is less of a technical question and more of a best implementation question.

Answers


JosephMCasey February 2016

When it comes to something that is open sourced, it's often a good idea to review their issue threads for your problem. If you don't find your problem being described, create a new issue. Then you can focus on updating the open source library instead of forcing a sort of polyfill workaround for a library using a deprecated method.


This issue is being reviewed and tracked on jQuery's Github Issue Thread:

https://github.com/jquery/jquery/issues/2895


Update with result of review:

It seems no one really needs an offsetParent equivalent in non-legacy APIs so I'll close this issue. We don't support SVG nodes with a few exceptions and since offsetParent was never implemented in every popular browser, no web-facing code should depend on it.

a crash, or even an exception, won't happen when these attributes are removed. What will happen is that if you're using jQuery older than 2.2.0, the :visible selector will match no SVG element and :hidden will match all SVG elements, i.e. SVG elements are always considered hidden.

With jQuery 2.2.0 (79bcb29) this has been fixed and you shouldn't need to do anything at all.

Post Status

Asked in February 2016
Viewed 1,433 times
Voted 14
Answered 1 times

Search




Leave an answer