@@ -117,6 +117,10 @@ function verifyNodeHasMismatchInfo(doc: Document, selector = 'app'): void {
117117 expect ( readHydrationInfo ( doc . querySelector ( selector ) ! ) ?. status ) . toBe ( HydrationStatus . Mismatched ) ;
118118}
119119
120+ function verifyNodeHasSkipHydrationMarker ( element : HTMLElement ) : void {
121+ expect ( readHydrationInfo ( element ) ?. status ) . toBe ( HydrationStatus . Skipped ) ;
122+ }
123+
120124/** Checks whether a given element is a <script> that contains transfer state data. */
121125function isTransferStateScript ( el : HTMLElement ) : boolean {
122126 return (
@@ -2744,6 +2748,97 @@ describe('platform-server hydration integration', () => {
27442748 const clientContents = stripExcessiveSpaces ( clientRootNode . innerHTML ) ;
27452749 expect ( clientContents ) . toBe ( '<ol><li>1</li><li>2</li><li>3</li><!--container--></ol>' ) ;
27462750 } ) ;
2751+
2752+ describe ( 'with ngSkipHydration' , ( ) => {
2753+ it ( 'should skip hydration when ngSkipHydration and i18n attributes are present on a same node' , async ( ) => {
2754+ loadTranslations ( {
2755+ [ computeMsgId ( ' Some {$START_TAG_STRONG}strong{$CLOSE_TAG_STRONG} content ' ) ] :
2756+ 'Some normal content' ,
2757+ } ) ;
2758+
2759+ @Component ( {
2760+ standalone : true ,
2761+ selector : 'cmp-a' ,
2762+ template : `<ng-content />` ,
2763+ } )
2764+ class CmpA { }
2765+
2766+ @Component ( {
2767+ standalone : true ,
2768+ selector : 'app' ,
2769+ imports : [ CmpA ] ,
2770+ template : `
2771+ <cmp-a i18n ngSkipHydration>
2772+ Some <strong>strong</strong> content
2773+ </cmp-a>
2774+ ` ,
2775+ } )
2776+ class SimpleComponent { }
2777+
2778+ const hydrationFeatures = [ withI18nSupport ( ) ] as unknown as HydrationFeature < any > [ ] ;
2779+ const html = await ssr ( SimpleComponent , { hydrationFeatures} ) ;
2780+ const ssrContents = getAppContents ( html ) ;
2781+ expect ( ssrContents ) . toContain ( '<app ngh' ) ;
2782+
2783+ resetTViewsFor ( SimpleComponent ) ;
2784+
2785+ const appRef = await renderAndHydrate ( doc , html , SimpleComponent , { hydrationFeatures} ) ;
2786+ const compRef = getComponentRef < SimpleComponent > ( appRef ) ;
2787+ appRef . tick ( ) ;
2788+
2789+ const clientRootNode = compRef . location . nativeElement ;
2790+ verifyAllNodesClaimedForHydration ( clientRootNode ) ;
2791+ verifyClientAndSSRContentsMatch ( ssrContents , clientRootNode ) ;
2792+
2793+ const cmpA = clientRootNode . querySelector ( 'cmp-a' ) ;
2794+ expect ( cmpA . textContent ) . toBe ( 'Some normal content' ) ;
2795+ verifyNodeHasSkipHydrationMarker ( cmpA ) ;
2796+ } ) ;
2797+
2798+ it ( 'should skip hydration when i18n is inside of an ngSkipHydration block' , async ( ) => {
2799+ loadTranslations ( {
2800+ [ computeMsgId ( 'strong' ) ] : 'very strong' ,
2801+ } ) ;
2802+
2803+ @Component ( {
2804+ standalone : true ,
2805+ selector : 'cmp-a' ,
2806+ template : `<ng-content />` ,
2807+ } )
2808+ class CmpA { }
2809+
2810+ @Component ( {
2811+ standalone : true ,
2812+ selector : 'app' ,
2813+ imports : [ CmpA ] ,
2814+ template : `
2815+ <cmp-a ngSkipHydration>
2816+ Some <strong i18n>strong</strong> content
2817+ </cmp-a>
2818+ ` ,
2819+ } )
2820+ class SimpleComponent { }
2821+
2822+ const hydrationFeatures = [ withI18nSupport ( ) ] as unknown as HydrationFeature < any > [ ] ;
2823+ const html = await ssr ( SimpleComponent , { hydrationFeatures} ) ;
2824+ const ssrContents = getAppContents ( html ) ;
2825+ expect ( ssrContents ) . toContain ( '<app ngh' ) ;
2826+
2827+ resetTViewsFor ( SimpleComponent ) ;
2828+
2829+ const appRef = await renderAndHydrate ( doc , html , SimpleComponent , { hydrationFeatures} ) ;
2830+ const compRef = getComponentRef < SimpleComponent > ( appRef ) ;
2831+ appRef . tick ( ) ;
2832+
2833+ const clientRootNode = compRef . location . nativeElement ;
2834+ verifyAllNodesClaimedForHydration ( clientRootNode ) ;
2835+ verifyClientAndSSRContentsMatch ( ssrContents , clientRootNode ) ;
2836+
2837+ const cmpA = clientRootNode . querySelector ( 'cmp-a' ) ;
2838+ expect ( cmpA . textContent . trim ( ) ) . toBe ( 'Some very strong content' ) ;
2839+ verifyNodeHasSkipHydrationMarker ( cmpA ) ;
2840+ } ) ;
2841+ } ) ;
27472842 } ) ;
27482843
27492844 // Note: hydration for i18n blocks is not *yet* fully supported, so the tests
0 commit comments