0

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:

  • Chrome 70 (crash)
  • Chrome Canary (72), Chromium, Firefox, Edge (ok)

So apparently this bug is fixed in next Chrome versions

2
  • When you say "crashes the page", do you mean you get an "aw, snap" message? Commented Oct 23, 2018 at 12:14
  • Yes, and DevTools gets disconnected Commented Oct 23, 2018 at 14:24

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.