From 980caf00c136929f080c23fea6be0349210bb9be Mon Sep 17 00:00:00 2001 From: Dmitrii Troitskii Date: Sat, 2 May 2026 10:58:48 +0000 Subject: [PATCH] fix: re-create disconnected style resource instances in acquireResource When a , + portalTarget, + )} + +
content
+ + ); + } + + const root = ReactDOMClient.createRoot(container); + await clientAct(() => { + root.render(); + }); + + // Both the portal render and the main-tree render share the same resource. + // After the first render the style should be in the document head. + const stylesBefore = document.head.querySelectorAll( + '[data-href="x"][data-precedence="custom"]', + ); + expect(stylesBefore.length).toBe(1); + + // Remove the portal target (simulates unmounting a detached portal container). + portalTarget.remove(); + + // Re-render to force a fresh acquireResource call with the same href. + await clientAct(() => { + setState(false); // hide portal, only main-tree style remains + }); + + // The style should still exist in the document — if the fix is absent, + // the cached-but-disconnected instance would be returned and the style + // would be gone from the document. + const stylesAfter = document.head.querySelectorAll( + '[data-href="x"][data-precedence="custom"]', + ); + expect(stylesAfter.length).toBeGreaterThanOrEqual(1); + + root.unmount(); + container.remove(); + }); }); describe('Script Resources', () => {