kirill-konshin / next-redux-wrapper

Redux wrapper for Next.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot update a component while rendering a different component

magicDvlp opened this issue · comments

Describe the bug

In version 8.0.1, an error occurs when changing the route.

To Reproduce

codesandbox

Steps to reproduce the behavior:

  1. Go to 'Home' page
  2. Click on 'To another page'
    An error appears in the console: "preview-protocol.js:13 Warning: Cannot update a component (Home) while rendering a different component (App). To locate the bad setState() call inside App, follow the stack trace as described in"

Getting same issue when using

export const getServerSideProps = storeWrapper.getServerSideProps(
  () =>
    async ({ params }) => {
      console.log('params', params);
      return { props: {} };
    }
);

export default connect((state: AppState) => state)(Page);

Will be fixed in #523 but will require some code changes.

I tried out the 9.0.0-rc.2, it still has some major issue for me.

  • Serialization and deserialization issue
  • Navigation between page or updating component causes hydration to not populate data. I tried to change component and it immediately crashes because the data is not hydrate in the store

@hung-phan I've changed the order and implementation of replacer. You need to first serialize your actions, then replacer with remove undefined. In any case Class objects cannot be transferred as JSON, so you need to create your own serializer.