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

fix: Deep link - /a/hello loads twice when navigate via link #42464

Merged
merged 3 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Expensify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ function Expensify({
const isAuthenticated = useMemo(() => !!(session?.authToken ?? null), [session]);
const autoAuthState = useMemo(() => session?.autoAuthState ?? '', [session]);

const isAuthenticatedRef = useRef(false);
isAuthenticatedRef.current = isAuthenticated;

const contextValue = useMemo(
() => ({
isSplashHidden,
Expand Down Expand Up @@ -194,7 +197,8 @@ function Expensify({

// Open chat report from a deep link (only mobile native)
Linking.addEventListener('url', (state) => {
Report.openReportFromDeepLink(state.url);
// We need to pass isAuthenticated to avoid having a non-existing profile page is loaded twice
Report.openReportFromDeepLink(state.url, !isAuthenticatedRef.current);
});

return () => {
Expand Down
6 changes: 5 additions & 1 deletion src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2458,7 +2458,7 @@ function toggleEmojiReaction(
addEmojiReaction(originalReportID, reportAction.reportActionID, emoji, skinTone);
}

function openReportFromDeepLink(url: string) {
function openReportFromDeepLink(url: string, shouldNavigate = true) {
const reportID = ReportUtils.getReportIDFromLink(url);

if (reportID && !Session.hasAuthToken()) {
Expand Down Expand Up @@ -2496,6 +2496,10 @@ function openReportFromDeepLink(url: string) {
return;
}

if (!shouldNavigate) {
return;
}

Navigation.navigate(route as Route, CONST.NAVIGATION.ACTION_TYPE.PUSH);
});
});
Expand Down
Loading