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

Kill onreadystatechange handler after readyState 4 #93

Merged
merged 1 commit into from Dec 13, 2012
Merged

Conversation

@gabalafou
Copy link
Contributor

@gabalafou 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.

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
@rvagg
Copy link
Collaborator

@rvagg 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
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
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants