Skip to content
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

usePathname usage in layouts breaks production builds at runtime #811

Open
matthewhausman opened this issue Jul 26, 2023 · 6 comments
Open

Comments

@matthewhausman
Copy link

Which package manager are you using? (Yarn is recommended)

yarn

Summary

Expo router version ^1.4.3

Minimal reproducible example

easily reproducible. run app with expo start --no-dev

@matthewhausman
Copy link
Author

works just fine in development. an error here would be great if this is not intended usage because it's very difficult to find the root cause

@matthewhausman matthewhausman changed the title usePathname usage in layouts breaks production builds usePathname usage in layouts breaks production builds at runtime Jul 26, 2023
@matthewhausman
Copy link
Author

actually, it is all and any usage of usePathname

@matthewhausman
Copy link
Author

usePathname isn't breaking when used in a client component (non navigation related)

@marklawlor
Copy link
Contributor

Please provide a full Minimal reproducible example and test on Expo Router v2

@maioradv
Copy link

maioradv commented Nov 6, 2023

i can confirm that, i'm using usePathname in a layout to save an history of the visited page in the app and the backhandler to goback on hardwarebackpress.
in production it throws me this error :
com.facebook.react.common.JavascriptException: TypeError: Cannot read property 'pathname' of undefined, js engine: hermes, stack:
since i dont use .pathname anywhere in my code it's clear that inside usePathname doesnt check if the property exists

just saw your code:
/** @returns global selected pathname without query parameters. */ export function usePathname(): string { return useStoreRouteInfo().pathname; }

the problem its probably that in first moment useStoreRouteInfo() cant return anything so using usePathname in a place where this can happen throws the exception

@EvanBacon
Copy link
Contributor

Please provide a reproducible example of the issue so we can investigate further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants