@@ -194,18 +194,38 @@ async function serveSiteRoutes(requestURL: URL, request: NextRequest) {
194
194
) ;
195
195
routeType = routeTypeFromPathname ?? routeType ;
196
196
197
+ // We pick only stable data from the siteURL data to prevent re-rendering of
198
+ // the root layout when changing pages..
199
+ const stableSiteURLData : Omit < typeof siteURLData , 'pathname' > = {
200
+ site : siteURLData . site ,
201
+ siteSection : siteURLData . siteSection ,
202
+ siteSpace : siteURLData . siteSpace ,
203
+ siteBasePath : siteURLData . siteBasePath ,
204
+ basePath : siteURLData . basePath ,
205
+ space : siteURLData . space ,
206
+ organization : siteURLData . organization ,
207
+ changeRequest : siteURLData . changeRequest ,
208
+ revision : siteURLData . revision ,
209
+ shareKey : siteURLData . shareKey ,
210
+ apiToken : siteURLData . apiToken ,
211
+ complete : siteURLData . complete ,
212
+ contextId : siteURLData . contextId ,
213
+ } ;
214
+
197
215
const route = [
198
216
'sites' ,
199
217
routeType ,
200
218
mode ,
201
219
encodeURIComponent ( siteURLWithoutProtocol ) ,
202
220
encodeURIComponent (
203
- rison . encode ( {
204
- ...siteURLData ,
205
- // The pathname is passed as the next segment of the route and should not cause this segment to change
206
- // based on the page being visited
207
- pathname : '<DO_NOT_USE>' ,
208
- } )
221
+ rison . encode (
222
+ // rison can't encode undefined values
223
+ Object . fromEntries (
224
+ Object . entries ( stableSiteURLData ) . filter (
225
+ ( [ _ , v ] ) => typeof v !== 'undefined'
226
+ )
227
+ )
228
+ )
209
229
) ,
210
230
pathname ,
211
231
] . join ( '/' ) ;
0 commit comments