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

Issue with v8.0 of library #492

Open
ajdiyassin opened this issue Sep 30, 2022 · 8 comments
Open

Issue with v8.0 of library #492

ajdiyassin opened this issue Sep 30, 2022 · 8 comments
Labels

Comments

@ajdiyassin
Copy link

Describe the bug

I'm having an issue with the latest version of the library. v8.0
The new version somehow reset the state(or it stays empty as the initial state) during navigation only. when I visit the page through a URL or a hard refresh this is not an issue I get the expected state. but when navigating the client side my app just crashes cause of an empty state.

To Reproduce

Steps to reproduce the behavior:

  1. Have an app with multiple pages
  2. Navigate to the second page which is using getStaticProps or getServerSideProps
  3. Empty state error

Expected behavior

Reverting back to version 7.0.5 fixed the issue.

Desktop (please complete the following information):

  • Browser Chrome
  • Version WIN 10

Additional context

Dependencies I'm using:

  "@reduxjs/toolkit": "^1.8.5",
  "next": "^12.3.1",
  "next-with-less": "^2.0.5",
  "react": "18.2.0",
  "react-dom": "18.2.0",
  "react-fast-compare": "^3.2.0",
  "react-icons": "^4.4.0",
  "react-redux": "^8.0.4",

Thanks!

@ajdiyassin ajdiyassin added the bug label Sep 30, 2022
@Osein
Copy link

Osein commented Oct 19, 2022

When i upgrade to v8 this happens on my project too, reverted back to v7

@kirill-konshin
Copy link
Owner

Please provide a codesandbox

@MrDockal
Copy link

MrDockal commented Nov 2, 2022

As a temporary workaround, you can disable client-side transitions between routes.
Simply replace <Link href=""/> from 'next/link' with the <a href="">

To me, it looks like it's a duplicate of #495

@kirill-konshin
Copy link
Owner

As a temporary workaround, you can disable client-side transitions between routes. Simply replace <Link href=""/> from 'next/link' with the <a href="">

To me, it looks like it's a duplicate of #495

Do not do that. You will ruin client side state.

@kirill-konshin
Copy link
Owner

@ajdiyassin @Osein most likely there is some issue in your HYDRATE handler. It overwrites the store's state. Check the Redux Dev Tools to see how your client state has changed during navigation.

And please provide codesandbox so I can debug.

@hasankhurshid29
Copy link

Same happening with me v8.0

@hasankhurshid29
Copy link

If anyone finds how to solve this issue with v8.0, please guide me.
@ajdiyassin @Osein

@rsagiev
Copy link

rsagiev commented Dec 25, 2022

I make my own version of wrapper
store.js

let store;
let prev = null;

const makeStore = (preloadedState) => {
  return configureStore({
    reducer: {
      main: mainReducer,
      home: homeReducer,
      viewport: viewportReducer,
      blog: blogReducer,
      portfolio: portfolioReducer,
      pages: pagesReducer
    },
    preloadedState: mergeDeep(initialState, preloadedState),
    devTools: process.env.NODE_ENV !== 'production'
  });
};

export const getStore = (preloadedState) => {
  if (typeof window === 'undefined') return makeStore(preloadedState); // for SSR

  if (!store) {
    store = makeStore(preloadedState);
  } else {
    if (prev !== preloadedState && preloadedState) {
      store.dispatch({
        type: 'HYDRATE',
        payload: preloadedState,
      });
      prev = preloadedState;
      console.log('after hydrate', store.getState());
    }
  }

  return store;
};

_app.js

const MyApp = ({ Component, pageProps }) => {
  const { initialState, ...restPageProps } = pageProps;
  const store = getStore(initialState);
  const router = useRouter();

  return (
    <>
      <Provider store={store}>
        <Component {...restPageProps} />
      </Provider>
    </>
  );
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants