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

with-redux-wrapper example bug #17299

Closed
zhangwei900808 opened this issue Sep 23, 2020 · 3 comments · Fixed by #17335 · 4 remaining pull requests
Closed

with-redux-wrapper example bug #17299

zhangwei900808 opened this issue Sep 23, 2020 · 3 comments · Fixed by #17335 · 4 remaining pull requests
Labels
examples Issue/PR related to examples good first issue Easy to fix issues, good for newcomers

Comments

@zhangwei900808
Copy link

Bug report

Describe the bug

In with-redux-wrapper example index.js page has a code:

export const getStaticProps = wrapper.getStaticProps(async ({ store }) => {
  store.dispatch(serverRenderClock(true))
  store.dispatch(addCount())
})

the reducer.js

import { countActionTypes } from './action'

const countInitialState = {
  count: 0,
}

export default function reducer(state = countInitialState, action) {
  switch (action.type) {
    case countActionTypes.ADD:
      return Object.assign({}, state, {
        count: state.count + 1,
      })
    default:
      return state
  }
}

in getStaticProps code has store.dispatch(addCount())
so when I run the index.js page the page count must be 1 but is 0 is bug?
image

@timneutkens timneutkens added the good first issue Easy to fix issues, good for newcomers label Sep 23, 2020
@lfades lfades added the examples Issue/PR related to examples label Sep 23, 2020
@Pitasi
Copy link
Contributor

Pitasi commented Sep 24, 2020

Hi, I found the problem here: https://github.com/vercel/next.js/blob/canary/examples/with-redux-wrapper/store/store.js#L26
That line should instead be:

    if (state.count.count) nextState.count.count = state.count.count // preserve count value on client side navigation

Since the first "count" key refers to the count reducer, and the second "count" key is the actual value defined in count/reducer.js. (In fact it is used correctly in AddCount.js:23).

Since it's a small change I decided to go ahead and opened a PR: #17335 😄

Pitasi added a commit to Pitasi/next.js that referenced this issue Sep 24, 2020
…7299)

Wrong variable was being checked for the hydrate action on redux. This
was causing the count to be reset to 0 instead of being 1 when initially
loading index.js page.
@kodiakhq kodiakhq bot closed this as completed in #17335 Sep 24, 2020
kodiakhq bot pushed a commit that referenced this issue Sep 24, 2020
…17335)

Wrong variable was being checked for the hydrate action on redux. This was causing the count to be reset to 0 instead of being 1 when initially loading index.js page.

Fixes #17299
@zhangwei900808
Copy link
Author

@Pitasi I try it, It work! very thank you

HitoriSensei pushed a commit to HitoriSensei/next.js that referenced this issue Sep 26, 2020
…7299) (vercel#17335)

Wrong variable was being checked for the hydrate action on redux. This was causing the count to be reset to 0 instead of being 1 when initially loading index.js page.

Fixes vercel#17299
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.