reflex
reflex copied to clipboard
Starting in 0.8 we can get: TypeError: useContext is not a function or its return value is not iterable
Describe the bug
Forcing a recompile by just adding a blank line causes the exception below.
The exception never happened in 0.7.14
[Reflex Frontend Exception]
TypeError: useContext is not a function or its return value is not iterable
at http://localhost:3000/utils/components.jsx?t=1752717277114:67:38
at react-stack-bottom-frame (http://localhost:3000/node_modules/.vite/deps/react-dom_client.js?v=03abd703:17424:20)
at renderWithHooks (http://localhost:3000/node_modules/.vite/deps/react-dom_client.js?v=03abd703:4206:24)
at updateFunctionComponent (http://localhost:3000/node_modules/.vite/deps/react-dom_client.js?v=03abd703:6619:21)
at updateSimpleMemoComponent (http://localhost:3000/node_modules/.vite/deps/react-dom_client.js?v=03abd703:6528:16)
at beginWork (http://localhost:3000/node_modules/.vite/deps/react-dom_client.js?v=03abd703:7923:20)
at runWithFiberInDEV (http://localhost:3000/node_modules/.vite/deps/react-dom_client.js?v=03abd703:1485:72)
at performUnitOfWork (http://localhost:3000/node_modules/.vite/deps/react-dom_client.js?v=03abd703:10868:98)
at workLoopSync (http://localhost:3000/node_modules/.vite/deps/react-dom_client.js?v=03abd703:10728:43)
at renderRootSync (http://localhost:3000/node_modules/.vite/deps/react-dom_client.js?v=03abd703:10711:13)
To Reproduce The error only ever happened in a large project and not when I tried to create a small test case from scratch. To get around that I started with my large project and kept removing stuff until the exception went away then restored the last remove and kept going with removing other stuff. Eventually I got down to the repo below which is valid but a bit non-sensical from a use perspective.
To reproduce:
- Clone the repo
- Setup venv and install requirements
- Reflex run
- Visit the web page
- Go to a python file like application.py
- Insert a blank line somewhere and wait for the recompile.
- You should get an exception but if not keep trying adding or removing a line and waiting for recompile and see if the exception appears after the recompile. If it still doesn't happen try restarting the app and doing that again.
https://github.com/bertbarabas/test-reflex-regen#
Specifics (please complete the following information):
- Python Version: 3.12.3
- Reflex Version: 0.8.2
- OS: Ubuntu on WSL
*Additional context It seems unrelated to any specific component, perhaps it is timing related. For instance I include a dummy project db on neon. When reproducing the bug a closer region didn't cause the bug so maybe you have to cause some kind of latency to get the timing just right. But it's not just the db, if I removed the @memo it went away. So like I said I don't think it's related to a specific component and it's more likely to show up in larger projects.
This issue occurs when vite hmr causes two different versions of React to be loaded in the browser. We're trying to find a way around it, but it's a bit lower level than what reflex generates/manages
Hi @masenf, any luck with this one? It pretty much blocks development since it requires stopping reflex run and restarting after most changes...
@masenf - Thinking about your point above that this exception is a problem with vite HMR,
I tried both env variables:
VITE_FORCE_FULL_RELOAD=1 VITE_HMR=0
But the useContext exception still happens...