@@ -10,6 +10,7 @@ import {
1010 ELEMENT_ID ,
1111 ELEMENT_ID_PREFIX ,
1212 QContainerAttr ,
13+ QCtxAttr ,
1314 QHostAttr ,
1415 QObjAttr ,
1516 QSeqAttr ,
@@ -87,6 +88,7 @@ export function resumeContainer(containerEl: Element) {
8788
8889 const seq = el . getAttribute ( QSeqAttr ) ! ;
8990 const host = el . getAttribute ( QHostAttr ) ! ;
91+ const contexts = el . getAttribute ( QCtxAttr ) ! ;
9092 const ctx = getContext ( el ) ;
9193
9294 // Restore captured objets
@@ -109,16 +111,14 @@ export function resumeContainer(containerEl: Element) {
109111 ctx . props = ctx . refMap . get ( props ) ;
110112 ctx . renderQrl = ctx . refMap . get ( renderQrl ) ;
111113 }
112-
113- const attributes = el . attributes ;
114- for ( let i = 0 ; i < attributes . length ; i ++ ) {
115- const attr = attributes . item ( i ) ! ;
116- if ( attr . name . startsWith ( 'ctx:' ) ) {
114+ if ( contexts ) {
115+ contexts . split ( ' ' ) . map ( ( part ) => {
116+ const [ key , value ] = part . split ( '=' ) ;
117117 if ( ! ctx . contexts ) {
118118 ctx . contexts = new Map ( ) ;
119119 }
120- ctx . contexts . set ( attr . name . slice ( 'ctx:' . length ) , ctx . refMap . get ( strToInt ( attr . value ) ) ) ;
121- }
120+ ctx . contexts . set ( key , ctx . refMap . get ( strToInt ( value ) ) ) ;
121+ } ) ;
122122 }
123123 } ) ;
124124 containerEl . setAttribute ( QContainerAttr , 'resumed' ) ;
@@ -160,7 +160,7 @@ export function snapshotState(containerEl: Element): SnapshotResult {
160160 // TODO: improve serialization, get rid of refMap
161161 const hasListeners = ctx . listeners && ctx . listeners . size > 0 ;
162162 const hasWatch = ctx . refMap . array . some ( isWatchCleanup ) ;
163- const hasContext = ctx . refMap . array . some ( isWatchCleanup ) ;
163+ const hasContext = ! ! ctx . contexts ;
164164 if ( hasListeners || hasWatch || hasContext ) {
165165 collectElement ( node , collector ) ;
166166 }
@@ -327,9 +327,11 @@ export function snapshotState(containerEl: Element): SnapshotResult {
327327 }
328328
329329 if ( contexts ) {
330+ const serializedContexts : string [ ] = [ ] ;
330331 contexts . forEach ( ( value , key ) => {
331- node . setAttribute ( `ctx: ${ key } ` , ` ${ ctx . refMap . indexOf ( value ) } `) ;
332+ serializedContexts . push ( ` ${ key } = ${ ctx . refMap . indexOf ( value ) } `) ;
332333 } ) ;
334+ node . setAttribute ( QCtxAttr , serializedContexts . join ( ' ' ) ) ;
333335 }
334336 } ) ;
335337
0 commit comments