0

I've seen error in Sentry. It says: "undefined is not an object", and shows snippet like this: const someVariable = useSelector((state) => state.someReducer.someVariable); It is very hard to reproduce. You need to reload page more then 100 times to catch this case. Next.js will handle it with "Page not found message". I don't know, how can it be? Looks like Next.js sometimes randomly somehow run _app and component before Redux store is ready. I can't find any meaningful message, looks like Next.js simply hiding something or optimizing something. I can't reproduce it often enough to figure out what is wrong. How can I handle this? Thank you for help.

3
  • Please provide a minimal reproducible example. Commented Dec 7, 2021 at 16:25
  • This is a problem. It is not reproducible. You can catch it one time from hundred. It happens on page load start. Redux store should be initialized with initial data. And in this time initial state from one of reducers is absent. I made workaround with page reload, but I need to know real cause of this. Maybe somebody has some similar hard reproducible undefine prop in initial redux store using next.js, redux-toolkit and axios. I hope somebody will recognize this case or answer with couple real examples when something like this can happen. And how to handle this without page reload.
    – Ivan Driuk
    Commented Dec 8, 2021 at 18:40
  • For example, do you know cases then createAsyncThunk(...) will be undefined randomly (once per hundred) on page load ? I think it is connected somehow to next.js or browser optimizations. And sometimes next.js or redux-toolkit or axios can't handle something, after that action become undefined , [action.pending] in reducer became undefined, reducer became undefined. Maybe somebody met examples of similar hard reproducible cases?
    – Ivan Driuk
    Commented Dec 8, 2021 at 20:40

0