Reputation: 12465
I have a react-native sample which works fine in simulator. But when I try to debug it in the chrome, it stops working.
I am using Navigator, first page is a greeting, which works fine. When I enable debug, the behavior is like this : Go to the first page, every thing is fine. Click on enter button to enter the app, I can see the messages from my render function in chrome, but there is no visual change Click again on the same button, give erros : many
Warning: flattenChildren(...): Encountered two children with the same key,
.0:$0
. Child keys must be unique; when two children share a key, only the first child will be used.
And at the end
Exception 'shadowView (for ID 19) not found' was thrown while invoking replaceExistingNonRootView on target RCTUIManager with params ( 19, 446 )
The component that might cause the error is as follows ( it is a chess board)
var Dimensions = require('Dimensions');
var fen = require('../logic/fen');
var windowSize = Dimensions.get('window');
import React, {
AppRegistry,
Component,
TouchableHighlight,
StyleSheet,
Text,
View
} from 'react-native';
const Square = require('./square');
const Piece = require('./piece.component');
const CONSTANTS = require('./constants');
var squares = [];
var pieces = [];
var createRow = function(i, width) {
for (let j = 0; j < 8; j++) {
squares.push(<Square width={width} key={i*10+j} row = {i} column = {j} onSquareSelected = {this.squareSelected}></Square>
);
}
}
var createBoard = function(width) {
for (let i = 0; i < 8; i++) {
createRow(i, width);
}
};
const Board = React.createClass({
componentWillMount() {
this.pieceWidth = this.props.width/8;
createBoard(this.pieceWidth);
this.createPieces();
},
createPieces(){
console.log('Creating pieces');
let pieceDefinitions = fen.read(fen.initial);
pieces = [];
var key = 0;
for(let p in pieceDefinitions){
key = key +1 ;
console.log('piece key is ' + key)
pieces.push(
<Piece key={key} width ={this.pieceWidth} coordinate={p} color = {pieceDefinitions[p].color}
role = {pieceDefinitions[p].role}>
</Piece>
)
}
return pieces;
},
squareSelected(row, column) {
console.log("Row", row, "Column", column, "selected");
},
getInitialState() {
return { selectedPiece: null }
},
render() {
return (
<View style={[styles.container, {width : this.props.width ,height: this.props.width}]}>
{squares}
{pieces}
</View>
)
}
});
const styles = StyleSheet.create({
container: {
marginTop : 20,
backgroundColor: '#F5FCFF',
flexDirection: 'row',
flexWrap: 'wrap',
}
})
module.exports = Board;
Upvotes: 2
Views: 733
Reputation: 3175
Apparently any RN code that uses let
breaks completely in the Chrome debugger. There is no solution. We are screwed. I believe that the transpiler used by RN wraps each block that contains even a single let
in a closure, and suddenly this
is something else like _this2
, but Chrome debugger doesn't know that.
Upvotes: 3