Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add maps warning
Maps are still experimental. Warn the first time a map is used.
  • Loading branch information
acdlite committed Feb 2, 2017
commit baacc3e6f50703c555fa0ab80867f46a57a2cca2
38 changes: 31 additions & 7 deletions src/renderers/shared/fiber/ReactChildFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ if (__DEV__) {
var { getCurrentFiberStackAddendum } = require('ReactDebugCurrentFiber');
var { getComponentName } = require('ReactFiberTreeReflection');
var warning = require('warning');
var didWarnAboutMaps = false;
}

const {
Expand Down Expand Up @@ -118,13 +119,10 @@ function throwOnInvalidObjectType(returnFiber : Fiber, newChild : Object) {
' If you meant to render a collection of children, use an array ' +
'instead or wrap the object using createFragment(object) from the ' +
'React add-ons.';
const owner = ReactCurrentOwner.owner || returnFiber._debugOwner;
if (owner && typeof owner.tag === 'number') {
const name = getComponentName((owner : any));
if (name) {
addendum += '\n\nCheck the render method of `' + name + '`.';
}
}
const ownerName = getOwnerName(returnFiber);
addendum += ownerName ?
'\n\nCheck the render method of `' + ownerName + '`.' :
'';
}
invariant(
false,
Expand All @@ -137,6 +135,16 @@ function throwOnInvalidObjectType(returnFiber : Fiber, newChild : Object) {
}
}

function getOwnerName(returnFiber : Fiber) : string | null {
if (__DEV__) {
const owner = ReactCurrentOwner.current || returnFiber._debugOwner;
if (owner && typeof owner.tag === 'number') {
return getComponentName((owner : any));
}
}
return null;
}

// This wrapper function exists because I expect to clone the code in each path
// to be able to optimize each path individually by branching early. This needs
// a compiler or we can do it manually. Helpers that don't need this branching
Expand Down Expand Up @@ -828,6 +836,22 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
iteratorFn === newChildrenIterable.entries;

if (__DEV__) {
if (isMap && !didWarnAboutMaps) {
// Warn about experimental maps usage the first time a map is used.
const ownerName = getOwnerName(returnFiber);
const addendum = ownerName ?
'\n\nCheck the render method of `' + ownerName + '`.' :
'';
warning(
didWarnAboutMaps,
'Using Maps as children is not yet fully supported. It is an ' +
'experimental feature that might be removed. Convert it to a ' +
'sequence / iterable of keyed ReactElements instead.%s',
addendum
);
didWarnAboutMaps = true;
}

// First, validate keys.
// We'll get a different iterator later for the main pass.
const newChildren = iteratorFn.call(newChildrenIterable);
Expand Down