From fb8c1917e9985f83032f642e5db8b9abf089653e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Markb=C3=A5ge?= Date: Wed, 24 Mar 2021 12:58:23 -0400 Subject: [PATCH] Don't use nested objects to "namespace" namespace constants (#21073) --- packages/react-dom/src/client/ReactDOMComponent.js | 4 +--- packages/react-dom/src/client/setInnerHTML.js | 4 ++-- .../react-dom/src/server/ReactPartialRenderer.js | 8 ++++---- packages/react-dom/src/shared/DOMNamespaces.js | 12 +++--------- 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/packages/react-dom/src/client/ReactDOMComponent.js b/packages/react-dom/src/client/ReactDOMComponent.js index 86789230ca0f4..71da034466c8a 100644 --- a/packages/react-dom/src/client/ReactDOMComponent.js +++ b/packages/react-dom/src/client/ReactDOMComponent.js @@ -54,7 +54,7 @@ import { setValueForStyles, validateShorthandPropertyCollisionInDev, } from '../shared/CSSPropertyOperations'; -import {Namespaces, getIntrinsicNamespace} from '../shared/DOMNamespaces'; +import {HTML_NAMESPACE, getIntrinsicNamespace} from '../shared/DOMNamespaces'; import { getPropertyInfo, shouldIgnoreAttribute, @@ -86,8 +86,6 @@ const CHILDREN = 'children'; const STYLE = 'style'; const HTML = '__html'; -const {html: HTML_NAMESPACE} = Namespaces; - let warnedUnknownTags; let suppressHydrationWarning; diff --git a/packages/react-dom/src/client/setInnerHTML.js b/packages/react-dom/src/client/setInnerHTML.js index 7afcd9a6306b4..43319acd2bf03 100644 --- a/packages/react-dom/src/client/setInnerHTML.js +++ b/packages/react-dom/src/client/setInnerHTML.js @@ -7,7 +7,7 @@ * @flow */ -import {Namespaces} from '../shared/DOMNamespaces'; +import {SVG_NAMESPACE} from '../shared/DOMNamespaces'; import createMicrosoftUnsafeLocalFunction from '../shared/createMicrosoftUnsafeLocalFunction'; import {enableTrustedTypesIntegration} from 'shared/ReactFeatureFlags'; @@ -25,7 +25,7 @@ const setInnerHTML = createMicrosoftUnsafeLocalFunction(function( node: Element, html: {valueOf(): {toString(): string, ...}, ...}, ): void { - if (node.namespaceURI === Namespaces.svg) { + if (node.namespaceURI === SVG_NAMESPACE) { if (__DEV__) { if (enableTrustedTypesIntegration) { // TODO: reconsider the text of this warning and when it should show diff --git a/packages/react-dom/src/server/ReactPartialRenderer.js b/packages/react-dom/src/server/ReactPartialRenderer.js index d01c431e7318b..1e536e5cdd496 100644 --- a/packages/react-dom/src/server/ReactPartialRenderer.js +++ b/packages/react-dom/src/server/ReactPartialRenderer.js @@ -63,7 +63,7 @@ import { setCurrentPartialRenderer, } from './ReactPartialRendererHooks'; import { - Namespaces, + HTML_NAMESPACE, getIntrinsicNamespace, getChildNamespace, } from '../shared/DOMNamespaces'; @@ -747,7 +747,7 @@ class ReactDOMServerRenderer { type: null, // Assume all trees start in the HTML namespace (not totally true, but // this is what we did historically) - domNamespace: Namespaces.html, + domNamespace: HTML_NAMESPACE, children: flatChildren, childIndex: 0, context: emptyObject, @@ -1327,12 +1327,12 @@ class ReactDOMServerRenderer { const tag = element.type.toLowerCase(); let namespace = parentNamespace; - if (parentNamespace === Namespaces.html) { + if (parentNamespace === HTML_NAMESPACE) { namespace = getIntrinsicNamespace(tag); } if (__DEV__) { - if (namespace === Namespaces.html) { + if (namespace === HTML_NAMESPACE) { // Should this check be gated by parent namespace? Not sure we want to // allow or . if (tag !== element.type) { diff --git a/packages/react-dom/src/shared/DOMNamespaces.js b/packages/react-dom/src/shared/DOMNamespaces.js index ca0e8fb377026..0ce6aef355fe7 100644 --- a/packages/react-dom/src/shared/DOMNamespaces.js +++ b/packages/react-dom/src/shared/DOMNamespaces.js @@ -5,15 +5,9 @@ * LICENSE file in the root directory of this source tree. */ -const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml'; -const MATH_NAMESPACE = 'http://www.w3.org/1998/Math/MathML'; -const SVG_NAMESPACE = 'http://www.w3.org/2000/svg'; - -export const Namespaces = { - html: HTML_NAMESPACE, - mathml: MATH_NAMESPACE, - svg: SVG_NAMESPACE, -}; +export const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml'; +export const MATH_NAMESPACE = 'http://www.w3.org/1998/Math/MathML'; +export const SVG_NAMESPACE = 'http://www.w3.org/2000/svg'; // Assumes there is no parent namespace. export function getIntrinsicNamespace(type: string): string {