@@ -12,6 +12,15 @@ declare const htmx: typeof htmxType;
1212( function ( ) {
1313 let api : HtmxApi ;
1414
15+ // Helper function to detect chunked transfer (HTTP/1.1) or streaming (HTTP/2)
16+ function isChunkedTransfer ( xhr : XMLHttpRequest ) : boolean {
17+ const te = xhr . getResponseHeader ( "Transfer-Encoding" ) ;
18+ const cl = xhr . getResponseHeader ( "Content-Length" ) ;
19+ const isHttp1Chunked = te === "chunked" ;
20+ const isStreamingWithoutLength = ! te && ! cl ; // typical HTTP/2 streaming
21+ return isHttp1Chunked || isStreamingWithoutLength ;
22+ }
23+
1524 htmx . defineExtension ( "chunked-transfer" , {
1625 init : function ( apiRef : HtmxApi ) {
1726 api = apiRef ;
@@ -27,10 +36,10 @@ declare const htmx: typeof htmxType;
2736 ( xhr as any ) . _chunkedLastLen = 0 ;
2837
2938 xhr . onprogress = function ( ) {
30- const is_chunked =
31- xhr . getResponseHeader ( "Transfer-Encoding" ) === "chunked" ;
39+ if ( ! isChunkedTransfer ( xhr ) ) return ;
3240
33- if ( ! is_chunked ) return ;
41+ const swapSpec = api . getSwapSpecification ( elt ) ;
42+ if ( swapSpec . swapStyle !== "innerHTML" ) return ;
3443
3544 const mode = ( xhr as any ) . _chunkedMode || "append" ;
3645 const full = ( xhr . response as string ) ?? "" ;
@@ -55,7 +64,6 @@ declare const htmx: typeof htmxType;
5564 response = extension . transformResponse ( response , xhr , elt ) ;
5665 } ) ;
5766
58- const swapSpec = api . getSwapSpecification ( elt ) ;
5967 const settleInfo = api . makeSettleInfo ( elt ) ;
6068
6169 if ( api . swap ) {
@@ -85,9 +93,7 @@ declare const htmx: typeof htmxType;
8593 const mode = ( xhr as any ) . _chunkedMode ;
8694 if ( mode !== "swap" ) return ;
8795
88- const is_chunked =
89- xhr . getResponseHeader ( "Transfer-Encoding" ) === "chunked" ;
90- if ( ! is_chunked ) return ;
96+ if ( ! isChunkedTransfer ( xhr ) ) return ;
9197
9298 detail . shouldSwap = false ;
9399 }
@@ -134,13 +140,13 @@ interface SwapSpec {
134140}
135141
136142interface SwapOptions {
137- select : string ;
138- selectOOB : string ;
139- eventInfo : Object ;
140- anchor : Element ;
141- contextElement : Element ;
142- afterSwapCallback : ( ) => void ;
143- afterSettleCallback : ( ) => void ;
143+ select ? : string ;
144+ selectOOB ? : string ;
145+ eventInfo ? : Object ;
146+ anchor ? : Element ;
147+ contextElement ? : Element ;
148+ afterSwapCallback ? : ( ) => void ;
149+ afterSettleCallback ? : ( ) => void ;
144150}
145151
146152interface SettleInfo {
0 commit comments