Don't use nested objects to "namespace" namespace constants (#21073)
Sebastian Markbåge committed
Mar 24, 2021 at 12:58 UTC
fb8c1917e9985f83032f642e5db8b9abf089653e
4 files changed
+10
-18
packages/react-dom/src/client/ReactDOMComponent.js
+1
-3
@@ -54,7 +54,7 @@ import {
54
setValueForStyles,
55
validateShorthandPropertyCollisionInDev,
56
} from '../shared/CSSPropertyOperations';
57
-import {Namespaces, getIntrinsicNamespace} from '../shared/DOMNamespaces';
57
+import {HTML_NAMESPACE, getIntrinsicNamespace} from '../shared/DOMNamespaces';
58
import {
59
getPropertyInfo,
60
shouldIgnoreAttribute,
@@ -86,8 +86,6 @@ const CHILDREN = 'children';
86
const STYLE = 'style';
87
const HTML = '__html';
88
89
-const {html: HTML_NAMESPACE} = Namespaces;
90
-
89
let warnedUnknownTags;
90
let suppressHydrationWarning;
91
packages/react-dom/src/client/setInnerHTML.js
+2
-2
@@ -7,7 +7,7 @@
7
* @flow
8
*/
9
10
-import {Namespaces} from '../shared/DOMNamespaces';
10
+import {SVG_NAMESPACE} from '../shared/DOMNamespaces';
11
import createMicrosoftUnsafeLocalFunction from '../shared/createMicrosoftUnsafeLocalFunction';
12
import {enableTrustedTypesIntegration} from 'shared/ReactFeatureFlags';
13
@@ -25,7 +25,7 @@ const setInnerHTML = createMicrosoftUnsafeLocalFunction(function(
25
node: Element,
26
html: {valueOf(): {toString(): string, ...}, ...},
27
): void {
28
- if (node.namespaceURI === Namespaces.svg) {
28
+ if (node.namespaceURI === SVG_NAMESPACE) {
29
if (__DEV__) {
30
if (enableTrustedTypesIntegration) {
31
// TODO: reconsider the text of this warning and when it should show
packages/react-dom/src/server/ReactPartialRenderer.js
+4
-4
@@ -63,7 +63,7 @@ import {
63
setCurrentPartialRenderer,
64
} from './ReactPartialRendererHooks';
65
import {
66
- Namespaces,
66
+ HTML_NAMESPACE,
67
getIntrinsicNamespace,
68
getChildNamespace,
69
} from '../shared/DOMNamespaces';
@@ -747,7 +747,7 @@ class ReactDOMServerRenderer {
747
type: null,
748
// Assume all trees start in the HTML namespace (not totally true, but
749
// this is what we did historically)
750
- domNamespace: Namespaces.html,
750
+ domNamespace: HTML_NAMESPACE,
751
children: flatChildren,
752
childIndex: 0,
753
context: emptyObject,
@@ -1327,12 +1327,12 @@ class ReactDOMServerRenderer {
1327
const tag = element.type.toLowerCase();
1328
1329
let namespace = parentNamespace;
1330
- if (parentNamespace === Namespaces.html) {
1330
+ if (parentNamespace === HTML_NAMESPACE) {
1331
namespace = getIntrinsicNamespace(tag);
1332
}
1333
1334
if (__DEV__) {
1335
- if (namespace === Namespaces.html) {
1335
+ if (namespace === HTML_NAMESPACE) {
1336
// Should this check be gated by parent namespace? Not sure we want to
1337
// allow <SVG> or <mATH>.
1338
if (tag !== element.type) {
packages/react-dom/src/shared/DOMNamespaces.js
+3
-9
@@ -5,15 +5,9 @@
5
* LICENSE file in the root directory of this source tree.
6
*/
7
8
-const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
9
-const MATH_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
10
-const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
11
-
12
-export const Namespaces = {
13
- html: HTML_NAMESPACE,
14
- mathml: MATH_NAMESPACE,
15
- svg: SVG_NAMESPACE,
16
-};
8
+export const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
9
+export const MATH_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
10
+export const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
11
12
// Assumes there is no parent namespace.
13
export function getIntrinsicNamespace(type: string): string {