Don't use nested objects to "namespace" namespace constants (#21073)

This commit is contained in:
Sebastian Markbåge
2021-03-24 09:58:23 -07:00
committed by GitHub
parent fa868d6be7
commit fb8c1917e9
4 changed files with 10 additions and 18 deletions
+1 -3
View File
@@ -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;
+2 -2
View File
@@ -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
+4 -4
View File
@@ -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 <SVG> or <mATH>.
if (tag !== element.type) {
+3 -9
View File
@@ -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 {