@@ -194,18 +194,38 @@ async function serveSiteRoutes(requestURL: URL, request: NextRequest) {
194194 ) ;
195195 routeType = routeTypeFromPathname ?? routeType ;
196196
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+
197215 const route = [
198216 'sites' ,
199217 routeType ,
200218 mode ,
201219 encodeURIComponent ( siteURLWithoutProtocol ) ,
202220 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+ )
209229 ) ,
210230 pathname ,
211231 ] . join ( '/' ) ;
0 commit comments