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

3rd party XHR request still intercepted in spite of passthrough #1320

Closed
allthesignals opened this issue May 20, 2018 · 11 comments
Closed

3rd party XHR request still intercepted in spite of passthrough #1320

allthesignals opened this issue May 20, 2018 · 11 comments
Labels

Comments

@allthesignals
Copy link
Contributor

allthesignals commented May 20, 2018

May be related to #285, the 3rd party lib I'm using is MapboxGL.

Here are all my passthroughs:

  this.passthrough('https://raw.githubusercontent.com/**');
  this.passthrough('http://raw.githubusercontent.com/**');
  this.passthrough('https://tiles.planninglabs.nyc/**');
  this.passthrough('http://tiles.planninglabs.nyc/**');

Console just throws AJAXError {status: 200}

image

After setting up breakpoints, the actual response 3rd party lib gets from pretender is undefined:

ajax.getJSON(request, function (error, json) { } // error = AJAXError {status: 200}, json = undefined

I'm not sure where this problem is coming from. One of the requests, https://raw.githubusercontent.com/NYCPlanning/labs-gl-style/master/data/style.json, gives strange errors when you try to visit it directly. I'm not sure if the headers are confusing pretender in someway. Any ideas?

Full stacktrace
server.js:22 Passthrough request: GET //raw.githubusercontent.com/NYCPlanning/labs-gl-style/master/data/style.json
server.js:28 Mirage: [200] GET /api/sources
mapbox-gl-dev.js:40253 AJAXError {status: 200}status: 200__proto__: Error
fire @ mapbox-gl-dev.js:40253
(anonymous) @ mapbox-gl-dev.js:27330
xhr.onload @ mapbox-gl-dev.js:39705
(anonymous) @ fake_xml_http_request.js:137
dispatchEvent @ fake_xml_http_request.js:181
dispatchEvent @ pretender.js:216
xhr.(anonymous function) @ pretender.js:226
load (async)
createHandler @ pretender.js:224
createPassthrough @ pretender.js:242
send @ pretender.js:166
exports.getJSON @ mapbox-gl-dev.js:39708
loadURL @ mapbox-gl-dev.js:27328
setStyle @ mapbox-gl-dev.js:37965
Map @ mapbox-gl-dev.js:37369
_setup @ mapbox-gl.js:49
invoke @ backburner.js:205
flush @ backburner.js:125
flush @ backburner.js:278
end @ backburner.js:410
_run @ backburner.js:760
_join @ backburner.js:736
join @ backburner.js:477
run.join @ ember-metal.js:4366
(anonymous) @ ember-metal.js:4441
mightThrow @ jquery.js:3534
process @ jquery.js:3602
setTimeout (async)
(anonymous) @ jquery.js:3640
fire @ jquery.js:3268
fireWith @ jquery.js:3398
fire @ jquery.js:3406
fire @ jquery.js:3268
fireWith @ jquery.js:3398
ready @ jquery.js:3878
completed @ jquery.js:3888
mapbox-gl-dev.js:40253 AJAXError {status: 200}
fire @ mapbox-gl-dev.js:40253
(anonymous) @ mapbox-gl-dev.js:27330
xhr.onload @ mapbox-gl-dev.js:39705
dispatchEvent @ pretender.js:218
xhr.(anonymous function) @ pretender.js:226
load (async)
createHandler @ pretender.js:224
createPassthrough @ pretender.js:242
send @ pretender.js:166
exports.getJSON @ mapbox-gl-dev.js:39708
loadURL @ mapbox-gl-dev.js:27328
setStyle @ mapbox-gl-dev.js:37965
Map @ mapbox-gl-dev.js:37369
_setup @ mapbox-gl.js:49
invoke @ backburner.js:205
flush @ backburner.js:125
flush @ backburner.js:278
end @ backburner.js:410
_run @ backburner.js:760
_join @ backburner.js:736
join @ backburner.js:477
run.join @ ember-metal.js:4366
(anonymous) @ ember-metal.js:4441
mightThrow @ jquery.js:3534
process @ jquery.js:3602
setTimeout (async)
(anonymous) @ jquery.js:3640
fire @ jquery.js:3268
fireWith @ jquery.js:3398
fire @ jquery.js:3406
fire @ jquery.js:3268
fireWith @ jquery.js:3398
ready @ jquery.js:3878
completed @ jquery.js:3888
@samselikoff
Copy link
Collaborator

Thanks for the details & sorry you're running into this!

Any chance you could post a simplified reproduction somewhere?

@allthesignals
Copy link
Contributor Author

Thanks, @samselikoff - here's a demo repo: https://github.com/allthesignals/ember-mirage-mapbox-example, it's simply a clone of ember-mapbox-gl with mirage installed & configured. See console for errors.

Looping in @kturney who pointed out the PR here: pretenderjs/FakeXMLHttpRequest#32. It seems to be more of a Pretender issue, and might be addressed if that PR gets merged.

@billdami
Copy link

@allthesignals seeing this same issue with ember-cli-mirage/ember-mapbox-gl. Were you ever able to figure out a workaround?

@kturney
Copy link

kturney commented Jun 26, 2018

@billdami we managed to monkeypatch it. See here: kturney/ember-mapbox-gl#53 (comment)

@billdami
Copy link

@kturney great thanks!

@samselikoff
Copy link
Collaborator

Catching up with issues here... so if the Pretender PR gets merged this should be fixed? Is that correct?

@kturney
Copy link

kturney commented Aug 10, 2018

@samselikoff I'm unsure if just that pr will fix the issue. The above linked monkeypatch also had to work around the load event getting triggered twice.

@samselikoff
Copy link
Collaborator

@kturney Thanks for the info.

Is your monkey patch fixing a Mirage bug, a Pretender bug or a Mapbox issue? If it's a Mirage bug, could you walk me through it?

I'm trying to figure out what Mirage's responsibility is here & what the fix is/should be. Once we get that Pretender PR merged, is Mirage's role done?

@kturney
Copy link

kturney commented Nov 16, 2018

@samselikoff It definitely seems like just a Pretender bug.
Ideally someone interested could submit a failing test pr against pretender.
I don't think there's anything in mirage that needs to change.

@samselikoff
Copy link
Collaborator

@kturney Gotcha - thanks for the reply 👍

Does pretenderjs/FakeXMLHttpRequest#32 have the correct failing test?

@kturney
Copy link

kturney commented Nov 19, 2018

That's part of it. Maybe it needs a separate pr/test for not triggering a double load event.

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

No branches or pull requests

4 participants