@@ -18,7 +18,7 @@ import {RElement, RNode, RText} from '../interfaces/renderer_dom';
1818import { SanitizerFn } from '../interfaces/sanitization' ;
1919import { HEADER_OFFSET , LView , RENDERER , TView } from '../interfaces/view' ;
2020import { createCommentNode , createElementNode , createTextNode , nativeInsertBefore , nativeParentNode , nativeRemoveNode , updateTextNode } from '../node_manipulation' ;
21- import { getBindingIndex , lastNodeWasCreated } from '../state' ;
21+ import { getBindingIndex , lastNodeWasCreated , wasLastNodeCreated } from '../state' ;
2222import { renderStringify } from '../util/stringify_utils' ;
2323import { getNativeByIndex , unwrapRNode } from '../util/view_utils' ;
2424
@@ -78,12 +78,9 @@ export function applyI18n(tView: TView, lView: LView, index: number) {
7878 changeMaskCounter = 0 ;
7979}
8080
81- function locateOrCreateNode (
82- lView : LView , index : number , textOrName : string ,
81+ function createNodeWithoutHydration (
82+ lView : LView , textOrName : string ,
8383 nodeType : typeof Node . COMMENT_NODE | typeof Node . TEXT_NODE | typeof Node . ELEMENT_NODE ) {
84- // TODO: Add support for hydration
85- lastNodeWasCreated ( true ) ;
86-
8784 const renderer = lView [ RENDERER ] ;
8885
8986 switch ( nodeType ) {
@@ -98,6 +95,23 @@ function locateOrCreateNode(
9895 }
9996}
10097
98+ let _locateOrCreateNode : typeof locateOrCreateNodeImpl = ( lView , index , textOrName , nodeType ) => {
99+ lastNodeWasCreated ( true ) ;
100+ return createNodeWithoutHydration ( lView , textOrName , nodeType ) ;
101+ } ;
102+
103+ function locateOrCreateNodeImpl (
104+ lView : LView , index : number , textOrName : string ,
105+ nodeType : typeof Node . COMMENT_NODE | typeof Node . TEXT_NODE | typeof Node . ELEMENT_NODE ) {
106+ // TODO: Add support for hydration
107+ lastNodeWasCreated ( true ) ;
108+ return createNodeWithoutHydration ( lView , textOrName , nodeType ) ;
109+ }
110+
111+ export function enableLocateOrCreateI18nNodeImpl ( ) {
112+ _locateOrCreateNode = locateOrCreateNodeImpl ;
113+ }
114+
101115/**
102116 * Apply `I18nCreateOpCodes` op-codes as stored in `TI18n.create`.
103117 *
@@ -121,13 +135,15 @@ export function applyCreateOpCodes(
121135 ( opCode & I18nCreateOpCode . APPEND_EAGERLY ) === I18nCreateOpCode . APPEND_EAGERLY ;
122136 const index = opCode >>> I18nCreateOpCode . SHIFT ;
123137 let rNode = lView [ index ] ;
138+ let lastNodeWasCreated = false ;
124139 if ( rNode === null ) {
125140 // We only create new DOM nodes if they don't already exist: If ICU switches case back to a
126141 // case which was already instantiated, no need to create new DOM nodes.
127142 rNode = lView [ index ] =
128- locateOrCreateNode ( lView , index , text , isComment ? Node . COMMENT_NODE : Node . TEXT_NODE ) ;
143+ _locateOrCreateNode ( lView , index , text , isComment ? Node . COMMENT_NODE : Node . TEXT_NODE ) ;
144+ lastNodeWasCreated = wasLastNodeCreated ( ) ;
129145 }
130- if ( appendNow && parentRNode !== null ) {
146+ if ( appendNow && parentRNode !== null && lastNodeWasCreated ) {
131147 nativeInsertBefore ( renderer , parentRNode , rNode , insertInFrontOf , false ) ;
132148 }
133149 }
@@ -160,7 +176,7 @@ export function applyMutableOpCodes(
160176 if ( lView [ textNodeIndex ] === null ) {
161177 ngDevMode && ngDevMode . rendererCreateTextNode ++ ;
162178 ngDevMode && assertIndexInRange ( lView , textNodeIndex ) ;
163- lView [ textNodeIndex ] = locateOrCreateNode ( lView , textNodeIndex , opCode , Node . TEXT_NODE ) ;
179+ lView [ textNodeIndex ] = _locateOrCreateNode ( lView , textNodeIndex , opCode , Node . TEXT_NODE ) ;
164180 }
165181 } else if ( typeof opCode == 'number' ) {
166182 switch ( opCode & IcuCreateOpCode . MASK_INSTRUCTION ) {
@@ -238,7 +254,7 @@ export function applyMutableOpCodes(
238254 ngDevMode && ngDevMode . rendererCreateComment ++ ;
239255 ngDevMode && assertIndexInExpandoRange ( lView , commentNodeIndex ) ;
240256 const commentRNode = lView [ commentNodeIndex ] =
241- locateOrCreateNode ( lView , commentNodeIndex , commentValue , Node . COMMENT_NODE ) ;
257+ _locateOrCreateNode ( lView , commentNodeIndex , commentValue , Node . COMMENT_NODE ) ;
242258 // FIXME(misko): Attaching patch data is only needed for the root (Also add tests)
243259 attachPatchData ( commentRNode , lView ) ;
244260 }
@@ -255,7 +271,7 @@ export function applyMutableOpCodes(
255271 ngDevMode && ngDevMode . rendererCreateElement ++ ;
256272 ngDevMode && assertIndexInExpandoRange ( lView , elementNodeIndex ) ;
257273 const elementRNode = lView [ elementNodeIndex ] =
258- locateOrCreateNode ( lView , elementNodeIndex , tagName , Node . ELEMENT_NODE ) ;
274+ _locateOrCreateNode ( lView , elementNodeIndex , tagName , Node . ELEMENT_NODE ) ;
259275 // FIXME(misko): Attaching patch data is only needed for the root (Also add tests)
260276 attachPatchData ( elementRNode , lView ) ;
261277 }
0 commit comments