Skip to content

Commit e4c4587

Browse files
committed
Current behavior
1 parent c6bb26b commit e4c4587

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

packages/react-devtools-shared/src/__tests__/store-test.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff 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
});

0 commit comments

Comments
 (0)