gihankarunarathne / jquery-stream

Automatically exported from code.google.com/p/jquery-stream
0 stars 0 forks source link

Initial chunk of streaming response is dropped in IE #50

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
When I open a streaming connection in IE (using the hidden iframe transport), 
the first 6-8 messages are dropped entirely. 

Background:

My server is sending raw json data delimited by a custom string, i.e.

{"someInitialJsonData":["A","B","C"]}CUSTOM_DELIMITER{"someDataUpdate":4}CUSTOM_
DELIMITER ... etc etc 

Firefox works fine - it displays the initial data payload, followed by realtime 
updates. However, i.e. misses the initial payload. 

I am requesting the data using the standard $.stream() method, overriding the 
handleOpen/handleMessage for my custom stream.

I've tracked this down to the code snippet below (line 585 in version 1.2). 
When I enter this block, the response variable correctly contains all the 
initial messages. However, after the manipulation of the cdoc head, the 
innerText of cdoc.body.lastChild is blank, and when response is re-assigned, 
the data vanishes.

To solve this, I've implemented the following fix, which saves the response in 
a separate variable, and then re-injects it into the cdoc body. Can you please 
advise whether this fix has any unintended consequences, and consider merging 
it into the next release?

// To support text/html content type
if (!$.nodeName(response, "pre")) {
        // etc etc...               
    head.insertBefore(script, head.firstChild);
    head.removeChild(script);

    // save the reponse!
    var originalResponse = response;
    // The plaintext element will be the response container
    response = cdoc.body.lastChild;
    // re-append the data so it is not lost....
    response.appendChild(cdoc.createTextNode( originalResponse.data));
}

What steps will reproduce the problem?
1. Try to stream data in a custom fashion using the $.stream() api method and 
overriding the handleOpen/handleMessage methods in IE7

What is the expected output? What do you see instead?
I should receive all data received by the server. Instead, the first 6-8 
messages are dropped.

What version of the product are you using? On what operating system?

jQuery Version 1.2 with jQuery 1.7.1 on WindowsXP with IE7.

Please provide any additional information below.

Original issue reported on code.google.com by deganii on 7 Feb 2012 at 7:53

GoogleCodeExporter commented 9 years ago
It seems that the stream response's content type is text/html and there is no 
padding. Is it right? 

It's best to use text/plain response with padding if possible because if the 
content type of the response is text/html, the first chunk will be interpreted 
as HTML and its interpreted content will be unreliable. 

Thanks for the patch and I'll test and commit the patch.

Original comment by flowersi...@gmail.com on 8 Feb 2012 at 3:36