Skip to content

Commit

Permalink
Rename methods to better reflect their meanings
Browse files Browse the repository at this point in the history
Clarify which are DEV or PROD-only.
Clarify which can return null.

I believe the "work in progress only" was a mistake. I introduced it because I wasn't sure what guarantees we have around .return. But we know for sure that following a .return chain gives us an accurate stack even if we get into WIP trees because we don't have reparenting. So it's fine to relax that naming.
  • Loading branch information
gaearon committed Jul 6, 2018
1 parent 26e0b53 commit 146ba8e
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 65 deletions.
34 changes: 21 additions & 13 deletions packages/react-dom/src/client/ReactDOMFiberComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

// TODO: direct imports like some-package/src/* are bad. Fix me.
import {
getCurrentFiberOwnerName,
getCurrentFiberStackAddendum,
getCurrentFiberOwnerNameInDevOrNull,
getCurrentFiberStackInDevOrNull,
} from 'react-reconciler/src/ReactDebugCurrentFiber';
import {registrationNameModules} from 'events/EventPluginRegistry';
import warning from 'shared/warning';
Expand Down Expand Up @@ -61,7 +61,7 @@ const HTML = '__html';

const {html: HTML_NAMESPACE} = Namespaces;

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

let warnedUnknownTags;
let suppressHydrationWarning;
Expand All @@ -76,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 @@ -180,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 @@ -266,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 @@ -322,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 @@ -441,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 @@ -515,7 +523,7 @@ export function setInitialProperties(
props = rawProps;
}

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

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

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

let propKey;
let styleName;
Expand Down Expand Up @@ -833,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 @@ -894,7 +902,7 @@ export function diffHydratedProperties(
break;
}

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

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

// TODO: direct imports like some-package/src/* are bad. Fix me.
import {
getCurrentFiberOwnerName,
getCurrentFiberStackAddendum,
getCurrentFiberOwnerNameInDevOrNull,
getCurrentFiberStackInDevOrNull,
} from 'react-reconciler/src/ReactDebugCurrentFiber';
import invariant from 'shared/invariant';
import warning from 'shared/warning';
Expand Down Expand Up @@ -74,7 +74,7 @@ export function initWrapperState(element: Element, props: Object) {
ReactControlledValuePropTypes.checkPropTypes(
'input',
props,
getCurrentFiberStackAddendum,
getCurrentFiberStackInDevOrNull,
);

if (
Expand All @@ -90,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 @@ -108,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 @@ -153,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 @@ -169,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
8 changes: 4 additions & 4 deletions packages/react-dom/src/client/ReactDOMFiberSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

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

Expand All @@ -30,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 @@ -46,7 +46,7 @@ function checkSelectPropTypes(props) {
ReactControlledValuePropTypes.checkPropTypes(
'select',
props,
getCurrentFiberStackAddendum,
getCurrentFiberStackInDevOrNull,
);

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

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

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

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

let validateDOMNesting = () => {};

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

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

const warnKey =
!!invalidParent + '|' + childTag + '|' + ancestorTag + '|' + addendum;
Expand Down
4 changes: 2 additions & 2 deletions packages/react-native-renderer/src/ReactNativeRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import './ReactNativeInjection';

import * as ReactNativeFiberRenderer from 'react-reconciler/inline.native';
// TODO: direct imports like some-package/src/* are bad. Fix me.
import {getStackAddendumByWorkInProgressFiber} from 'react-reconciler/src/ReactDebugCurrentFiber';
import {getStackByFiberInDevAndProd} from 'react-reconciler/src/ReactDebugCurrentFiber';
import * as ReactPortal from 'shared/ReactPortal';
import * as ReactGenericBatching from 'events/ReactGenericBatching';
import ReactVersion from 'shared/ReactVersion';
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 './ReactDebugCurrentFiber';
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),
};
}
20 changes: 10 additions & 10 deletions packages/react-reconciler/src/ReactChildFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ import {
} from './ReactFiber';
import {emptyRefsObject} from './ReactFiberClassComponent';
import {
getCurrentFiberStackAddendum,
getStackAddendumByWorkInProgressFiber,
getCurrentFiberStackInDevOrNull,
getStackByFiberInDevAndProd,
} from './ReactDebugCurrentFiber';
import {StrictMode} from './ReactTypeOfMode';

Expand Down Expand Up @@ -80,7 +80,7 @@ if (__DEV__) {
'Each child in an array or iterator should have a unique ' +
'"key" prop. See https://fb.me/react-warning-keys for ' +
'more information.' +
(getCurrentFiberStackAddendum() || '');
(getCurrentFiberStackInDevOrNull() || '');
if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
return;
}
Expand All @@ -91,7 +91,7 @@ if (__DEV__) {
'Each child in an array or iterator should have a unique ' +
'"key" prop. See https://fb.me/react-warning-keys for ' +
'more information.%s',
getCurrentFiberStackAddendum(),
getCurrentFiberStackInDevOrNull(),
);
};
}
Expand Down Expand Up @@ -122,7 +122,7 @@ function coerceRef(
'\n\nLearn more about using refs safely here:' +
'\nhttps://fb.me/react-strict-mode-string-ref',
mixedRef,
getStackAddendumByWorkInProgressFiber(returnFiber),
getStackByFiberInDevAndProd(returnFiber),
);
didWarnAboutStringRefInStrictMode[componentName] = true;
}
Expand Down Expand Up @@ -197,7 +197,7 @@ function throwOnInvalidObjectType(returnFiber: Fiber, newChild: Object) {
addendum =
' If you meant to render a collection of children, use an array ' +
'instead.' +
(getCurrentFiberStackAddendum() || '');
(getCurrentFiberStackInDevOrNull() || '');
}
invariant(
false,
Expand All @@ -215,7 +215,7 @@ function warnOnFunctionType() {
'Functions are not valid as a React child. This may happen if ' +
'you return a Component instead of <Component /> from render. ' +
'Or maybe you meant to call this function rather than return it.' +
(getCurrentFiberStackAddendum() || '');
(getCurrentFiberStackInDevOrNull() || '');

if (ownerHasFunctionTypeWarning[currentComponentErrorInfo]) {
return;
Expand All @@ -227,7 +227,7 @@ function warnOnFunctionType() {
'Functions are not valid as a React child. This may happen if ' +
'you return a Component instead of <Component /> from render. ' +
'Or maybe you meant to call this function rather than return it.%s',
getCurrentFiberStackAddendum() || '',
getCurrentFiberStackInDevOrNull() || '',
);
}

Expand Down Expand Up @@ -719,7 +719,7 @@ function ChildReconciler(shouldTrackSideEffects) {
'duplicated and/or omitted — the behavior is unsupported and ' +
'could change in a future version.%s',
key,
getCurrentFiberStackAddendum(),
getCurrentFiberStackInDevOrNull(),
);
break;
default:
Expand Down Expand Up @@ -912,7 +912,7 @@ function ChildReconciler(shouldTrackSideEffects) {
'Using Maps as children is unsupported and will likely yield ' +
'unexpected results. Convert it to a sequence/iterable of keyed ' +
'ReactElements instead.%s',
getCurrentFiberStackAddendum(),
getCurrentFiberStackInDevOrNull(),
);
didWarnAboutMaps = true;
}
Expand Down

0 comments on commit 146ba8e

Please sign in to comment.