mirror of
https://github.com/facebook/react.git
synced 2026-02-21 19:31:52 +00:00
[DevTools] Fix memory leak when unmounting hoistables (#35741)
This commit is contained in:
committed by
GitHub
parent
49c3b270f9
commit
f23aa1d9f5
@@ -3616,4 +3616,59 @@ describe('Store', () => {
|
||||
<div>
|
||||
`);
|
||||
});
|
||||
|
||||
// @reactVersion >= 19
|
||||
it('cleans up host hoistables', async () => {
|
||||
function Left() {
|
||||
return (
|
||||
<style href="test.css" precedence="medium">
|
||||
{'* {color:black}'}
|
||||
</style>
|
||||
);
|
||||
}
|
||||
|
||||
function Right() {
|
||||
return (
|
||||
<style href="test.css" precedence="medium">
|
||||
{'* {color:black}'}
|
||||
</style>
|
||||
);
|
||||
}
|
||||
|
||||
await actAsync(() => {
|
||||
render(
|
||||
<>
|
||||
<Left />
|
||||
<Right />
|
||||
</>,
|
||||
);
|
||||
});
|
||||
|
||||
// Ensure we're still testing deduplicated hoistables.
|
||||
expect(document.head.querySelectorAll('style')).toHaveLength(1);
|
||||
expect(store).toMatchInlineSnapshot(`
|
||||
[root]
|
||||
<Left>
|
||||
<Right>
|
||||
`);
|
||||
let style = document.head.querySelector('style');
|
||||
let styleID = agent.getIDForHostInstance(style).id;
|
||||
expect(store.containsElement(styleID)).toBe(true);
|
||||
|
||||
await actAsync(() => {
|
||||
render(
|
||||
<>
|
||||
<Right />
|
||||
</>,
|
||||
);
|
||||
});
|
||||
|
||||
expect(store).toMatchInlineSnapshot(`
|
||||
[root]
|
||||
<Right>
|
||||
`);
|
||||
style = document.head.querySelector('style');
|
||||
styleID = agent.getIDForHostInstance(style).id;
|
||||
expect(store.containsElement(styleID)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -991,8 +991,8 @@ function releaseHostResource(
|
||||
// eslint-disable-next-line no-for-of-loops/no-for-of-loops
|
||||
for (const firstInstance of resourceInstances) {
|
||||
publicInstanceToDevToolsInstanceMap.set(
|
||||
publicInstance,
|
||||
firstInstance,
|
||||
nearestInstance,
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user