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

Fix readystatechange #130

Merged
merged 4 commits into from
Dec 11, 2015
Merged

Conversation

adamjmcgrath
Copy link
Contributor

  • Add readystatechange to xhr events regardless of the browser supporting onload, for ajax implementations that still rely on readystatechange (eg jQuery 1.x jQuery 1.x with passthrough #85 )
  • Move evts into function closure so multiple calls to createPassthrough don't result in duplicate entries in evts.

…orting `onload`, for ajax implementations that still rely on readystatechange

- Move `evts` into function closure so multiple calls to `createPassthrough` don't result in duplicate entries in `evts`.
@trek
Copy link
Member

trek commented Nov 24, 2015

If this is to fix issues with jQuery 1.x, the test suite needs to be updated to run integration tests against both jQuery 1.x and 2.x or we'll have regressions.

@adamjmcgrath
Copy link
Contributor Author

This is to fix issues with any ajax client that uses the readystatechange event, of which jQuery 1.x is one.

The additions to passthrough_test.js are designed to stop regressions of this case.

@@ -201,7 +202,6 @@ function interceptor(pretender) {
createUploadHandler(uploadEvents[i]);
}

xhr.open(fakeXHR.method, fakeXHR.url, fakeXHR.async, fakeXHR.username, fakeXHR.password);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was it necessary to move where the xhr.open is being called?

@adamjmcgrath
Copy link
Contributor Author

why was it necessary to move where the xhr.open is being called?

Good point, I probably should have explained this. There's a bug (https://bugs.webkit.org/show_bug.cgi?id=45994#c2) in older versions of webkit (that effect phantomjs 1.x) where the status is not accessible on an XMLHttpRequest if the readyState is 0 or 1. When we call xhr.open, a readystatechange event is fired and we try to copy the status of the xhr to the fakeXHR - this throws the "DOM Exception 11" that was causing pr#114's build to fail (https://travis-ci.org/pretenderjs/pretender/builds/90093794#L307). Moving the xhr.open to before the createHandler execution means that we don't try and copy the status until after xhr.send, when the readyState is > 1.

The downside is that the passthrough request doesn't proxy the initial readystatechange event. Another solution could be to upgrade phantomjs to 2.x - although getting a linux binary that works on travis might not be trivial.

Also, for neatness - I should really have moved it to below the createUploadHandler definition rather than above - will do that.

If this is to fix issues with jQuery 1.x, the test suite needs to be updated to run integration tests against both jQuery 1.x and 2.x or we'll have regressions.

Also, on retrospect, I agree - will take a look at adding tests for jQuery 1 and 2 at some point this weekend.

trek added a commit that referenced this pull request Dec 11, 2015
@trek trek merged commit 44a0b00 into pretenderjs:master Dec 11, 2015
@trek
Copy link
Member

trek commented Dec 11, 2015

Looks good!

@trek trek mentioned this pull request Dec 11, 2015
arm1n added a commit to arm1n/ember-cli-mirage that referenced this pull request Jun 9, 2016
Unfortunately there's a bug in pretender.js library, which makes AJAX requests fail within testrunners.

pretenderjs/pretender#130
arm1n added a commit to arm1n/ember-cli-mirage that referenced this pull request Jun 9, 2016
Unfortunately there's a bug in pretender.js library, which makes AJAX requests fail within testrunners.
Please refer to: pretenderjs/pretender#130
jeremy-w added a commit to jeremy-w/mirage-xhr-hanging-repro that referenced this pull request Jul 13, 2016
The app this is based on originally used an older Mirage.
The npm dependencies were updated to the newer, but not the bower.

It was hoped this would fix the issue by incorporating the fix
for pretenderjs/pretender#85
via pretenderjs/pretender#130
as part of the move past Pretender version 0.11.0
(https://github.com/pretenderjs/pretender/blob/master/CHANGELOG.md#0110),
but, surprisingly, that did *not* fix the issue.

Well, this is frustrating.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants