Skip to content

Commit

Permalink
use expando to avoid leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
gnoff committed Oct 4, 2022
1 parent 5035f71 commit 4ac3af2
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions packages/react-dom-bindings/src/client/ReactDOMFloatClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ let lastCurrentDocument: ?Document = null;

let previousDispatcher = null;
export function prepareToRenderResources(rootContainer: Container) {
// $FlowFixMe all Container types are Node's and have a getRootNode method
const rootNode = rootContainer.getRootNode();
lastCurrentDocument = rootNode.ownerDocument || rootNode;
lastCurrentDocument = getDocumentFromRoot(rootNode);

previousDispatcher = Dispatcher.current;
Dispatcher.current = ReactDOMClientDispatcher;
Expand All @@ -108,14 +109,12 @@ export function cleanupAfterRenderResources() {
// from Internals -> ReactDOM -> FloatClient -> Internals so this doesn't introduce a new one.
export const ReactDOMClientDispatcher = {preload, preinit};

type FloatRoot = Document | ShadowRoot;
type FloatDocument = Document & {_rstyles?: Map<string, StyleResource>};
type FloatShadowRoot = ShadowRoot & {_rstyles?: Map<string, StyleResource>};
type FloatRoot = FloatDocument | FloatShadowRoot;

// global maps of Resources
const preloadResources: Map<string, PreloadResource> = new Map();
const styleResourceRoots: Map<
FloatRoot,
Map<string, StyleResource>,
> = new Map();

function getCurrentResourceRoot(): null | FloatRoot {
const currentContainer = getCurrentRootHostContainer();
Expand Down Expand Up @@ -242,10 +241,9 @@ function preinit(href: string, options: PreinitOptions) {

switch (as) {
case 'style': {
let styleResources = styleResourceRoots.get(resourceRoot);
let styleResources = resourceRoot._rstyles;
if (!styleResources) {
styleResources = new Map();
styleResourceRoots.set(resourceRoot, styleResources);
styleResources = resourceRoot._rstyles = new Map();
}
const precedence = options.precedence || 'default';
let resource = styleResources.get(href);
Expand Down Expand Up @@ -338,10 +336,9 @@ export function getResource(
const {rel} = pendingProps;
switch (rel) {
case 'stylesheet': {
let styleResources = styleResourceRoots.get(resourceRoot);
let styleResources = resourceRoot._rstyles;
if (!styleResources) {
styleResources = new Map();
styleResourceRoots.set(resourceRoot, styleResources);
styleResources = resourceRoot._rstyles = new Map();
}
let didWarn;
if (__DEV__) {
Expand Down

0 comments on commit 4ac3af2

Please sign in to comment.