Repository navigation
Public Room - User is logged out after opening a public room - #70382
Conversation
|
We are migrating Onyx.Connect as much as possible. but I think waiting for onyx value to load could delay some other logic in that hook. We can create a HOC to deal with it but that will delay app rendering as Expensify is root component. I think it is better to stick with Onyx.connectWithoutView for this case. @dukenv0307 |
|
@dukenv0307 Can you please verify whether this PR solves all of these? I will check too. |
rojiphil
left a comment
There was a problem hiding this comment.
@dukenv0307 I have left some comments. Please have a look. Thanks.
|
|
||
| // Display a blank page until the onyx migration completes | ||
| if (!isOnyxMigrated) { | ||
| if (!isOnyxMigrated || isLoadingOnyxValue(sessionMetadata)) { |
There was a problem hiding this comment.
Why do we need to keep showing the blank page until we fetch session data? Wondering what problems we ran into here.
There was a problem hiding this comment.
We're using isAuthenticated to show PublicScreens or AuthScreens, so I think we should wait for session data to be loaded to avoid unexpected errors.
@parasharrajat Since |
|
|
||
| // Display a blank page until the onyx migration completes | ||
| if (!isOnyxMigrated) { | ||
| if (!isOnyxMigrated || isLoadingOnyxValue(sessionMetadata)) { |
There was a problem hiding this comment.
Should we keep showing a blank page until we fetch session data?
I am on the fence about this.
@mountiny what do you think?
There was a problem hiding this comment.
Can you describe the flow right now and what is proposed to do?
Also curious what caused this change? Previously we havent had this problem, as far as I know
There was a problem hiding this comment.
I think we were using WithOnyx HOC earlier.
There was a problem hiding this comment.
I agree with @rojiphil here. We shouldn’t gate the whole app on session load. This issue is from acting before session state stabilises, not rendering.
Related to my earlier note on deep-link listener duplication: set up the listener once with cleanup, fetch the initial URL once and process it after session metadata finishes loading, while letting the loader/splasher render normally.
Let's create HOC in that case to load session data. |
Regarding the flow right now, the RCA in the proposal looks accurate to me i.e. The proposed approach is to call the 70382-web-chrome-001.mp4 |
That’s a very good question. Seems like the problem existed for quite some time but surfaced only recently due to the side effect been triggered even before the session data was fetched. Not able to pinpoint exactly what caused this though. |
@parasharrajat I do not see any distinct advantage of using HOC here over the proposed solution. Or am I missing something here? |
|
If we use the HOC the session data will be ready on first render of the component. It might be slightly delayed by few ms but we will have main data ready. |
|
The proposed solution here also has a similar effect. In that case, I think it would be better to avoid one more component and use the proposed solution here. |
|
to me the second loading on your dev looks good to me, no issue there #70382 (comment) cc @Expensify/design in case you would have any feedback @rojiphil could you go ahead with the checklist please? |
Reviewer Checklist
Screenshots/VideosAndroid: HybridApp70382-android-native-001.mp4Android: mWeb Chrome70382-mweb-chrome-001.mp4iOS: HybridApp70382-ios-hybrid-001.mp4iOS: mWeb Safari70382-mweb-safari-001.mp4MacOS: Chrome / Safari70382-web-chrome-001.mp4MacOS: Desktop70382-desktop-001.mp4 |
rojiphil
left a comment
There was a problem hiding this comment.
Thanks @dukenv0307 for the PR and updates.
@mountiny Changes LGTM and works well too.
All yours. Thanks.
|
We did not find an internal engineer to review this PR, trying to assign a random engineer to #68719 as well as to this PR... Please reach out for help on Slack if no one gets assigned! |
| }; | ||
| // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps -- we don't want this effect to run again | ||
| }, []); | ||
| }, [sessionMetadata?.status]); |
There was a problem hiding this comment.
Changes look good in terms of addressing the current problem, but I'm concerned we might introduce a new regression linked to deep-link listener duplication. Because the effect now re-runs on session metadata changes and re-adds the Linking 'url' listener without cleanup, therefore could cause multiple navigations/API calls.
There was a problem hiding this comment.
We could set up the Linking 'url' listener once in a single effect (and clean it up on unmount), avoiding any dependency on session metadata for its setup. Fetch the initial URL once, store it, and process it only after session metadata finishes loading, ensuring it’s handled exactly once (e.g., with a “processed” guard).
There was a problem hiding this comment.
@inimaga I think we can keep the current approach and clear the listener in the cleanup function. Another fact, sessionMetadata?.status is only changed once and we skipped when the status is loading.
const linkingChangeListener = Linking.addEventListener('url', (state) => {
Report.openReportFromDeepLink(state.url, currentOnboardingPurposeSelected, currentOnboardingCompanySize, onboardingInitialPath, allReports);
});
return () => {
if (!appStateChangeListener.current) {
return;
}
appStateChangeListener.current.remove();
linkingChangeListener.remove();
};
There was a problem hiding this comment.
Actually, I think that's fine, because
- We already had the logic to return early at the beginning of this hook
if (isLoadingOnyxValue(sessionMetadata)) {
return;
}
and sessionMetadata?.status only changes from loading to loaded, which means the Linking logic only triggers 1 time
- In this hook, we used
isAuthenticatedmany times we should wait until the session data is loaded to prevent the same issue
There was a problem hiding this comment.
Good point on the early return. It helps, but there are still end‑user flows where session status changes more than once (e.g., sign‑out then sign‑in, switching accounts, opening a public room first and then signing in). So wouldn't put too much faith in sessionMetadata?.status only changing once.
|
|
||
| // Display a blank page until the onyx migration completes | ||
| if (!isOnyxMigrated) { | ||
| if (!isOnyxMigrated || isLoadingOnyxValue(sessionMetadata)) { |
There was a problem hiding this comment.
I agree with @rojiphil here. We shouldn’t gate the whole app on session load. This issue is from acting before session state stabilises, not rendering.
Related to my earlier note on deep-link listener duplication: set up the listener once with cleanup, fetch the initial URL once and process it after session metadata finishes loading, while letting the loader/splasher render normally.
PR SummaryFixed a bug where users were being logged out when opening a public room via a direct link. The issue was caused by improper session state handling during deep link navigation. The solution properly tracks authentication state and prevents unnecessary logout when accessing public rooms through links. Changes
autogenerated by presubmit.ai |
|
@dukenv0307 can you please address the PR comments with urgency? |
There was a problem hiding this comment.
✅ LGTM!
Review Summary
Commits Considered (7)
Files Processed (2)
- src/Expensify.tsx (6 hunks)
- src/libs/actions/Report.ts (2 hunks)
Actionable Comments (0)
Skipped Comments (7)
-
src/Expensify.tsx [98-98]
enhancement: "Session metadata extraction improves loading state detection"
-
src/Expensify.tsx [189-191]
best practice: "Prevent premature initialization before session data loads"
-
src/Expensify.tsx [230-230]
enhancement: "Authentication state now properly passed to deep link handler"
-
src/Expensify.tsx [248-248]
possible issue: "Effect dependency on session status may be incomplete"
-
src/Expensify.tsx [283-283]
enhancement: "Prevent rendering before session data loads"
-
src/libs/actions/Report.ts [226-226]
possible issue: "Removed hasAuthToken import may affect other functions"
-
src/libs/actions/Report.ts [3399-3399]
best practice: "Authentication state now passed as parameter improves function design"
There was a problem hiding this comment.
🚨 Pull request needs attention.
Review Summary
Commits Considered (1)
- 2ed1e46: remove isLoadingOnyxValue check
Files Processed (2)
- src/Expensify.tsx (5 hunks)
- src/libs/actions/Report.ts (2 hunks)
Actionable Comments (2)
-
src/Expensify.tsx [189-191]
possible bug: "Potential memory leak with event listeners"
-
src/Expensify.tsx [248-248]
performance: "Missing cleanup for event listeners on dependency change"
Skipped Comments (2)
-
src/Expensify.tsx [230-230]
possible issue: "Potential race condition with authentication state"
-
src/libs/actions/Report.ts [226-226]
possible issue: "Removed function from imports may affect other code"
| if (isLoadingOnyxValue(sessionMetadata)) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
This early return prevents the effect from running when session metadata is still loading, but it doesn't properly clean up any previously set listeners. If the component re-renders while sessionMetadata is loading, the cleanup function won't be called. Consider moving the early return condition inside the timeout callback or restructuring the effect to ensure proper cleanup regardless of the loading state.
| }; | ||
| // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps -- we don't want this effect to run again | ||
| }, []); | ||
| }, [sessionMetadata?.status]); |
There was a problem hiding this comment.
The effect dependency is now set to sessionMetadata?.status, which means the effect will re-run whenever the session status changes. However, the effect contains event listeners that are being added without proper cleanup between re-runs. This could lead to duplicate event listeners and multiple executions of the same code when deep links are opened. Consider storing the event listener reference and removing it in the cleanup function to prevent memory leaks and duplicate handlers.
There was a problem hiding this comment.
🚨 Pull request needs attention.
Review Summary
Commits Considered (1)
- fa35a9d: clean linking listener
Files Processed (1)
- src/Expensify.tsx (5 hunks)
Actionable Comments (4)
-
src/Expensify.tsx [234-236]
possible issue: "Potential memory leak with event listener"
-
src/Expensify.tsx [189-191]
possible bug: "Early return prevents proper cleanup of effect resources"
-
src/Expensify.tsx [230-230]
performance: "Passing entire object as dependency"
-
src/Expensify.tsx [235-235]
performance: "Passing entire object in event handler"
Skipped Comments (0)
| const linkingChangeListener = Linking.addEventListener('url', (state) => { | ||
| Report.openReportFromDeepLink(state.url, currentOnboardingPurposeSelected, currentOnboardingCompanySize, onboardingInitialPath, allReports, isAuthenticated); | ||
| }); |
There was a problem hiding this comment.
The event listener is correctly created and stored in a variable, but there's a potential issue with how it's cleaned up. While you've added linkingChangeListener.remove() to the cleanup function, this pattern could lead to memory leaks if the component re-renders while sessionMetadata is still loading.
Consider moving the event listener setup outside of the dependency array or ensuring it's properly cleaned up on each re-render by using a ref to track the listener:
// Store the listener in a ref
const linkingChangeListenerRef = useRef(null);
// Set up the listener
linkingChangeListenerRef.current = Linking.addEventListener('url', (state) => {
Report.openReportFromDeepLink(state.url, currentOnboardingPurposeSelected, currentOnboardingCompanySize, onboardingInitialPath, allReports, isAuthenticated);
});
// Clean up in the return function
return () => {
if (appStateChangeListener.current) {
appStateChangeListener.current.remove();
}
if (linkingChangeListenerRef.current) {
linkingChangeListenerRef.current.remove();
}
};| if (isLoadingOnyxValue(sessionMetadata)) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
This early return prevents the effect from running when session metadata is still loading, but it doesn't properly clean up any previously set listeners. If the component re-renders while sessionMetadata is loading, the cleanup function won't be called.
Consider restructuring the effect to ensure proper cleanup regardless of the loading state:
useEffect(() => {
// Only set up listeners if session metadata is loaded
if (!isLoadingOnyxValue(sessionMetadata)) {
const timeoutId = setTimeout(() => {
// Existing timeout code
}, 0);
// Set up listeners only when not loading
// ...
// Return cleanup function that always runs
return () => {
clearTimeout(timeoutId);
if (appStateChangeListener.current) {
appStateChangeListener.current.remove();
}
if (linkingChangeListener) {
linkingChangeListener.remove();
}
};
}
// Return empty cleanup when loading
return () => {};
}, [sessionMetadata?.status]);
<!-- presubmit.ai: comment -->| Linking.getInitialURL().then((url) => { | ||
| setInitialUrl(url as Route); | ||
| Report.openReportFromDeepLink(url ?? '', currentOnboardingPurposeSelected, currentOnboardingCompanySize, onboardingInitialPath, allReports); | ||
| Report.openReportFromDeepLink(url ?? '', currentOnboardingPurposeSelected, currentOnboardingCompanySize, onboardingInitialPath, allReports, isAuthenticated); |
There was a problem hiding this comment.
This component is violating the [PERF-6] rule by passing the entire allReports object as a dependency to Report.openReportFromDeepLink(). Passing entire objects can cause unnecessary re-renders and performance issues.
Consider extracting only the specific properties needed from allReports or restructuring the function to accept more granular parameters:
// Extract only needed properties from allReports
const reportIds = useMemo(() => Object.keys(allReports || {}), [allReports]);
// Then pass specific properties instead of the entire object
Report.openReportFromDeepLink(url ?? '', currentOnboardingPurposeSelected, currentOnboardingCompanySize, onboardingInitialPath, reportIds, isAuthenticated);| Linking.addEventListener('url', (state) => { | ||
| Report.openReportFromDeepLink(state.url, currentOnboardingPurposeSelected, currentOnboardingCompanySize, onboardingInitialPath, allReports); | ||
| const linkingChangeListener = Linking.addEventListener('url', (state) => { | ||
| Report.openReportFromDeepLink(state.url, currentOnboardingPurposeSelected, currentOnboardingCompanySize, onboardingInitialPath, allReports, isAuthenticated); |
There was a problem hiding this comment.
Similar to the previous issue, this line also violates the [PERF-6] rule by passing the entire allReports object to the function. This can lead to performance issues, especially in event handlers that may be called frequently.
Extract only the necessary properties from allReports or restructure the function to accept more specific parameters to improve performance.
There was a problem hiding this comment.
🚨 Pull request needs attention.
Review Summary
Commits Considered (1)
- 54a6939: refactor
Files Processed (1)
- src/Expensify.tsx (4 hunks)
Actionable Comments (3)
-
src/Expensify.tsx [190-192]
possible issue: "Early return prevents proper cleanup of event listeners"
-
src/Expensify.tsx [231-231]
performance: "Passing entire object as dependency can cause performance issues"
-
src/Expensify.tsx [236-236]
performance: "Passing entire object in event handler affects performance"
Skipped Comments (0)
| if (isLoadingOnyxValue(sessionMetadata)) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
This early return prevents the effect from running when session metadata is still loading, but it doesn't properly clean up any previously set listeners. If the component re-renders while sessionMetadata is loading, the cleanup function won't be called.
Consider restructuring the effect to ensure proper cleanup regardless of the loading state:
useEffect(() => {
let timeoutId: NodeJS.Timeout;
// Only set up listeners if session metadata is loaded
if (!isLoadingOnyxValue(sessionMetadata)) {
timeoutId = setTimeout(() => {
// Existing timeout code
}, 0);
// Set up listeners only when not loading
// ...
}
// Return cleanup function that always runs
return () => {
if (timeoutId) clearTimeout(timeoutId);
if (appStateChangeListener.current) {
appStateChangeListener.current.remove();
}
if (linkingChangeListener.current) {
linkingChangeListener.current.remove();
}
};
}, [sessionMetadata?.status]);| Linking.getInitialURL().then((url) => { | ||
| setInitialUrl(url as Route); | ||
| Report.openReportFromDeepLink(url ?? '', currentOnboardingPurposeSelected, currentOnboardingCompanySize, onboardingInitialPath, allReports); | ||
| Report.openReportFromDeepLink(url ?? '', currentOnboardingPurposeSelected, currentOnboardingCompanySize, onboardingInitialPath, allReports, isAuthenticated); |
There was a problem hiding this comment.
This line violates the [PERF-6] rule by passing the entire allReports object to Report.openReportFromDeepLink(). Passing entire objects can cause unnecessary re-renders and performance issues when the dependency changes.
Consider extracting only the specific properties needed from allReports or restructuring the function to accept more granular parameters:
// Extract only needed properties from allReports
const reportIds = useMemo(() => Object.keys(allReports || {}), [allReports]);
// Then pass specific properties instead of the entire object
Report.openReportFromDeepLink(url ?? '', currentOnboardingPurposeSelected, currentOnboardingCompanySize, onboardingInitialPath, reportIds, isAuthenticated);| Linking.addEventListener('url', (state) => { | ||
| Report.openReportFromDeepLink(state.url, currentOnboardingPurposeSelected, currentOnboardingCompanySize, onboardingInitialPath, allReports); | ||
| linkingChangeListener.current = Linking.addEventListener('url', (state) => { | ||
| Report.openReportFromDeepLink(state.url, currentOnboardingPurposeSelected, currentOnboardingCompanySize, onboardingInitialPath, allReports, isAuthenticated); |
There was a problem hiding this comment.
Similar to the previous issue, this line also violates the [PERF-6] rule by passing the entire allReports object to the function. This can lead to performance issues, especially in event handlers that may be called frequently.
Extract only the necessary properties from allReports or restructure the function to accept more specific parameters to improve performance.
|
Hmmm, @dukenv0307 with the latest updates, the original issue still remains. We can still recreate the original bug as no early-return when And then: Thoughts? |
|
@inimaga looks like this was merged without a test passing. Please add a note explaining why this was done and remove the |
|
"Failing test" linked to automated review comments from review bot. |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
This comment has been minimized.
This comment has been minimized.
|
🚧 @mountiny has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, Desktop, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/inimaga in version: 9.2.16-0 🚀
|
|
🚀 Deployed to production by https://github.com/roryabraham in version: 9.2.16-14 🚀
|
Explanation of Change
Fixed Issues
$ #68719
PROPOSAL: #68719 (comment)
Tests
Offline tests
Same as above
QA Steps
Same as above
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectioncanBeMissingparam foruseOnyxtoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Screen_Recording_2025-09-11_at_21.18.19.mov
Android: mWeb Chrome
Screen_Recording_2025-09-11_at_21.13.13.mov
iOS: Native
Screen_Recording_2025-09-11_at_21.21.59.mov
iOS: mWeb Safari
Screen_Recording_2025-09-11_at_21.14.31.mov
MacOS: Chrome / Safari
web-1.mov
MacOS: Desktop
Screen_Recording_2025-09-11_at_21.24.53.mov