Reputation: 574
I'm developing a board game and to test both players I have this piece of code in my componentDidMount
:
window.swap = () => {
this.setState({
self: rotate(this.state.game[0].players, this.state.game[0].players.indexOf(this.state.self))[1]
})
}
This basically chooses the next player in the array of players and sets self
to that so I can impersonate that player.
When I call swap
the first time, it works fine, but when I call it again it it crashes the page. However, if I add a console.log
before, like so:
window.swap = () => {
console.log('what?')
this.setState({
self: rotate(this.state.game[0].players, this.state.game[0].players.indexOf(this.state.self))[1]
})
}
it works fine every time. Even if I do a simple loop for(let i=0; i<100; i++) swap()
it works fine, printing "what?" 100 times.
If I close DevTools and add something like this
setTimeout(() => {
window.swap()
window.swap()
}, 5000)
it works fine, with or without a console.log
on swap
. What?
EDIT:
Tested on:
So apparently this bug is fixed in next Chrome versions
Upvotes: 0
Views: 156
Reputation: 574
This is a bug with Chrome that is fixed in an upcoming version. If someone can point me to an issue page or something, I'm curious to what caused this.
Upvotes: 1