@@ -95,15 +95,16 @@ export class Core extends Module {
9595 }
9696
9797 private static asyncLoadFragment ( fragment : IPageFragmentConfig ) {
98+ if ( fragment . asyncLoaded ) return ;
99+ fragment . asyncLoaded = true ;
98100 const queryString = this . prepareQueryString ( fragment . attributes ) ;
99- const key = `${ fragment . source } ${ location . pathname } ${ queryString } ` ;
101+ const key = `${ fragment . source } ${ window . location . pathname } ${ queryString } ` ;
100102
101103 if ( ! fragment . asyncDecentralized ) {
102104 return this . fetchGatewayFragment ( fragment )
103105 . then ( res => this . asyncRenderResponse ( fragment , res ) ) ;
104106 }
105107
106-
107108 Core . gun
108109 . get ( key , ( gunResponse : any ) => {
109110 if ( gunResponse . err || ! gunResponse . put ) {
@@ -141,7 +142,7 @@ export class Core extends Module {
141142
142143 private static fetchGatewayFragment ( fragment : IPageFragmentConfig ) {
143144 const queryString = this . prepareQueryString ( fragment . attributes ) ;
144- const fragmentRequestUrl = `${ fragment . source } ${ location . pathname } ${ queryString } ` ;
145+ const fragmentRequestUrl = `${ fragment . source } ${ window . location . pathname } ${ queryString } ` ;
145146 return fetch ( fragmentRequestUrl , {
146147 credentials : 'include'
147148 } )
@@ -183,7 +184,7 @@ export class Core extends Module {
183184 }
184185
185186 private static prepareQueryString ( fragmentAttributes : Record < string , string > ) {
186- const attributes = Object . assign ( location . search . slice ( 1 ) . split ( '&' ) . reduce ( ( dict : { [ name : string ] : string } , i ) => {
187+ const attributes = Object . assign ( window . location . search . slice ( 1 ) . split ( '&' ) . reduce ( ( dict : { [ name : string ] : string } , i ) => {
187188 const [ key , value ] = i . split ( '=' ) ;
188189 if ( typeof value !== "undefined" ) {
189190 dict [ key ] = value ;
@@ -269,6 +270,18 @@ export class Core extends Module {
269270 } ) ;
270271 }
271272
273+ static renderAsyncFragment ( fragmentName : string ) {
274+ const fragment = this . __pageConfiguration . fragments . find ( item => item . name === fragmentName ) ;
275+ if ( fragment ) {
276+ const selector = this . getFragmentContainerSelector ( fragment , "main" ) ;
277+ const fragmentContainer = window . document . querySelector ( selector ) ;
278+ if ( fragmentContainer ) {
279+ if ( this . observer ) this . observer . unobserve ( fragmentContainer ) ;
280+ return this . asyncLoadFragment ( fragment ) ;
281+ }
282+ }
283+ }
284+
272285 private static isIntersectionObserverSupported ( ) {
273286 return 'IntersectionObserver' in window
274287 && 'IntersectionObserverEntry' in window
0 commit comments