-
Notifications
You must be signed in to change notification settings - Fork 47k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/renderers/shared/devtools/ReactChildrenMutationWarningDevtool.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* Copyright 2013-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule ReactChildrenMutationWarningDevtool | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var ReactComponentTreeDevtool = require('ReactComponentTreeDevtool'); | ||
|
||
var warning = require('warning'); | ||
|
||
function handleElement(debugID, element) { | ||
if (element == null) { | ||
return; | ||
} | ||
if (element._shadowChildren === undefined) { | ||
return; | ||
} | ||
if (element._shadowChildren === element.props.children) { | ||
return; | ||
} | ||
var isMutated = false; | ||
if (Array.isArray(element._shadowChildren)) { | ||
if (element._shadowChildren.length === element.props.children.length) { | ||
for (var i = 0; i < element._shadowChildren.length; i++) { | ||
if (element._shadowChildren[i] !== element.props.children[i]) { | ||
isMutated = true; | ||
} | ||
} | ||
} else { | ||
isMutated = true; | ||
} | ||
} | ||
warning( | ||
Array.isArray(element._shadowChildren) && !isMutated, | ||
'Component\'s children should not be mutated.%s', | ||
ReactComponentTreeDevtool.getStackAddendumByID(debugID), | ||
); | ||
} | ||
|
||
var ReactDOMUnknownPropertyDevtool = { | ||
onBeforeMountComponent(debugID, element) { | ||
handleElement(debugID, element); | ||
}, | ||
onBeforeUpdateComponent(debugID, element) { | ||
handleElement(debugID, element); | ||
}, | ||
}; | ||
|
||
module.exports = ReactDOMUnknownPropertyDevtool; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters