boardgame.io
boardgame.io copied to clipboard
React board component doesn’t re-render with React 18
Good afternoon!
Thanks for the great library that makes it easier to make games!
I was experimenting with recreating a card game called The Game
and I am running into the issue where I call moves.SomeMove(args)
from the UI, which does update the state of G but the UI doesn't seem to recognize it. The reason I know it gets updated is because if I place the same card on the same pile twice, it gives me an invalid move error in the console (as expected).
I don't do much of the front-end development, so it's likely I am just doing something wrong. Could anyone help me take a look at what it is?
This is my repo: https://github.com/eurubkov/the-game
To repro, just drag a card from the bottom row and drop it into any of the boxes at the top row. The top row should get updated with this new card and the card should disappear from the bottom row but neither of these things is happening.
The move: ./src/Game.js PlayCard
The Drop event in the UI: ./src/Board.js onDragDrop
Appreciate the time and help!
Thanks for the bug report! Our React client is currently incompatible with React 18 unfortunately, we need to update it.
For now you should be able to downgrade to React 17:
npm i react@^17 react-dom@^17 @testing-library/react@^12
And update src/index.js
to use the React 17 API for setting up the app by doing the inverse of what is described in the 17 to 18 migration guide: https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html#updates-to-client-rendering-apis
Let’s keep this open to track React 18 support :-)
Thanks for the bug report! Our React client is currently incompatible with React 18 unfortunately, we need to update it.
For now you should be able to downgrade to React 17:
npm i react@^17 react-dom@^17 @testing-library/react@^12
And update
src/index.js
to use the React 17 API for setting up the app by doing the inverse of what is described in the 17 to 18 migration guide: https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html#updates-to-client-rendering-apisLet’s keep this open to track React 18 support :-)
Appreciate the quick response! I will try it later and report back. How big of a job do you think adding React 18 support is going to be? I could try to tackle it
I haven’t had a chance to dive into React 18 enough to be sure, but I wonder if there’s some deprecated method used in the WrappedBoard
class we return from the Client
factory:
https://github.com/boardgameio/boardgame.io/blob/3cef3bb2be9b82a2baa53efceeb8ef80f45da070/src/client/react.tsx#L94-L192
My guess is that it could be a small change if we can spot what the needed change is. If you do have time, I’d love to look at a PR or answer any questions you might have :-)
(One hint might be in #1068 where someone reported componentWillUnmount
maybe being an issue? But I’m not sure if that’s connected.)