Skip to content

Commit fb8c191

Browse files
authored
Don't use nested objects to "namespace" namespace constants (#21073)
1 parent fa868d6 commit fb8c191

File tree

4 files changed

+10
-18
lines changed

4 files changed

+10
-18
lines changed

packages/react-dom/src/client/ReactDOMComponent.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import {
5454
setValueForStyles,
5555
validateShorthandPropertyCollisionInDev,
5656
} from '../shared/CSSPropertyOperations';
57-
import {Namespaces, getIntrinsicNamespace} from '../shared/DOMNamespaces';
57+
import {HTML_NAMESPACE, getIntrinsicNamespace} from '../shared/DOMNamespaces';
5858
import {
5959
getPropertyInfo,
6060
shouldIgnoreAttribute,
@@ -86,8 +86,6 @@ const CHILDREN = 'children';
8686
const STYLE = 'style';
8787
const HTML = '__html';
8888

89-
const {html: HTML_NAMESPACE} = Namespaces;
90-
9189
let warnedUnknownTags;
9290
let suppressHydrationWarning;
9391

packages/react-dom/src/client/setInnerHTML.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
import {Namespaces} from '../shared/DOMNamespaces';
10+
import {SVG_NAMESPACE} from '../shared/DOMNamespaces';
1111
import createMicrosoftUnsafeLocalFunction from '../shared/createMicrosoftUnsafeLocalFunction';
1212
import {enableTrustedTypesIntegration} from 'shared/ReactFeatureFlags';
1313

@@ -25,7 +25,7 @@ const setInnerHTML = createMicrosoftUnsafeLocalFunction(function(
2525
node: Element,
2626
html: {valueOf(): {toString(): string, ...}, ...},
2727
): void {
28-
if (node.namespaceURI === Namespaces.svg) {
28+
if (node.namespaceURI === SVG_NAMESPACE) {
2929
if (__DEV__) {
3030
if (enableTrustedTypesIntegration) {
3131
// TODO: reconsider the text of this warning and when it should show

packages/react-dom/src/server/ReactPartialRenderer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ import {
6363
setCurrentPartialRenderer,
6464
} from './ReactPartialRendererHooks';
6565
import {
66-
Namespaces,
66+
HTML_NAMESPACE,
6767
getIntrinsicNamespace,
6868
getChildNamespace,
6969
} from '../shared/DOMNamespaces';
@@ -747,7 +747,7 @@ class ReactDOMServerRenderer {
747747
type: null,
748748
// Assume all trees start in the HTML namespace (not totally true, but
749749
// this is what we did historically)
750-
domNamespace: Namespaces.html,
750+
domNamespace: HTML_NAMESPACE,
751751
children: flatChildren,
752752
childIndex: 0,
753753
context: emptyObject,
@@ -1327,12 +1327,12 @@ class ReactDOMServerRenderer {
13271327
const tag = element.type.toLowerCase();
13281328

13291329
let namespace = parentNamespace;
1330-
if (parentNamespace === Namespaces.html) {
1330+
if (parentNamespace === HTML_NAMESPACE) {
13311331
namespace = getIntrinsicNamespace(tag);
13321332
}
13331333

13341334
if (__DEV__) {
1335-
if (namespace === Namespaces.html) {
1335+
if (namespace === HTML_NAMESPACE) {
13361336
// Should this check be gated by parent namespace? Not sure we want to
13371337
// allow <SVG> or <mATH>.
13381338
if (tag !== element.type) {

packages/react-dom/src/shared/DOMNamespaces.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,9 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

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';
1711

1812
// Assumes there is no parent namespace.
1913
export function getIntrinsicNamespace(type: string): string {

0 commit comments

Comments
 (0)