nandorojo / solito

🧍‍♂️ React Native + Next.js, unified.
https://solito.dev
MIT License
3.54k stars 181 forks source link

Debug mode? #162

Closed kevinvangelder closed 2 years ago

kevinvangelder commented 2 years ago

Is there a debug mode I can enable to log Link presses and push/reset/etc calls? My links are working fine in Next but are not working at all in Expo.

kevinvangelder commented 2 years ago

Alternatively, in dev mode could clicking a link that has no matching route simply log could not find route: ${route}? It seems I had misconfigured my linking to nest screens, it would have been very useful to know that the route could not be found versus it seeming like the press wasn't even registering.

nandorojo commented 2 years ago

i believe it should be doing that already…but yeah that sounds useful

nandorojo commented 2 years ago

I wonder if this would help? https://reactnavigation.org/docs/devtools/

kevinvangelder commented 2 years ago

I was only getting errors if the link matched a key that does not exist in the navigation stack or if the link did not exist at all, but my problem was that the link existed but navigation to the key failed because I had nested it (I'm using a BottomTabNavigator and did not fully understand how the linking should be configured). Maybe this is an abnormal enough edge-case that it doesn't need special error handling, but it sure would have saved me a day or two of debugging.

nandorojo commented 2 years ago

We'd essentially have to manually override the built-in useLinkTo function from @react-navigation/native I believe.

nandorojo commented 2 years ago

It may be a good issue to open on the React Navigation repo. But we could consider overriding the function here to improve the DX.

nandorojo commented 2 years ago

This code should be throwing an error for you, so it seems like it's able to parse a state from the URL, but it just isn't the desired one?

      const state = options?.getStateFromPath
        ? options.getStateFromPath(to, options.config)
        : getStateFromPath(to, options?.config);

      if (state) {
        const action = getActionFromState(state, options?.config);

        if (action !== undefined) {
          navigation.dispatch(action);
        } else {
          navigation.reset(state);
        }
      } else {
        throw new Error('Failed to parse the path to a navigation state.');
      }
nandorojo commented 2 years ago

Maybe we can throw an error if there's no action too (assuming that's what happened).

kevinvangelder commented 2 years ago

If you want to reproduce the issue I had you can do so by nesting some valid screens that aren't direct children of the tab navigator in the linking config:

screens: {
  Login: '/login',
  BottomTabs: {
    screens: {
      Main: '/home', // Valid child of bottom tabs
      UserDetails: '/user/:id', // Deeply nested screen, not a direct descendant 
     },
   }
 }
nandorojo commented 2 years ago

Got it. If you're open to adding a PR / testing it, I'm happy to review it! Thanks for reporting this.