Skip to content

Commit

Permalink
Don't use nested objects to "namespace" namespace constants (facebook…
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage authored and koto committed Jun 15, 2021
1 parent 8af1d84 commit 2e40575
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
4 changes: 1 addition & 3 deletions packages/react-dom/src/client/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -86,8 +86,6 @@ const CHILDREN = 'children';
const STYLE = 'style';
const HTML = '__html';

const {html: HTML_NAMESPACE} = Namespaces;

let warnedUnknownTags;
let suppressHydrationWarning;

Expand Down
4 changes: 2 additions & 2 deletions packages/react-dom/src/client/setInnerHTML.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions packages/react-dom/src/server/ReactPartialRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import {
setCurrentPartialRenderer,
} from './ReactPartialRendererHooks';
import {
Namespaces,
HTML_NAMESPACE,
getIntrinsicNamespace,
getChildNamespace,
} from '../shared/DOMNamespaces';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 <SVG> or <mATH>.
if (tag !== element.type) {
Expand Down
12 changes: 3 additions & 9 deletions packages/react-dom/src/shared/DOMNamespaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2e40575

Please sign in to comment.