@@ -114,10 +114,15 @@ const registerComponent = <TEl extends object>(
114114export
115115const registerElement = < TEl extends object > (
116116 r : ComponentRegistry < TEl > ,
117- component_id : NodeID ,
117+ component_id : NodeID | null ,
118118 element_id : NodeID ,
119119 element : TEl ,
120120) : void => {
121+ // TODO: also allow registering elements without a component
122+ if ( component_id == null ) {
123+ return
124+ }
125+
121126 let component = r . components . get ( component_id )
122127 if ( component == null ) return
123128
@@ -310,22 +315,22 @@ export function gatherElementMap(
310315}
311316
312317function mapChildren < TEl extends object > (
313- owner : Solid . Owner ,
314- owner_map : Mapped . Owner | null ,
315- config : TreeWalkerConfig < TEl > ,
316- children : Mapped . Owner [ ] = [ ] ,
318+ owner : Solid . Owner ,
319+ component_id : NodeID | null ,
320+ config : TreeWalkerConfig < TEl > ,
321+ children : Mapped . Owner [ ] = [ ] ,
317322) : Mapped . Owner [ ] {
318323
319324 for ( let child of owner_each_child ( owner ) ) {
320325 if ( config . mode === TreeWalkerMode . Owners ||
321326 markOwnerType ( child ) === NodeType . Component
322327 ) {
323- unwrap_append ( children , mapOwner ( child , owner_map , config ) )
328+ unwrap_append ( children , mapOwner ( child , component_id , config ) )
324329 } else {
325330 if ( isSolidComputation ( child ) ) {
326331 observeComputation ( child , owner , config )
327332 }
328- mapChildren ( child , owner_map , config , children )
333+ mapChildren ( child , component_id , config , children )
329334 }
330335 }
331336
@@ -334,12 +339,12 @@ function mapChildren<TEl extends object>(
334339
335340let els_seen = new Set < object > ( )
336341
337- const add_new_el_json = < TEl extends object > (
338- comp_id : NodeID ,
342+ function add_new_el_json < TEl extends object > (
339343 child_arr : Mapped . Owner [ ] ,
340344 el : TEl ,
345+ comp_id : NodeID | null ,
341346 config : TreeWalkerConfig < TEl > ,
342- ) : Mapped . Owner => {
347+ ) : Mapped . Owner {
343348 let el_json : Mapped . Owner = {
344349 id : get_id_el ( el ) ,
345350 type : NodeType . Element ,
@@ -353,9 +358,10 @@ const add_new_el_json = <TEl extends object>(
353358}
354359
355360function mapOwner < TEl extends object > (
356- owner : Solid . Owner ,
357- parent : Mapped . Owner | null ,
358- config : TreeWalkerConfig < TEl > ,
361+ owner : Solid . Owner ,
362+ /** last seen component id - for registering elements to components */
363+ last_comp_id : NodeID | null ,
364+ config : TreeWalkerConfig < TEl > ,
359365) : Mapped . Owner | undefined {
360366
361367 let id = getSdtId ( owner , ObjectType . Owner )
@@ -386,7 +392,7 @@ function mapOwner<TEl extends object>(
386392 owner . owned . length === 1 &&
387393 markOwnerType ( first_owned = owner . owned [ 0 ] ! ) === NodeType . Context
388394 ) {
389- return mapOwner ( first_owned , parent , config )
395+ return mapOwner ( first_owned , last_comp_id , config )
390396 }
391397
392398 // Register component to global map
@@ -400,6 +406,9 @@ function mapOwner<TEl extends object>(
400406 mapped . hmr = true
401407 owner = refresh
402408 }
409+
410+ /* This owner is now last seen component */
411+ last_comp_id = id
403412 }
404413 // Computation
405414 else if ( isSolidComputation ( owner ) ) {
@@ -409,7 +418,7 @@ function mapOwner<TEl extends object>(
409418 }
410419 }
411420
412- mapChildren ( owner , mapped , config , mapped . children )
421+ mapChildren ( owner , last_comp_id , config , mapped . children )
413422
414423 // Map html elements in DOM mode
415424 if ( config . mode === TreeWalkerMode . DOM ) {
@@ -497,7 +506,7 @@ function mapOwner<TEl extends object>(
497506 if ( ! els_seen . has ( el ) ) {
498507 stack_els_arr [ stack_els_len ] = config . eli . getChildren ( el )
499508 stack_els_idx [ stack_els_len ] = 0
500- stack_els_own [ stack_els_len ] = add_new_el_json ( id , el_own . children , el , config )
509+ stack_els_own [ stack_els_len ] = add_new_el_json ( el_own . children , el , last_comp_id , config )
501510 stack_els_len += 1
502511 }
503512 }
@@ -521,7 +530,7 @@ function mapOwner<TEl extends object>(
521530 if ( ! els_seen . has ( el ) ) {
522531 stack_els_arr [ stack_els_len ] = config . eli . getChildren ( el )
523532 stack_els_idx [ stack_els_len ] = 0
524- stack_els_own [ stack_els_len ] = add_new_el_json ( id , el_own . children , el , config )
533+ stack_els_own [ stack_els_len ] = add_new_el_json ( el_own . children , el , last_comp_id , config )
525534 stack_els_len += 1
526535 }
527536 }
0 commit comments