@@ -19,7 +19,7 @@ import {getFirstNativeNode} from '../render3/node_manipulation';
1919import { ɵɵresolveBody } from '../render3/util/misc_utils' ;
2020import { renderStringify } from '../render3/util/stringify_utils' ;
2121import { getNativeByTNode , unwrapRNode } from '../render3/util/view_utils' ;
22- import { assertDefined } from '../util/assert' ;
22+ import { assertDefined , assertEqual } from '../util/assert' ;
2323
2424import { compressNodeLocation , decompressNodeLocation } from './compression' ;
2525import {
@@ -408,11 +408,19 @@ export function gatherDeferBlocksCommentNodes(
408408
409409 const nodesByBlockId = new Map < string , Comment > ( ) ;
410410 while ( ( currentNode = commentNodesIterator . nextNode ( ) as Comment ) ) {
411- // TODO(incremental-hydration: convert this to use string parsing rather than regex
412- const regex = new RegExp ( / ^ \s * n g h = ( d [ 0 - 9 ] + ) / g) ;
413- const result = regex . exec ( currentNode ?. textContent ?? '' ) ;
414- if ( result && result ?. length > 0 ) {
415- nodesByBlockId . set ( result [ 1 ] , currentNode ) ;
411+ const nghPattern = 'ngh=' ;
412+ const content = currentNode ?. textContent ;
413+ const nghIdx = content ?. indexOf ( nghPattern ) ?? - 1 ;
414+ if ( nghIdx > - 1 ) {
415+ const nghValue = content ! . substring ( nghIdx + nghPattern . length ) . trim ( ) ;
416+ // Make sure the value has an expected format.
417+ ngDevMode &&
418+ assertEqual (
419+ nghValue . startsWith ( 'd' ) ,
420+ true ,
421+ 'Invalid defer block id found in a comment node.' ,
422+ ) ;
423+ nodesByBlockId . set ( nghValue , currentNode ) ;
416424 }
417425 }
418426 return nodesByBlockId ;
0 commit comments