@samitouri / QOS-React / commits / e7d7809eb1

reverted the getChildContext warning from showing on functional components in Fiber

Dominic Gannaway committed Feb 23, 2017 at 13:39 UTC e7d7809eb198616b1765179c654b1f53a8d0486b
4 files changed +36 -41
src/renderers/__tests__/ReactStatelessComponent-test.js
+20 -11
@@ -118,17 +118,26 @@ describe('ReactStatelessComponent', () => {
118
119 ReactDOM.render(<StatelessComponentWithChildContext name="A" />, container);
120
121 - expectDev(console.error.calls.count()).toBe(2);
122 - expectDev(console.error.calls.argsFor(0)[0]).toContain(
123 - 'StatelessComponentWithChildContext(...): childContextTypes cannot ' +
124 - 'be defined on a functional component.'
125 - );
126 - expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toBe(
127 - 'Warning: StatelessComponentWithChildContext.childContextTypes is specified ' +
128 - 'but there is no getChildContext() method on the instance. You can either ' +
129 - 'define getChildContext() on StatelessComponentWithChildContext or remove ' +
130 - 'childContextTypes from it.'
131 - );
121 + // Stack and Fiber differ in terms of they show warnings
122 + if (!ReactDOMFeatureFlags.useFiber) {
123 + expectDev(console.error.calls.count()).toBe(2);
124 + expectDev(console.error.calls.argsFor(0)[0]).toContain(
125 + 'StatelessComponentWithChildContext(...): childContextTypes cannot ' +
126 + 'be defined on a functional component.'
127 + );
128 + expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toBe(
129 + 'Warning: StatelessComponentWithChildContext.childContextTypes is specified ' +
130 + 'but there is no getChildContext() method on the instance. You can either ' +
131 + 'define getChildContext() on StatelessComponentWithChildContext or remove ' +
132 + 'childContextTypes from it.'
133 + );
134 + } else {
135 + expectDev(console.error.calls.count()).toBe(1);
136 + expectDev(console.error.calls.argsFor(0)[0]).toContain(
137 + 'StatelessComponentWithChildContext(...): childContextTypes cannot ' +
138 + 'be defined on a functional component.'
139 + );
140 + }
141 });
142
143 if (!ReactDOMFeatureFlags.useFiber) {
src/renderers/dom/shared/ReactDOMFeatureFlags.js
+1 -1
@@ -13,7 +13,7 @@
13
14 var ReactDOMFeatureFlags = {
15 useCreateElement: true,
16 - useFiber: false,
16 + useFiber: true,
17 };
18
19 module.exports = ReactDOMFeatureFlags;
src/renderers/shared/fiber/ReactFiberBeginWork.js
-7
@@ -67,10 +67,6 @@ var invariant = require('invariant');
67 if (__DEV__) {
68 var ReactDebugCurrentFiber = require('ReactDebugCurrentFiber');
69 var warning = require('warning');
70 - var {
71 - warnAboutMissingGetChildContext,
72 - } = require('ReactFiberContext');
73 -
70 var warnedAboutStatelessRefs = {};
71 }
72
@@ -490,9 +486,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
486 '%s(...): childContextTypes cannot be defined on a functional component.',
487 Component.displayName || Component.name || 'Component'
488 );
493 - if (Component.childContextTypes) {
494 - warnAboutMissingGetChildContext(workInProgress);
495 - }
489 }
490 if (workInProgress.ref !== null) {
491 let info = '';
src/renderers/shared/fiber/ReactFiberContext.js
+15 -22
@@ -32,30 +32,9 @@ const {
32 push,
33 } = require('ReactFiberStack');
34
35 -var warnAboutMissingGetChildContext;
36 -
35 if (__DEV__) {
36 var checkReactTypeSpec = require('checkReactTypeSpec');
37 var warnedAboutMissingGetChildContext = {};
40 -
41 - // TODO (bvaughn) Replace this behavior with an invariant() in the future.
42 - // It has only been added in Fiber to match the (unintentional) behavior in Stack.
43 - warnAboutMissingGetChildContext = (fiber: Fiber) => {
44 - const componentName = getComponentName(fiber);
45 -
46 - if (!warnedAboutMissingGetChildContext[componentName]) {
47 - warnedAboutMissingGetChildContext[componentName] = true;
48 - warning(
49 - false,
50 - '%s.childContextTypes is specified but there is no getChildContext() method ' +
51 - 'on the instance. You can either define getChildContext() on %s or remove ' +
52 - 'childContextTypes from it.',
53 - componentName,
54 - componentName,
55 - );
56 - }
57 - };
58 - module.exports.warnAboutMissingGetChildContext = warnAboutMissingGetChildContext;
38 }
39
40 // A cursor to the current merged context object on the stack.
@@ -165,9 +144,23 @@ function processChildContext(fiber : Fiber, parentContext : Object, isReconcilin
144 const instance = fiber.stateNode;
145 const childContextTypes = fiber.type.childContextTypes;
146
147 + // TODO (bvaughn) Replace this behavior with an invariant() in the future.
148 + // It has only been added in Fiber to match the (unintentional) behavior in Stack.
149 if (typeof instance.getChildContext !== 'function') {
150 if (__DEV__) {
170 - warnAboutMissingGetChildContext(fiber);
151 + const componentName = getComponentName(fiber);
152 +
153 + if (!warnedAboutMissingGetChildContext[componentName]) {
154 + warnedAboutMissingGetChildContext[componentName] = true;
155 + warning(
156 + false,
157 + '%s.childContextTypes is specified but there is no getChildContext() method ' +
158 + 'on the instance. You can either define getChildContext() on %s or remove ' +
159 + 'childContextTypes from it.',
160 + componentName,
161 + componentName,
162 + );
163 + }
164 }
165 return parentContext;
166 }