TypeError: batch is not a function
at Object.batch [as notify] (node_modules/react-redux/lib/utils/Subscription.js:29:7)
at Subscription.notify [as notifyNestedSubs] (node_modules/react-redux/lib/utils/Subscription.js:71:20)
at notifyNestedSubs (node_modules/react-redux/lib/components/connectAdvanced.js:272:13)
at checkForUpdates (node_modules/react-redux/lib/components/connectAdvanced.js:296:9)
at create (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:10867:26)
at commitHookEffectList (node_modules/react-test-renderer/cjs/react-test-renderer.develo
Versions
"react": "^16.9.0",
"react-native": "0.60.5",
"react-redux": "7.0.0",
"redux": "^4.0.0",
"redux-persist": "^5.10.0",
Once I updated to 7.0, this problem appears in all test cases using react-redux.
When I go into node_modules/react-redux/lib/utils/Subscription.js and change line
var batch = (0, _batch.getBatch)();
to
var batch = (0, _batch.getBatch);
it works fine
Was able to temporarily get around the issue with this.
jest.mock('../../node_modules/react-redux/lib/utils/batch.js', () => ({
setBatch: jest.fn(),
getBatch: () => fn => fn()
}))
I would update beyond 7.0.0 exactly. At least 7.0.2, if not the latest 7.1.1.
@timdorr
Have updated to updated and refreshed node_modules, still the same issue.
"react-redux": "7.1.1",
"redux": "^4.0.4",
Can you show an example of the test code that you're using? Is it possible that it's bypassing our index file somehow?
My thought was Alister is doing direct imports. But even then, the getBatch function should still be an actual function.
We should bring over flat bundles to this library at some point. But for now, I would make sure you're doing import { connect } from 'react-redux' and not doing a direct import anywhere.
hey guys,
I think this is something to do with the react-dom version?
Looking at the following code:
https://github.com/reduxjs/react-redux/blob/6c873c7e5ab7504ef3d17e68a0cebdde168d8292/src/utils/batch.js#L9
https://github.com/reduxjs/react-redux/blob/6c873c7e5ab7504ef3d17e68a0cebdde168d8292/src/index.js#L11
https://github.com/reduxjs/react-redux/blob/6c873c7e5ab7504ef3d17e68a0cebdde168d8292/src/utils/reactBatchedUpdates.js#L2
if unstable_batchedUpdates doesn't exist, this error would happen, right?
Sorry actually I think it's to do with the react-native mock we have
We're using react-native-mock-render which doesn't have the unstable_batchedUpdates method
Yep, that would do it. Nothing we can do on our end. We depend on that API existing in your react-dom/native implementation.
IMHO, they should add the unstable_* APIs, as those are part of the public API currently (despite their unstable nature). But until they do, we can't do anything on our end.
Was able to temporarily get around the issue with this.
jest.mock('../../node_modules/react-redux/lib/utils/batch.js', () => ({ setBatch: jest.fn(), getBatch: () => fn => fn() }))
Tnx. This works for me.
In case it helps anyone, here is how I've attempted to implement unstable_batchedUpdates for my React custom renderer without creating a dependency upon React DOM or React Native. It's undocumented, so I have no idea.
My app is now freezing at run-time post state update, rather than crashing at startup, so I think it's at least a step in the right direction. And the latter part about freezing may not even be related.
EDIT: My methodology seems to be exactly the same as that used by react-three, so I can at least have some confidence in advising it.
Most helpful comment
Was able to temporarily get around the issue with this.