@@ -69,6 +69,12 @@ describe('SSR', () => {
6969 } ,
7070 } ) ;
7171
72+ const genCardStyle = ( token : DerivativeToken ) : CSSInterpolation => ( {
73+ '.card' : {
74+ backgroundColor : token . primaryColor ,
75+ } ,
76+ } ) ;
77+
7278 const Box = ( { children } : { children ?: React . ReactNode } ) => {
7379 const [ token ] = useCacheToken < DerivativeToken > ( theme , [ baseToken ] ) ;
7480
@@ -79,6 +85,16 @@ describe('SSR', () => {
7985 return wrapSSR ( < div className = "box" > { children } </ div > ) ;
8086 } ;
8187
88+ const Card = ( { children } : { children ?: React . ReactNode } ) => {
89+ const [ token ] = useCacheToken < DerivativeToken > ( theme , [ baseToken ] , {
90+ cssVar : { key : 'css-var-test' } ,
91+ } ) ;
92+
93+ useStyleRegister ( { theme, token, path : [ '.card' ] } , ( ) => [ genCardStyle ( token ) ] ) ;
94+
95+ return < div className = "card" > { children } </ div > ;
96+ } ;
97+
8298 const IdHolder = ( ) => {
8399 const id = React . useId ( ) ;
84100 return (
@@ -441,4 +457,33 @@ describe('SSR', () => {
441457 ] . join ( '' ) ,
442458 ) ;
443459 } ) ;
460+
461+ it ( 'should extract once when once option is true' , ( ) => {
462+ const cache = createCache ( ) ;
463+
464+ renderToString (
465+ < StyleProvider cache = { cache } >
466+ < IdHolder />
467+ < Box >
468+ < IdHolder />
469+ </ Box >
470+ < IdHolder />
471+ </ StyleProvider > ,
472+ ) ;
473+
474+ const style = extractStyle ( cache , { plain : true , once : true } ) ;
475+
476+ renderToString (
477+ < StyleProvider cache = { cache } >
478+ < Card />
479+ </ StyleProvider > ,
480+ ) ;
481+ const style2 = extractStyle ( cache , { plain : true , once : true } ) ;
482+
483+ expect ( style ) . toContain ( '.box' ) ;
484+ expect ( style ) . not . toContain ( '.card' ) ;
485+
486+ expect ( style2 ) . toContain ( '.card' ) ;
487+ expect ( style2 ) . not . toContain ( '.box' ) ;
488+ } )
444489} ) ;
0 commit comments