You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previously we restricted Float methods to only being callable while rendering. This allowed us to make associations between calls and their position in the DOM tree, for instance hoisting preinitialized styles into a ShadowRoot or an iframe Document.
When considering how we are going to support Flight support in Float however it became clear that this restriction would lead to compromises on the implementation because the Flight client does not execute within the context of a client render. We want to be able to disaptch Float directives coming from Flight as soon as possible and this requires being able to call them outside of render.
this patch modifies Float so that its methods are callable anywhere. The main consequence of this change is Float will always use the Document the renderer script is running within as the HoistableRoot. This means if you preinit as style inside a component render targeting a ShadowRoot the style will load in the ownerDocument not the ShadowRoot. Practially speaking it means that preinit is not useful inside ShadowRoots and iframes.
This tradeoff was deemed acceptable because these methods are optimistic, not critical. Additionally, the other methods, preconntect, prefetchDNS, and preload, are not impacted because they already operated at the level of the ownerDocument and really only interface with the Network cache layer.
Copy file name to clipboardExpand all lines: packages/react-dom/src/__tests__/ReactDOMFloat-test.js
+49-7Lines changed: 49 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -24,8 +24,6 @@ let ReactDOMFizzServer;
24
24
letSuspense;
25
25
lettextCache;
26
26
letloadCache;
27
-
letwindow;
28
-
letdocument;
29
27
letwritable;
30
28
constCSPnonce=null;
31
29
letcontainer;
@@ -51,8 +49,8 @@ function resetJSDOM(markup) {
51
49
media: query,
52
50
})),
53
51
});
54
-
window=jsdom.window;
55
-
document=jsdom.window.document;
52
+
global.window=jsdom.window;
53
+
global.document=jsdom.window.document;
56
54
}
57
55
58
56
describe('ReactDOMFloat',()=>{
@@ -3750,7 +3748,7 @@ body {
3750
3748
});
3751
3749
3752
3750
// @gate enableFloat
3753
-
it('creates a preload resource when ReactDOM.preinit(..., {as: "style" }) is called outside of render on the client',async()=>{
3751
+
it('creates a stylesheet resource in the ownerDocument when ReactDOM.preinit(..., {as: "style" }) is called outside of render on the client',async()=>{
it('creates a stylesheet resource in the ownerDocument when ReactDOM.preinit(..., {as: "style" }) is called outside of render on the client',async()=>{
3778
+
// This is testing behavior, but it shows that it is not a good idea to preinit inside a shadowRoot. The point is we are asserting a behavior
0 commit comments