Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG [v0.49.12] React Client: broken reactivity for React 18 (works fine with React 17) #1096

Closed
pwoloszun opened this issue Sep 21, 2022 · 3 comments · Fixed by #1104
Closed

Comments

@pwoloszun
Copy link

package.json

    "boardgame.io": "~0.49.12",
    "react": "~18.2.0",
    "react-dom": "~18.2.0",
    "@types/react": "~18.0.20",
    "@types/react-dom": "~18.0.6",
    "typescript": "~4.8.3",

It modifies redux state, BUT do not rerender react component.
Works fine with React 17.0.2

Code:

import type { Game } from "boardgame.io";
import { Client, BoardProps } from 'boardgame.io/react';

// game state
interface MyGameState {
  someValue: number;
}

const MyGame: Game<MyGameState> = {
  setup: () => {
    return { someValue: 1 };
  },

  moves: {
    someMove: (G, ctx) => {
      G.someValue += 1;
    },
  },
};

// board component
interface MyGameProps extends BoardProps<MyGameState> { }

function MyGameBoard(props: MyGameProps) {
  const { G, moves } = props;
  console.log('RERENDER:', props);

  return (
    <div>
      <p>Val: {G.someValue}</p>
      <button onClick={() => moves.someMove()}>Test</button>
    </div>
  );
}

// game client
const App = Client({
  game: MyGame,
  board: MyGameBoard,
});

// React 18: app bootstrap
import React from 'react';
import ReactDOM from 'react-dom/client';

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);


@pwoloszun pwoloszun changed the title [v0.49.12] React Client: broken reactivity for React 18 BUG [v0.49.12] React Client: broken reactivity for React 18 l Sep 21, 2022
@pwoloszun pwoloszun changed the title BUG [v0.49.12] React Client: broken reactivity for React 18 l BUG [v0.49.12] React Client: broken reactivity for React 18 (works fine with React 17) Sep 21, 2022
@nsaritzky
Copy link

I've been trying to figure out why my board wasn't re-rendering. Reverting to React 17 fixed it.

@pwoloszun
Copy link
Author

I've been trying to figure out why my board wasn't re-rendering. Reverting to React 17 fixed it.

Yes it works with React 17.
Still its a bug in React 18.

@nsaritzky
Copy link

Right, I meant that only as a confirming anecdote.

@delucis delucis linked a pull request Oct 26, 2022 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants