Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome 57 making .data() not function well

This part of an .on("change") event is not working properly when users are working in Chrome 57. This is only a Chrome 57 issue.

The userId variable in the if is set and has a value before it gets to this piece of code.
However, the conditional is not being found true when it should.

But if I am debugging and have a break point set I think on the if and I stop at the break point and linger for a while does this work properly.

This is not affecting everyone using 57.
I've only been able to recreate this issue twice and after debugging, it goes away.

Any idea on what's going on and how to fix it?
I will also note that we are using a very old version of jquery - 1.11.1 and upgrading will not be easy.

var selected = $(this).children("option:selected");
var name = selected.html();
var userId = selected.attr("value");
var personInList;

$("li", "#list1").add("li.person", "#list2").each(function () {
    if ($(this).data("userId") == userId) {
        personInList = $(this);
        return;
    }
});

if (userId && userId!= "default" && !personInList) {
    //some code that gets triggered that shouldn't because this "if" is turning up true
}
like image 216
Kendra Ball Avatar asked Mar 30 '17 23:03

Kendra Ball


People also ask

Why is my Google Chrome not working properly?

You can restart your computer to see if that fixes the problem. If the above solutions didn't work, we suggest you uninstall and reinstall Chrome. Uninstalling and reinstalling Chrome can fix problems with your search engine, pop-ups, updates, or other problems that might have prevented Chrome from opening.

How do I stop Chrome from throttling?

To disable throttling in versions of Chrome up to 20.0. 1115.2: Type chrome://net-internals/#httpThrottling into the address bar and uncheck the checkbox labeled "Throttle HTTP requests if the server has been overloaded or encountered an error."


1 Answers

For me, this did the trick:

In the place that the .data() is set, just save the element or the result of data somewhere.

$('#someElem').data('userId', '1234');
var elemData = $('#someElem').data('userId');

window['someUniqueKey'] = elemData;
//or
console.log(elemData);

Then, the call to $('#someElem').data('userId') should return valid data in your event handler.

As to why this happens: I would be very gratefull for an answer. A colleague of mine suggested it might be something with the Garbage Collection in the new Chrome. But if so, it looks like it's a bug in the GC.

like image 180
Botis Avatar answered Oct 03 '22 08:10

Botis