diff --git a/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js b/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js index 2bd2d29350b99..281ec1fea0582 100644 --- a/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js +++ b/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js @@ -3481,10 +3481,20 @@ function onUnsuspend(this: SuspendedState) { } } +// We use a value that is type distinct from precedence to track which one is last. +// This ensures there is no collision with user defined precedences. Normally we would +// just track this in module scope but since the precedences are tracked per HoistableRoot +// we need to associate it to something other than a global scope hence why we try to +// colocate it with the map of precedences in the first place +const LAST_PRECEDENCE = null; + // This is typecast to non-null because it will always be set before read. // it is important that this not be used except when the stack guarantees it exists. // Currentlyt his is only during insertSuspendedStylesheet. -let precedencesByRoot: Map> = (null: any); +let precedencesByRoot: Map< + HoistableRoot, + Map, +> = (null: any); function insertSuspendedStylesheets( state: SuspendedState, @@ -3539,15 +3549,15 @@ function insertStylesheetIntoRoot( // and will be hoisted by the Fizz runtime imminently. node.getAttribute('media') !== 'not all' ) { - precedences.set('p' + node.dataset.precedence, node); + precedences.set(node.dataset.precedence, node); last = node; } } if (last) { - precedences.set('last', last); + precedences.set(LAST_PRECEDENCE, last); } } else { - last = precedences.get('last'); + last = precedences.get(LAST_PRECEDENCE); } // We only call this after we have constructed an instance so we assume it here @@ -3555,11 +3565,11 @@ function insertStylesheetIntoRoot( // We will always have a precedence for stylesheet instances const precedence: string = (instance.getAttribute('data-precedence'): any); - const prior = precedences.get('p' + precedence) || last; + const prior = precedences.get(precedence) || last; if (prior === last) { - precedences.set('last', instance); + precedences.set(LAST_PRECEDENCE, instance); } - precedences.set('p' + precedence, instance); + precedences.set(precedence, instance); this.count++; const onComplete = onUnsuspend.bind(this);