Closed zy-jtp closed 4 months ago
It looks like there is another place that is missing the getCurrent
method for getting the state id, as described in https://github.com/reduxjs/redux-toolkit/pull/4412
In my case, this happens on a sorted state and only occurs after a seconds add mutation.
PR description:
I had added a getCurrent() util that checks if the value is draftable before calling current(value), but missed a spot. Turns out that a sequence of removeAll() + upsertMany() hits the case where now state.ids is a plain array, and thus current(state.ids) will throw because it's a plain value and not a draft.
This is the relavant line: https://github.com/reduxjs/redux-toolkit/blob/ff65194d84ea80f5293ae4af1a413878cef3eb31/packages/toolkit/src/entities/sorted_state_adapter.ts#L74
sigh Thanks. Busy atm, but could you throw up a PR to fix that one as well?
Here is a PR to fix this issue.
Fix released in v2.2.6 😄
Unhandled Runtime Error | Error: [Immer] 'current' expects a draft, got:
Example Repo
https://github.com/zy-jtp/rtk-next14-error
Context
pages
, notapp
router.The call triggering the error is a dispatch call to modals slice from an
onClick
callbackits initial state comes from an
entityAdapter
Runtime Error