@samitouri / QOS-React / commits / ea2ade251f

Don't pass method names in production

Requires us to make the error message a bit more generic.

Andrew Clark committed Feb 9, 2017 at 15:54 UTC ea2ade251fc0205a328315ab00921600f03e94f3
2 files changed +13 -24
src/renderers/shared/fiber/ReactFiberReconciler.js
+1 -1
@@ -155,7 +155,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
155 String(callback)
156 );
157 }
158 - addTopLevelUpdate(current, nextState, callback || null, priorityLevel);
158 + addTopLevelUpdate(current, nextState, callback, priorityLevel);
159 scheduleUpdate(current, priorityLevel);
160 }
161
src/renderers/shared/fiber/ReactFiberUpdateQueue.js
+12 -23
@@ -217,31 +217,20 @@ function findInsertionPosition(queue, update) : Update | null {
217 // we shouldn't make a copy.
218 //
219 // If the update is cloned, it returns the cloned update.
220 -function insertUpdate(fiber : Fiber, update : Update, methodName : string) : Update | null {
220 +function insertUpdate(fiber : Fiber, update : Update) : Update | null {
221 const queue1 = ensureUpdateQueue(fiber);
222 const queue2 = fiber.alternate ? ensureUpdateQueue(fiber.alternate) : null;
223
224 // Warn if an update is scheduled from inside an updater function.
225 if (__DEV__) {
226 if (queue1.isProcessing || (queue2 && queue2.isProcessing)) {
227 - if (methodName === 'setState') {
228 - warning(
229 - false,
230 - 'setState was called from inside the updater function of another' +
231 - 'setState. A function passed as the first argument of setState ' +
232 - 'should not contain any side-effects. Return a partial state ' +
233 - 'object instead of calling setState again. Example: ' +
234 - 'this.setState(function(state) { return { count: state.count + 1 }; })'
235 - );
236 - } else {
237 - warning(
238 - false,
239 - '%s was called from inside the updater function of setState. A ' +
240 - 'function passed as the first argument of setState ' +
241 - 'should not contain any side-effects.',
242 - methodName
243 - );
244 - }
227 + warning(
228 + false,
229 + 'An update (setState, replaceState, or forceUpdate) was scheduled ' +
230 + 'from inside an update function. Update functions should be pure, ' +
231 + 'with zero side-effects. Consider using componentDidUpdate or a ' +
232 + 'callback.'
233 + );
234 }
235 }
236
@@ -300,7 +289,7 @@ function addUpdate(
289 isTopLevelUnmount: false,
290 next: null,
291 };
303 - insertUpdate(fiber, update, 'setState');
292 + insertUpdate(fiber, update);
293 }
294 exports.addUpdate = addUpdate;
295
@@ -319,7 +308,7 @@ function addReplaceUpdate(
308 isTopLevelUnmount: false,
309 next: null,
310 };
322 - insertUpdate(fiber, update, 'replaceState');
311 + insertUpdate(fiber, update);
312 }
313 exports.addReplaceUpdate = addReplaceUpdate;
314
@@ -337,7 +326,7 @@ function addForceUpdate(
326 isTopLevelUnmount: false,
327 next: null,
328 };
340 - insertUpdate(fiber, update, 'forceUpdate');
329 + insertUpdate(fiber, update);
330 }
331 exports.addForceUpdate = addForceUpdate;
332
@@ -366,7 +355,7 @@ function addTopLevelUpdate(
355 isTopLevelUnmount,
356 next: null,
357 };
369 - const update2 = insertUpdate(fiber, update, 'render');
358 + const update2 = insertUpdate(fiber, update);
359
360 if (isTopLevelUnmount) {
361 // Drop all updates that are lower-priority, so that the tree is not