File tree Expand file tree Collapse file tree
packages/react-devtools-shared/src/__tests__ Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3616,4 +3616,58 @@ describe('Store', () => {
36163616 <div>
36173617 ` ) ;
36183618 } ) ;
3619+
3620+ it ( 'cleans up host hoistables' , async ( ) => {
3621+ function Left ( ) {
3622+ return (
3623+ < style href = "test.css" precedence = "medium" >
3624+ { '* {color:black}' }
3625+ </ style >
3626+ ) ;
3627+ }
3628+
3629+ function Right ( ) {
3630+ return (
3631+ < style href = "test.css" precedence = "medium" >
3632+ { '* {color:black}' }
3633+ </ style >
3634+ ) ;
3635+ }
3636+
3637+ await actAsync ( ( ) => {
3638+ render (
3639+ < >
3640+ < Left />
3641+ < Right />
3642+ </ > ,
3643+ ) ;
3644+ } ) ;
3645+
3646+ // Ensure we're still testing deduplicated hoistables.
3647+ expect ( document . head . querySelectorAll ( 'style' ) ) . toHaveLength ( 1 ) ;
3648+ expect ( store ) . toMatchInlineSnapshot ( `
3649+ [root]
3650+ <Left>
3651+ <Right>
3652+ ` ) ;
3653+ let style = document . head . querySelector ( 'style' ) ;
3654+ let styleID = agent . getIDForHostInstance ( style ) . id ;
3655+ expect ( store . containsElement ( styleID ) ) . toBe ( true ) ;
3656+
3657+ await actAsync ( ( ) => {
3658+ render (
3659+ < >
3660+ < Right />
3661+ </ > ,
3662+ ) ;
3663+ } ) ;
3664+
3665+ expect ( store ) . toMatchInlineSnapshot ( `
3666+ [root]
3667+ <Right>
3668+ ` ) ;
3669+ style = document . head . querySelector ( 'style' ) ;
3670+ styleID = agent . getIDForHostInstance ( style ) . id ;
3671+ expect ( store . containsElement ( styleID ) ) . toBe ( false ) ;
3672+ } ) ;
36193673} ) ;
You can’t perform that action at this time.
0 commit comments