@samitouri / QOS-React / commits / ac76c95fbc

Add a disclaimer to internal invariants (#10285)

Dan Abramov committed Jul 26, 2017 at 19:08 UTC ac76c95fbc70d486e5619fcfa813d742c559a902
7 files changed +41 -13
src/renderers/shared/fiber/ReactChildFiber.js
+2 -1
@@ -49,7 +49,8 @@ if (__DEV__) {
49 }
50 invariant(
51 typeof child._store === 'object',
52 - 'React Component in warnForMissingKey should have a _store',
52 + 'React Component in warnForMissingKey should have a _store. ' +
53 + 'This error is likely caused by a bug in React. Please file an issue.',
54 );
55 child._store.validated = true;
56
src/renderers/shared/fiber/ReactFiberContext.js
+14 -4
@@ -142,7 +142,8 @@ exports.pushTopLevelContextObject = function(
142 ): void {
143 invariant(
144 contextStackCursor.cursor == null,
145 - 'Unexpected context found on stack',
145 + 'Unexpected context found on stack. ' +
146 + 'This error is likely caused by a bug in React. Please file an issue.',
147 );
148
149 push(contextStackCursor, context, fiber);
@@ -242,7 +243,11 @@ exports.pushContextProvider = function(workInProgress: Fiber): boolean {
243
244 exports.invalidateContextProvider = function(workInProgress: Fiber): void {
245 const instance = workInProgress.stateNode;
245 - invariant(instance, 'Expected to have an instance by this point.');
246 + invariant(
247 + instance,
248 + 'Expected to have an instance by this point. ' +
249 + 'This error is likely caused by a bug in React. Please file an issue.',
250 + );
251
252 // Merge parent and own context.
253 const mergedContext = processChildContext(
@@ -272,7 +277,8 @@ exports.findCurrentUnmaskedContext = function(fiber: Fiber): Object {
277 // makes sense elsewhere
278 invariant(
279 isFiberMounted(fiber) && fiber.tag === ClassComponent,
275 - 'Expected subtree parent to be a mounted class component',
280 + 'Expected subtree parent to be a mounted class component. ' +
281 + 'This error is likely caused by a bug in React. Please file an issue.',
282 );
283
284 let node: Fiber = fiber;
@@ -281,7 +287,11 @@ exports.findCurrentUnmaskedContext = function(fiber: Fiber): Object {
287 return node.stateNode.__reactInternalMemoizedMergedChildContext;
288 }
289 const parent = node.return;
284 - invariant(parent, 'Found unexpected detached subtree parent');
290 + invariant(
291 + parent,
292 + 'Found unexpected detached subtree parent. ' +
293 + 'This error is likely caused by a bug in React. Please file an issue.',
294 + );
295 node = parent;
296 }
297 return node.stateNode.context;
src/renderers/shared/fiber/ReactFiberHydrationContext.js
+10 -2
@@ -66,10 +66,18 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
66 resetHydrationState() {},
67 tryToClaimNextHydratableInstance() {},
68 prepareToHydrateHostInstance() {
69 - invariant(false, 'React bug.');
69 + invariant(
70 + false,
71 + 'Expected prepareToHydrateHostInstance() to never be called. ' +
72 + 'This error is likely caused by a bug in React. Please file an issue.',
73 + );
74 },
75 prepareToHydrateHostTextInstance() {
72 - invariant(false, 'React bug.');
76 + invariant(
77 + false,
78 + 'Expected prepareToHydrateHostTextInstance() to never be called. ' +
79 + 'This error is likely caused by a bug in React. Please file an issue.',
80 + );
81 },
82 popHydrationState(fiber: Fiber) {
83 return false;
src/renderers/shared/fiber/ReactFiberScheduler.js
+5 -1
@@ -919,7 +919,11 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
919 // No work left. We can exit.
920 break loop;
921 default:
922 - invariant(false, 'Switch statement should be exhuastive.');
922 + invariant(
923 + false,
924 + 'Switch statement should be exhuastive. ' +
925 + 'This error is likely caused by a bug in React. Please file an issue.',
926 + );
927 }
928 } while (true);
929 }
src/renderers/shared/fiber/ReactFiberTreeReflection.js
+3 -2
@@ -206,14 +206,15 @@ function findCurrentFiberUsingSlowPath(fiber: Fiber): Fiber | null {
206 invariant(
207 didFindChild,
208 'Child was not found in either parent set. This indicates a bug ' +
209 - 'related to the return pointer.',
209 + 'in React related to the return pointer. Please file an issue.',
210 );
211 }
212 }
213
214 invariant(
215 a.alternate === b,
216 - "Return fibers should always be each others' alternates.",
216 + "Return fibers should always be each others' alternates. " +
217 + 'This error is likely caused by a bug in React. Please file an issue.',
218 );
219 }
220 // If the root is not a host container, we're in a disconnected tree. I.e.
src/renderers/shared/server/ReactPartialRenderer.js
+4 -1
@@ -308,7 +308,10 @@ function createOpenTagMarkup(
308
309 function resolve(child, context) {
310 // TODO: We'll need to support Arrays (and strings) after Fiber is rolled out
311 - invariant(!Array.isArray(child), 'Did not expect to receive an Array child');
311 + invariant(
312 + !Array.isArray(child),
313 + 'The server renderer does not implement support for array children yet.',
314 + );
315 while (React.isValidElement(child)) {
316 if (__DEV__) {
317 pushElementToDebugStack(child);
src/renderers/shared/shared/event/ReactControlledComponent.js
+3 -2
@@ -43,7 +43,7 @@ function restoreStateOfTarget(target) {
43 fiberHostComponent &&
44 typeof fiberHostComponent.restoreControlledState === 'function',
45 'Fiber needs to be injected to handle a fiber target for controlled ' +
46 - 'events.',
46 + 'events. This error is likely caused by a bug in React. Please file an issue.',
47 );
48 const props = EventPluginUtils.getFiberCurrentPropsFromNode(
49 internalInstance.stateNode,
@@ -57,7 +57,8 @@ function restoreStateOfTarget(target) {
57 }
58 invariant(
59 typeof internalInstance.restoreControlledState === 'function',
60 - 'The internal instance must be a React host component.',
60 + 'The internal instance must be a React host component. ' +
61 + 'This error is likely caused by a bug in React. Please file an issue.',
62 );
63 // If it is not a Fiber, we can just use dynamic dispatch.
64 internalInstance.restoreControlledState();