-
-
Notifications
You must be signed in to change notification settings - Fork 5k
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
The 'navigation' object hasn't been initialized yet #6879
Comments
Hey! Thanks for opening the issue. Can you provide a minimal repro which demonstrates the issue? Posting a snippet of your code in the issue is useful, but it's not usually straightforward to run. A repro will help us debug the issue faster. Please try to keep the repro as small as possible. The easiest way to provide a repro is on snack.expo.io. If it's not possible to repro it on snack.expo.io, then you can also provide the repro in a GitHub repository. |
Encountered the same on RN 61.5. My terribly hacky workaround was to wrap navigate() in a setTimeout with 100 ms delay. |
Can you provide a repro to show when the happens? |
This comment has been minimized.
This comment has been minimized.
sure @satya164 , will create snack and share it. |
Closing due to no repro. Please comment with repro to re-open. |
This comment has been minimized.
This comment has been minimized.
https://reactnavigation.org/docs/navigating-without-navigation-prop/#handling-initialization i already did what mentioned above but still same error occurs The 'navigation' object hasn't been initialized yet. This might happen if you don't have a navigator mounted, |
I'm facing this problem in RN 0.62.2 and react-navigation 5.x.x. In my case, this only happens when the Fast refresh feature is enabled and I change some part of my code. it's probably a debug phase problem and should not happens in production, but it's very annoying because it makes the Fast refresh useless to development. I also tried the link you mentioned, the result is the same |
Facing same issue over here. Tried all doc says related with initialization. (https://reactnavigation.org/docs/navigating-without-navigation-prop/#handling-initialization)
|
Hi, I know this issue is closed, but I did some experiments, and it looks like there is different behavior between a I put together a snack (based on the official documentation) that demonstrates this. Swap the commented https://snack.expo.io/H3O3jaNxi I'm a bit surprised that there is a difference between Hope this helps. |
Same here, what's suggested in the doc is not working. https://reactnavigation.org/docs/navigating-without-navigation-prop/#handling-initialization Sometimes the error occurs, sometimes not... |
This works for me, although 0ms is enough. |
I don't know if this can help someone but I solved it by reversing the problem : Instead of navigating-without-navigation-prop and handling-initialization, I made the No need for a |
Why every app should handle it. Queue shold be created by |
+1 on this, I followed what is says here: https://reactnavigation.org/docs/navigating-without-navigation-prop/#handling-initialization still getting the initialization error |
solved it like this, if it helps anyone
|
Doing the same with RN.5.. still getting the initialization error.. |
onReady is returning when we the navigationRef is set, but before it's been initialised |
This issue is still happening. Repro: https://snack.expo.io/1TiQCzjM3 cc @satya164 |
issue still happens even if you're not using useLinking |
Still happens why is closed? this part of documentation is broken |
i think a key for this fix is to make sure that the navigation is "ready" . there's an |
Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro. |
Hey I've got a workaround here! It is basically set "isReady" variable to true only when the first screen inside the navigator is mounted. This is a simplified version of my code when I am working with deep linking which I want to navigate to a screen immediately after the navigator is ready.
And then in Screen1:
I'm passing setState as params and ignoring the warning because I'm not accessing the state somewhere else and I didn't use state persistence or React Navigation's deep link as stated in the Official Docs. But you can use React Context as well :) |
Can confirm that this is still happening on the latest |
My error was that I was missing this ref: |
Not even 1000ms was enough, wrote 2000ms and worked. very disturbing... |
Hi. Did you solve your problem? Interested because of facing the same case |
Having same issue and setTimeout is not working. Why is this issue closed? |
I placed
And it consoled How to get a moment, when it is ready? |
@satya164 why the issue is still closed? there are a lot of reprodution repos |
I created new library for handling navigation initialization |
I still see this after setting a state variable in NavigationContainer's Nothing seems to work (on iOS) |
I have the same issue , React Native 67 and Navigation 6.x have just fixed it , this is an example
|
Facing the same issue |
I had the same issue like a lot of commenters. Tried to navigate upon receiving notifications. Tried the NavigationContainer's ref using the docs https://reactnavigation.org/docs/navigating-without-navigation-prop#handling-initialization The suggested createNavigationContainerRef "didn't work" I used useNavigationContainerRef instead, as @azizmobarak suggested. Now it works like it should. Not sure what's the actual bug here maybe they should just review their docs? @react-navigation/native 6.0.8 |
Would either of you @albert-hajdu-mondd-io or @azizmobarak be able to provide some sort of reproduction as to how you implemented this change? Within the framework given in the react-navigation documentation I was unable to reproduce a successful solution with the information you provided. |
@JoshWeiner something like this:
|
For who is getting this error in a jest test. That's what I did...
|
why this issue closed? if app opened and user click universal link, navigationRef.isReady() - is always false, even after 10 second timeout |
checkout this library |
@oktaysenkan Why you made the lib to fix an issue of another one? If you know how to fix, just make a PR =) |
thanks, your package solved my problem |
My team have experienced "The 'navigation' object hasn't been initialized yet" error inside
rewriting it so every stack is stable with a navigation container solved the issue:
Hope that helps someone. |
I am facing the same issue with deep links and push notifications. I've created a function that checks if the navigationRef is ready and returns a promise.
It checks if navigation is ready each 25 ms. Then in my handleDeepLink function I do
Hope it helps someone. |
I met this problem when I modify font size in the setting app.
|
This is not error, I can't catch it. This is so weird, I tried to call on 'focus' event in the first screen. So I had to resolve with setTimeout. |
For Jest what's weird this worked for me, normally we don't need instance of Stack.Navigator
|
I still get the error. |
Thank you - this was not explicitly mentioned in the docs, and is a crucial step. Maybe its obvious to folks who have been using this library for a while, but was not for me. |
SOLUTION:
But your usage is not.
And you use it automatically without a user event (which normally takes a few seconds..) before the navigation is ready.
|
Current Behavior
Expected Behavior
How to reproduce
app.tsx
NavigationService.ts
I am getting:
Your Environment
NOTE: I am upgrading from 4.x.x via https://reactnavigation.org/docs/en/upgrading-from-4.x.html and https://reactnavigation.org/docs/en/compatibility.html
The text was updated successfully, but these errors were encountered: