Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor stack handling (no functional changes) #13165

Merged
merged 4 commits into from
Jul 7, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 23 additions & 16 deletions packages/react-dom/src/client/ReactDOMFiberComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
*/

// TODO: direct imports like some-package/src/* are bad. Fix me.
import ReactDebugCurrentFiber from 'react-reconciler/src/ReactDebugCurrentFiber';
import {
getCurrentFiberOwnerNameInDevOrNull,
getCurrentFiberStackInDevOrNull,
} from 'react-reconciler/src/ReactDebugCurrentFiber';
import {registrationNameModules} from 'events/EventPluginRegistry';
import warning from 'shared/warning';

Expand Down Expand Up @@ -45,10 +48,6 @@ import {validateProperties as validateARIAProperties} from '../shared/ReactDOMIn
import {validateProperties as validateInputProperties} from '../shared/ReactDOMNullInputValuePropHook';
import {validateProperties as validateUnknownProperties} from '../shared/ReactDOMUnknownPropertyHook';

const {
getCurrentFiberOwnerName,
getCurrentFiberStackAddendum,
} = ReactDebugCurrentFiber;
let didWarnInvalidHydration = false;
let didWarnShadyDOM = false;

Expand All @@ -62,7 +61,7 @@ const HTML = '__html';

const {html: HTML_NAMESPACE} = Namespaces;

let getStack = () => '';
let getStackInDevOrNull = () => '';

let warnedUnknownTags;
let suppressHydrationWarning;
Expand All @@ -77,7 +76,7 @@ let normalizeMarkupForTextOrAttribute;
let normalizeHTML;

if (__DEV__) {
getStack = getCurrentFiberStackAddendum;
getStackInDevOrNull = getCurrentFiberStackInDevOrNull;

warnedUnknownTags = {
// Chrome is the only major browser not shipping <time>. But as of July
Expand Down Expand Up @@ -181,15 +180,15 @@ if (__DEV__) {
registrationName,
registrationName,
registrationName,
getCurrentFiberStackAddendum(),
getCurrentFiberStackInDevOrNull(),
);
} else {
warning(
false,
'Expected `%s` listener to be a function, instead got a value of `%s` type.%s',
registrationName,
typeof listener,
getCurrentFiberStackAddendum(),
getCurrentFiberStackInDevOrNull(),
);
}
};
Expand Down Expand Up @@ -267,7 +266,11 @@ function setInitialDOMProperties(
}
}
// Relies on `updateStylesByID` not mutating `styleUpdates`.
CSSPropertyOperations.setValueForStyles(domElement, nextProp, getStack);
CSSPropertyOperations.setValueForStyles(
domElement,
nextProp,
getStackInDevOrNull,
);
} else if (propKey === DANGEROUSLY_SET_INNER_HTML) {
const nextHtml = nextProp ? nextProp[HTML] : undefined;
if (nextHtml != null) {
Expand Down Expand Up @@ -323,7 +326,11 @@ function updateDOMProperties(
const propKey = updatePayload[i];
const propValue = updatePayload[i + 1];
if (propKey === STYLE) {
CSSPropertyOperations.setValueForStyles(domElement, propValue, getStack);
CSSPropertyOperations.setValueForStyles(
domElement,
propValue,
getStackInDevOrNull,
);
} else if (propKey === DANGEROUSLY_SET_INNER_HTML) {
setInnerHTML(domElement, propValue);
} else if (propKey === CHILDREN) {
Expand Down Expand Up @@ -442,7 +449,7 @@ export function setInitialProperties(
false,
'%s is using shady DOM. Using shady DOM with React can ' +
'cause things to break subtly.',
getCurrentFiberOwnerName() || 'A component',
getCurrentFiberOwnerNameInDevOrNull() || 'A component',
);
didWarnShadyDOM = true;
}
Expand Down Expand Up @@ -516,7 +523,7 @@ export function setInitialProperties(
props = rawProps;
}

assertValidProps(tag, props, getStack);
assertValidProps(tag, props, getStackInDevOrNull);

setInitialDOMProperties(
tag,
Expand Down Expand Up @@ -604,7 +611,7 @@ export function diffProperties(
break;
}

assertValidProps(tag, nextProps, getStack);
assertValidProps(tag, nextProps, getStackInDevOrNull);

let propKey;
let styleName;
Expand Down Expand Up @@ -834,7 +841,7 @@ export function diffHydratedProperties(
false,
'%s is using shady DOM. Using shady DOM with React can ' +
'cause things to break subtly.',
getCurrentFiberOwnerName() || 'A component',
getCurrentFiberOwnerNameInDevOrNull() || 'A component',
);
didWarnShadyDOM = true;
}
Expand Down Expand Up @@ -895,7 +902,7 @@ export function diffHydratedProperties(
break;
}

assertValidProps(tag, rawProps, getStack);
assertValidProps(tag, rawProps, getStackInDevOrNull);

if (__DEV__) {
extraAttributeNames = new Set();
Expand Down
19 changes: 9 additions & 10 deletions packages/react-dom/src/client/ReactDOMFiberInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
*/

// TODO: direct imports like some-package/src/* are bad. Fix me.
import ReactDebugCurrentFiber from 'react-reconciler/src/ReactDebugCurrentFiber';
import {
getCurrentFiberOwnerNameInDevOrNull,
getCurrentFiberStackInDevOrNull,
} from 'react-reconciler/src/ReactDebugCurrentFiber';
import invariant from 'shared/invariant';
import warning from 'shared/warning';

Expand All @@ -25,10 +28,6 @@ type InputWithWrapperState = HTMLInputElement & {
},
};

const {
getCurrentFiberOwnerName,
getCurrentFiberStackAddendum,
} = ReactDebugCurrentFiber;
let didWarnValueDefaultValue = false;
let didWarnCheckedDefaultChecked = false;
let didWarnControlledToUncontrolled = false;
Expand Down Expand Up @@ -75,7 +74,7 @@ export function initWrapperState(element: Element, props: Object) {
ReactControlledValuePropTypes.checkPropTypes(
'input',
props,
getCurrentFiberStackAddendum,
getCurrentFiberStackInDevOrNull,
);

if (
Expand All @@ -91,7 +90,7 @@ export function initWrapperState(element: Element, props: Object) {
'both). Decide between using a controlled or uncontrolled input ' +
'element and remove one of these props. More info: ' +
'https://fb.me/react-controlled-components',
getCurrentFiberOwnerName() || 'A component',
getCurrentFiberOwnerNameInDevOrNull() || 'A component',
props.type,
);
didWarnCheckedDefaultChecked = true;
Expand All @@ -109,7 +108,7 @@ export function initWrapperState(element: Element, props: Object) {
'both). Decide between using a controlled or uncontrolled input ' +
'element and remove one of these props. More info: ' +
'https://fb.me/react-controlled-components',
getCurrentFiberOwnerName() || 'A component',
getCurrentFiberOwnerNameInDevOrNull() || 'A component',
props.type,
);
didWarnValueDefaultValue = true;
Expand Down Expand Up @@ -154,7 +153,7 @@ export function updateWrapper(element: Element, props: Object) {
'Decide between using a controlled or uncontrolled input ' +
'element for the lifetime of the component. More info: https://fb.me/react-controlled-components%s',
props.type,
getCurrentFiberStackAddendum(),
getCurrentFiberStackInDevOrNull(),
);
didWarnUncontrolledToControlled = true;
}
Expand All @@ -170,7 +169,7 @@ export function updateWrapper(element: Element, props: Object) {
'Decide between using a controlled or uncontrolled input ' +
'element for the lifetime of the component. More info: https://fb.me/react-controlled-components%s',
props.type,
getCurrentFiberStackAddendum(),
getCurrentFiberStackInDevOrNull(),
);
didWarnControlledToUncontrolled = true;
}
Expand Down
14 changes: 6 additions & 8 deletions packages/react-dom/src/client/ReactDOMFiberSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
*/

// TODO: direct imports like some-package/src/* are bad. Fix me.
import ReactDebugCurrentFiber from 'react-reconciler/src/ReactDebugCurrentFiber';
import {
getCurrentFiberOwnerNameInDevOrNull,
getCurrentFiberStackInDevOrNull,
} from 'react-reconciler/src/ReactDebugCurrentFiber';
import warning from 'shared/warning';

import ReactControlledValuePropTypes from '../shared/ReactControlledValuePropTypes';

const {
getCurrentFiberOwnerName,
getCurrentFiberStackAddendum,
} = ReactDebugCurrentFiber;

let didWarnValueDefaultValue;

if (__DEV__) {
Expand All @@ -32,7 +30,7 @@ type SelectWithWrapperState = HTMLSelectElement & {
};

function getDeclarationErrorAddendum() {
const ownerName = getCurrentFiberOwnerName();
const ownerName = getCurrentFiberOwnerNameInDevOrNull();
if (ownerName) {
return '\n\nCheck the render method of `' + ownerName + '`.';
}
Expand All @@ -48,7 +46,7 @@ function checkSelectPropTypes(props) {
ReactControlledValuePropTypes.checkPropTypes(
'select',
props,
getCurrentFiberStackAddendum,
getCurrentFiberStackInDevOrNull,
);

for (let i = 0; i < valuePropNames.length; i++) {
Expand Down
5 changes: 2 additions & 3 deletions packages/react-dom/src/client/ReactDOMFiberTextarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
import invariant from 'shared/invariant';
import warning from 'shared/warning';
// TODO: direct imports like some-package/src/* are bad. Fix me.
import ReactDebugCurrentFiber from 'react-reconciler/src/ReactDebugCurrentFiber';
import {getCurrentFiberStackInDevOrNull} from 'react-reconciler/src/ReactDebugCurrentFiber';

import ReactControlledValuePropTypes from '../shared/ReactControlledValuePropTypes';

const {getCurrentFiberStackAddendum} = ReactDebugCurrentFiber;
let didWarnValDefaultVal = false;

type TextAreaWithWrapperState = HTMLTextAreaElement & {
Expand Down Expand Up @@ -68,7 +67,7 @@ export function initWrapperState(element: Element, props: Object) {
ReactControlledValuePropTypes.checkPropTypes(
'textarea',
props,
getCurrentFiberStackAddendum,
getCurrentFiberStackInDevOrNull,
);
if (
props.value !== undefined &&
Expand Down
5 changes: 2 additions & 3 deletions packages/react-dom/src/client/validateDOMNesting.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

import warning from 'shared/warning';
// TODO: direct imports like some-package/src/* are bad. Fix me.
import ReactDebugCurrentFiber from 'react-reconciler/src/ReactDebugCurrentFiber';
import {getCurrentFiberStackInDevOrNull} from 'react-reconciler/src/ReactDebugCurrentFiber';

const {getCurrentFiberStackAddendum} = ReactDebugCurrentFiber;
let validateDOMNesting = () => {};

if (__DEV__) {
Expand Down Expand Up @@ -427,7 +426,7 @@ if (__DEV__) {
}

const ancestorTag = invalidParentOrAncestor.tag;
const addendum = getCurrentFiberStackAddendum();
const addendum = getCurrentFiberStackInDevOrNull();

const warnKey =
!!invalidParent + '|' + childTag + '|' + ancestorTag + '|' + addendum;
Expand Down
6 changes: 3 additions & 3 deletions packages/react-native-renderer/src/ReactNativeRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import type {ReactNodeList} from 'shared/ReactTypes';
import './ReactNativeInjection';

import * as ReactNativeFiberRenderer from 'react-reconciler/inline.native';
// TODO: direct imports like some-package/src/* are bad. Fix me.
import {getStackByFiberInDevAndProd} from 'react-reconciler/src/ReactDebugCurrentFiber';
import * as ReactPortal from 'shared/ReactPortal';
import * as ReactGenericBatching from 'events/ReactGenericBatching';
import ReactVersion from 'shared/ReactVersion';
// Module provided by RN:
import UIManager from 'UIManager';

import {getStackAddendumByWorkInProgressFiber} from 'shared/ReactFiberComponentTreeHook';

import NativeMethodsMixin from './NativeMethodsMixin';
import ReactNativeComponent from './ReactNativeComponent';
import * as ReactNativeComponentTree from './ReactNativeComponentTree';
Expand Down Expand Up @@ -80,7 +80,7 @@ function computeComponentStackForErrorReporting(reactTag: number): string {
if (!fiber) {
return '';
}
return getStackAddendumByWorkInProgressFiber(fiber);
return getStackByFiberInDevAndProd(fiber);
}

const roots = new Map();
Expand Down
4 changes: 2 additions & 2 deletions packages/react-reconciler/src/ReactCapturedValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import type {Fiber} from './ReactFiber';

import {getStackAddendumByWorkInProgressFiber} from 'shared/ReactFiberComponentTreeHook';
import {getStackByFiberInDevAndProd} from './ReactDebugCurrentFiber';

export type CapturedValue<T> = {
value: T,
Expand All @@ -36,6 +36,6 @@ export function createCapturedValue<T>(
return {
value,
source,
stack: getStackAddendumByWorkInProgressFiber(source),
stack: getStackByFiberInDevAndProd(source),
};
}