@@ -62,7 +62,8 @@ function prepNewBodyScriptTagsToRun(newBody, oldBodyScriptTagHashes) {
62
62
}
63
63
64
64
function mergeNewHead ( newHead ) {
65
- let headChildrenHtmlLookup = Array . from ( document . head . children ) . map ( i => i . outerHTML )
65
+ let children = Array . from ( document . head . children )
66
+ let headChildrenHtmlLookup = children . map ( i => i . outerHTML )
66
67
67
68
// Only add scripts and styles that aren't already loaded on the page.
68
69
let garbageCollector = document . createDocumentFragment ( )
@@ -71,9 +72,9 @@ function mergeNewHead(newHead) {
71
72
if ( isAsset ( child ) ) {
72
73
if ( ! headChildrenHtmlLookup . includes ( child . outerHTML ) ) {
73
74
if ( isTracked ( child ) ) {
74
- setTimeout ( ( ) => window . location . reload ( ) )
75
-
76
- return
75
+ if ( ifTheQueryStringChangedSinceLastRequest ( child , children ) ) {
76
+ setTimeout ( ( ) => window . location . reload ( ) )
77
+ }
77
78
}
78
79
79
80
if ( isScript ( child ) ) {
@@ -117,6 +118,25 @@ function isTracked(el) {
117
118
return el . hasAttribute ( 'data-navigate-track' )
118
119
}
119
120
121
+ function ifTheQueryStringChangedSinceLastRequest ( el , currentHeadChildren ) {
122
+ let [ uri , queryString ] = extractUriAndQueryString ( el )
123
+
124
+ return currentHeadChildren . some ( child => {
125
+ if ( ! isTracked ( child ) ) return false
126
+
127
+ let [ currentUri , currentQueryString ] = extractUriAndQueryString ( child )
128
+
129
+ // Only consider a data-navigate-track element changed if the query string has changed (not the URI)...
130
+ if ( currentUri === uri && queryString !== currentQueryString ) return true
131
+ } )
132
+ }
133
+
134
+ function extractUriAndQueryString ( el ) {
135
+ let url = isScript ( el ) ? el . src : el . href
136
+
137
+ return url . split ( '?' )
138
+ }
139
+
120
140
function isAsset ( el ) {
121
141
return ( el . tagName . toLowerCase ( ) === 'link' && el . getAttribute ( 'rel' ) . toLowerCase ( ) === 'stylesheet' )
122
142
|| el . tagName . toLowerCase ( ) === 'style'
0 commit comments