Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Kill onreadystatechange handler after readyState 4 #93

Merged
merged 1 commit into from Dec 13, 2012

Conversation

Projects
None yet
2 participants
Contributor

gabalafou commented Dec 13, 2012

There's a bug that apparently only affects a subset of Webkit browsers where if the execution is halted (through a debugger, for example), an xhr object can fire the readystatechange event (with
readyState 4) multiple times (apparently, always 3 times). For reference,
see:

I'm also linking to 2 jsfiddles that illustrate the issue.
I was able to reproduce this behavior on Chrome 23 and mobile Safari on iOS 5
(using remote debugging with an iPad) but not on (desktop) Safari 6 or Safari 5.1.

Steps to reproduce with first jsfiddle:

  1. Open Chrome
  2. Allow pop-ups 
  3. Go to http://jsfiddle.net/MeXvJ/
  4. Close the pop-up
  5. You'll get 3 sequential alert boxes 

Steps to reproduce with second jsfiddle:

  1. Open Chrome
  2. Open Developer Tools
  3. Go to http://jsfiddle.net/44b3P/
  4. Unpause script execution in the debugger
  5. You'll get 3 sequential alert boxes

Both jQuery and Zepto already do something similar to what I'm proposing. The
difference is that they both set the onreadystatechange handler to a no-op
function. Not sure why.

Kill onreadystatechange handler after readyState 4
There's a bug in WebKit where if the execution is halted (through a debugger, 
for example), an xhr object can fire the readystatechange event (with 
readyState 4) multiple times (apparently, always 3 times). For reference, 
see:

* madrobby/zepto#633

I'm also linking to 2 jsfiddles that illustrate the issue.
I was able to reproduce this behavior on Chrome 23 and mobile Safari on iOS 5 
(using remote debugging with an iPad) but not on (desktop) Safari 6.

Steps to reproduce with first jsfiddle:

1. Open Chrome
2. Allow pop-ups 
3. Go to http://jsfiddle.net/MeXvJ/
4. Close the pop-up
5. You'll get 3 sequential alert boxes 

Steps to reproduce with second jsfiddle:

1. Open Chrome
2. Open Developer Tools
3. Go to http://jsfiddle.net/44b3P/
4. Unpause script execution in the debugger
5. You'll get 3 sequential alert boxes

Both jQuery and Zepto already do something similar to what I'm proposing. The 
difference is that they both set the onreadystatechange handler to a no-op 
function. Not sure why.

* jQuery: https://github.com/jquery/jquery/blob/master/src/ajax/xhr.js
* Zepto: https://github.com/madrobby/zepto/blob/master/src/ajax.js
Collaborator

rvagg commented Dec 13, 2012

oo, that is nasty. Thanks so much for researching this and providing so much information in the pull request @gabalafou! 👍

rvagg added a commit that referenced this pull request Dec 13, 2012

Merge pull request #93 from gabalafou/patch-1
Kill onreadystatechange handler after readyState 4

@rvagg rvagg merged commit 46f8458 into ded:master Dec 13, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment