@@ -45,7 +45,6 @@ import {
4545 createTView ,
4646 getInitialLViewFlagsFromDef ,
4747 getOrCreateComponentTView ,
48- getOrCreateTNode ,
4948 initializeDirectives ,
5049 invokeDirectivesHostBindings ,
5150 locateHostElement ,
@@ -76,8 +75,7 @@ import {
7675} from './interfaces/view' ;
7776import { MATH_ML_NAMESPACE , SVG_NAMESPACE } from './namespaces' ;
7877
79- import { createElementNode } from './dom_node_manipulation' ;
80- import { setupStaticAttributes } from './node_manipulation' ;
78+ import { createElementNode , setupStaticAttributes } from './dom_node_manipulation' ;
8179import {
8280 extractAttrsAndClassesFromSelector ,
8381 stringifyCSSSelectorList ,
@@ -93,6 +91,7 @@ import {unregisterLView} from './interfaces/lview_tracking';
9391import { executeContentQueries } from './queries/query_execution' ;
9492import { AttributeMarker } from './interfaces/attribute_marker' ;
9593import { CssSelector } from './interfaces/projection' ;
94+ import { getOrCreateTNode } from './tnode_manipulation' ;
9695
9796export class ComponentFactoryResolver extends AbstractComponentFactoryResolver {
9897 /**
@@ -339,6 +338,8 @@ export class ComponentFactory<T> extends AbstractComponentFactory<T> {
339338 hydrationInfo ,
340339 ) ;
341340
341+ rootLView [ HEADER_OFFSET ] = hostRNode ;
342+
342343 // rootView is the parent when bootstrapping
343344 // TODO(misko): it looks like we are entering view here but we don't really need to as
344345 // `renderView` does that. However as the code is written it is needed because
@@ -347,7 +348,6 @@ export class ComponentFactory<T> extends AbstractComponentFactory<T> {
347348 enterView ( rootLView ) ;
348349
349350 let component : T ;
350- let tElementNode : TElementNode ;
351351 let componentView : LView | null = null ;
352352
353353 try {
@@ -369,13 +369,21 @@ export class ComponentFactory<T> extends AbstractComponentFactory<T> {
369369 rootDirectives = [ rootComponentDef ] ;
370370 }
371371
372- const hostTNode = createRootComponentTNode ( rootLView , hostRNode ) ;
373372 // If host dom element is created (instead of being provided as part of the dynamic component creation), also apply attributes and classes extracted from component selector.
374373 const tAttributes = rootSelectorOrNode
375374 ? [ 'ng-version' , '0.0.0-PLACEHOLDER' ]
376375 : // Extract attributes and classes from the first selector only to match VE behavior.
377376 getRootTAttributesFromSelector ( this . componentDef . selectors [ 0 ] ) ;
378377
378+ // TODO: this logic is shared with the element instruction first create pass
379+ const hostTNode = getOrCreateTNode (
380+ rootTView ,
381+ HEADER_OFFSET ,
382+ TNodeType . Element ,
383+ '#host' ,
384+ tAttributes ,
385+ ) ;
386+
379387 for ( const def of rootDirectives ) {
380388 hostTNode . mergedAttrs = mergeHostAttrs ( hostTNode . mergedAttrs , def . hostAttrs ) ;
381389 }
@@ -399,8 +407,6 @@ export class ComponentFactory<T> extends AbstractComponentFactory<T> {
399407 environment ,
400408 ) ;
401409
402- tElementNode = getTNode ( rootTView , HEADER_OFFSET ) as TElementNode ;
403-
404410 if ( projectableNodes !== undefined ) {
405411 projectNodes ( hostTNode , this . ngContentSelectors , projectableNodes ) ;
406412 }
@@ -428,12 +434,13 @@ export class ComponentFactory<T> extends AbstractComponentFactory<T> {
428434 leaveView ( ) ;
429435 }
430436
437+ const hostTNode = getTNode ( rootTView , HEADER_OFFSET ) as TElementNode ;
431438 return new ComponentRef (
432439 this . componentType ,
433440 component ,
434- createElementRef ( tElementNode , rootLView ) ,
441+ createElementRef ( hostTNode , rootLView ) ,
435442 rootLView ,
436- tElementNode ,
443+ hostTNode ,
437444 ) ;
438445 } finally {
439446 setActiveConsumer ( prevConsumer ) ;
@@ -518,19 +525,6 @@ export class ComponentRef<T> extends AbstractComponentRef<T> {
518525/** Represents a HostFeature function. */
519526type HostFeature = < T > ( component : T , componentDef : ComponentDef < T > ) => void ;
520527
521- /** Creates a TNode that can be used to instantiate a root component. */
522- function createRootComponentTNode ( lView : LView , rNode : RNode ) : TElementNode {
523- const tView = lView [ TVIEW ] ;
524- const index = HEADER_OFFSET ;
525- ngDevMode && assertIndexInRange ( lView , index ) ;
526- lView [ index ] = rNode ;
527-
528- // '#host' is added here as we don't know the real host DOM name (we don't want to read it) and at
529- // the same time we want to communicate the debug `TNode` that this is a special `TNode`
530- // representing a host element.
531- return getOrCreateTNode ( tView , index , TNodeType . Element , '#host' , null ) ;
532- }
533-
534528/**
535529 * Creates the root component view and the root component node.
536530 *
0 commit comments