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

weird initialState of redux-toolkit in next js 13 #3154

Closed
vishalkumar2806 opened this issue Feb 3, 2023 · 15 comments · Fixed by vercel/next.js#45649
Closed

weird initialState of redux-toolkit in next js 13 #3154

vishalkumar2806 opened this issue Feb 3, 2023 · 15 comments · Fixed by vercel/next.js#45649

Comments

@vishalkumar2806
Copy link

i tried everything as per tutorial and connect my next js 13 with the provider with redux-toolkit but Im getting weird state not the state I defined. My code is exactly like the counter tutorial on react redux documentation. Anyone solution I was expecting a state with a counter variable with a value of zero.
issue

@phryneas
Copy link
Member

phryneas commented Feb 3, 2023

Take a look at the dropdown in the top right. That is not the internal state of the web site you are building, but the internal state of some "Free Gift Card Generator" - maybe another tab you have open or a browser plugin that injected itself into your site?

@vishalkumar2806
Copy link
Author

Yeah thats im building and its correct

@phryneas
Copy link
Member

phryneas commented Feb 3, 2023

Still, have you checked that dropdown if there are any other stores in there that could actually be your Redux store that you are building? There can sometimes be multiple stores on one page, often accidentally.

@vishalkumar2806
Copy link
Author

yes i check there is no other instance working. I generally don't open many tabs

@vishalkumar2806
Copy link
Author

you can come to my desktop and fix this thing by yourself

@phryneas
Copy link
Member

phryneas commented Feb 3, 2023

Did you accidentally import the wrong reducer in your store setup? Possibly from @nextjs/client/components/reducer or a similar place?

Please share your store setup file here, including imports.

@markerikson
Copy link
Collaborator

Yeah, that specifically looks like https://github.com/vercel/next.js/blob/4e2267ff61bcee74c26f16ec7675bf29338af141/packages/next/src/client/components/router-reducer/reducers/refresh-reducer.ts#L37 .

That tells me what you're looking at is definitely not your own application code somehow.

@vishalkumar2806
Copy link
Author

tree directory
directory tree
store.tcx
store
counterReducer.tcx
counterslice

@markerikson
Copy link
Collaborator

Store setup seems fine. Honestly, this just looks like the DevTools are somehow showing something that's not part of your app, and that's not an issue with RTK itself.

I'd double-check to see if there are any other options listed in the "Instances" dropdown menu.

@vishalkumar2806
Copy link
Author

okie thankx

@vishalkumar2806
Copy link
Author

1
yes you are correct its showing me the state of next-router now but my instance is not showing when I click the dropdown menu

@mxswat
Copy link

mxswat commented Feb 3, 2023

image

I'm having the same issue; it's showing me the next router state

@markerikson
Copy link
Collaborator

Folks, whatever's going on here is not actually a Redux Toolkit problem specifically. If anything, it's a Redux DevTools problem.

Your best bet is to file an issue in the Redux DevTools repo, with an app repo that demonstrates this problem happening.

@reduxjs reduxjs locked as resolved and limited conversation to collaborators Feb 3, 2023
@markerikson
Copy link
Collaborator

markerikson commented Feb 3, 2023

Short update: Looking at https://github.com/vercel/next.js/commits/canary/packages/next/src/client/components/router-reducer/reducers/refresh-reducer.ts , it does look like the Next folks have been working on this file recently. Per https://github.com/vercel/next.js/blob/0d7f7653e81a4f2aa16be7ead286e09b22761f52/packages/next/src/client/components/app-router.tsx#L32 , they also have a useReducerWithReduxDevtools hook that may be related.

I've asked them if they made any recent changes that might be affecting the DevTools, but overall this looks like it's a Next-related bug.

@markerikson
Copy link
Collaborator

Update: confirmed that this is a Next bug. They tried to wrap useReducer to talk to the Redux DevTools, but hardcoded the instanceId:

https://github.com/vercel/next.js/blob/0d7f7653e81a4f2aa16be7ead286e09b22761f52/packages/next/src/client/components/use-reducer-with-devtools.ts#LL144-L149C6

I've passed along a suggestion to have them fix that and call the Redux DevTools connect() method correctly.

kodiakhq bot pushed a commit to vercel/next.js that referenced this issue Feb 7, 2023
Fixes reduxjs/redux-toolkit#3154

Thanks @markerikson for helping out on this one.



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants