Skip to content
This repository has been archived by the owner on Dec 20, 2020. It is now read-only.

{ responseType: "document" } not supported correctly #132

Open
fluffywaffles opened this issue Oct 27, 2016 · 6 comments
Open

{ responseType: "document" } not supported correctly #132

fluffywaffles opened this issue Oct 27, 2016 · 6 comments
Labels

Comments

@fluffywaffles
Copy link

fluffywaffles commented Oct 27, 2016

Test case:

// expected behavior using XHR:
var myPartial = null
var xhr = new XMLHttpRequest()
xhr.open('GET', '/my/partial.html')
xhr.responseType = 'document'
xhr.onreadystatechange = function () { if (xhr.readyState == 4) myPartial = xhr.responseXML }
xhr.send()

// after a second...
myPartial.body instanceof HTMLElement // => true
// all is well.

// -----------------------------------

// behavior using qwest:
qwest.get('/my/partial.html', null, { responseType: 'document' })
  .then(function (xhr, myPartial) {
    xhr.responseXML // => null?!?!
    myPartial.body.querySelectorAll('div') // Yes, this works...
    myPartial.body instanceof HTMLElement // => false?!?!
    // That's not good. When I try to use this later, exceptions get thrown.
  })
  .catch(function (xhr, error) {
    console.error(error)
  })

I looked at the source code for qwest, and so far as I can tell this makes absolutely no sense. It looks like qwest should just let the responseType pass through into the XMLHttpRequest and everything should just be honky-dory. But instead, the responseXML field is null and the response data, while definitely parsed into DOM, is clearly not quite right since the prototypes don't match.

@pyrsmk
Copy link
Owner

pyrsmk commented Oct 28, 2016

It is weird, indeed. What's the type of body in your case?

@fluffywaffles
Copy link
Author

The response body is "text/html". No special metadata it just has a '.html' extension. It's a partial, so no DOCTYPE no and no top level .

@fluffywaffles
Copy link
Author

The two blanks up there were supposed to be <head> and <body>. They didn't render because I didn't use back ticks!

@pyrsmk
Copy link
Owner

pyrsmk commented Nov 4, 2016

Hum. So, is it working now? ^^

@fluffywaffles
Copy link
Author

No, sorry - I was just explaining why my github comment had blanks in it. :/

@pyrsmk
Copy link
Owner

pyrsmk commented Nov 4, 2016

Ahah ok, I wasn't sure.

Can you debug this by yourself by logging where the code is going in handleResponse()? Or can you publish a working example of your app so I can test this from home?

@pyrsmk pyrsmk added the bug label Nov 28, 2016
@pyrsmk pyrsmk added the v5 label Mar 21, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants