-
Notifications
You must be signed in to change notification settings - Fork 3.9k
An additional entry is added to the browser history when opening the app #67610
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,16 @@ | ||
| import React from 'react'; | ||
| import useSidePanel from '@hooks/useSidePanel'; | ||
| import Help from './HelpModal'; | ||
| import useSyncSidePanelWithHistory from './useSyncSidePanelWithHistory'; | ||
|
|
||
| function SidePanel() { | ||
| const {isSidePanelTransitionEnded, shouldHideSidePanel, sidePanelTranslateX, shouldHideSidePanelBackdrop, closeSidePanel} = useSidePanel(); | ||
|
|
||
| // This hook synchronizes the side panel visibility with the browser history when it is displayed as RHP. | ||
| // This means when you open or close the side panel, an entry connected with it is added to or removed from the browser history, | ||
| // allowing this modal to be toggled using browser's "go back" and "go forward" buttons. | ||
| useSyncSidePanelWithHistory(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure this is the right spot for this hook? It will be called even when side panel is not available/closed
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I need to open it when I go forward in the browser history, then the side panel is not rendered, so the hook will not be called if I call it from
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's the described case Screen.Recording.2025-08-01.at.11.02.42.mov
mountiny marked this conversation as resolved.
Outdated
|
||
|
|
||
| if (isSidePanelTransitionEnded && shouldHideSidePanel) { | ||
| return null; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| // Side panel synchronization with the browser history is only supported for web | ||
| export default function useSyncSidePanelWithHistory() {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import {useNavigationState} from '@react-navigation/native'; | ||
| import {useEffect} from 'react'; | ||
| import usePrevious from '@hooks/usePrevious'; | ||
| import useResponsiveLayout from '@hooks/useResponsiveLayout'; | ||
| import useSidePanel from '@hooks/useSidePanel'; | ||
| import navigationRef from '@libs/Navigation/navigationRef'; | ||
| import CONST from '@src/CONST'; | ||
|
|
||
| export default function useSyncSidePanelWithHistory() { | ||
| const {closeSidePanel, openSidePanel, shouldHideSidePanel} = useSidePanel(); | ||
| const {isExtraLargeScreenWidth} = useResponsiveLayout(); | ||
| const lastHistoryEntry = useNavigationState((state) => state?.history?.at(-1)); | ||
| const previousLastHistoryEntry = usePrevious(lastHistoryEntry); | ||
|
|
||
| useEffect(() => { | ||
| // If the window width has been expanded and the modal is displayed, remove its history entry. | ||
| // The side panel is only synced with the history when it's displayed as RHP. | ||
| if (!shouldHideSidePanel && isExtraLargeScreenWidth) { | ||
| navigationRef.dispatch({ | ||
| type: CONST.NAVIGATION.ACTION_TYPE.TOGGLE_SIDE_PANEL_WITH_HISTORY, | ||
| payload: {isVisible: false}, | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| // When shouldHideSidePanel changes, synchronize the side panel with the browser history. | ||
| navigationRef.dispatch({ | ||
| type: CONST.NAVIGATION.ACTION_TYPE.TOGGLE_SIDE_PANEL_WITH_HISTORY, | ||
| payload: {isVisible: !shouldHideSidePanel}, | ||
| }); | ||
| }, [shouldHideSidePanel, isExtraLargeScreenWidth]); | ||
|
|
||
| useEffect(() => { | ||
| // The side panel is synced with the browser history only when displayed in RHP. | ||
| if (isExtraLargeScreenWidth) { | ||
| return; | ||
| } | ||
|
|
||
| const hasHistoryChanged = previousLastHistoryEntry !== lastHistoryEntry; | ||
|
|
||
| // If nothing has changed in the browser history, do nothing. | ||
| if (!hasHistoryChanged) { | ||
| return; | ||
| } | ||
|
|
||
| const hasSidePanelBeenClosed = previousLastHistoryEntry === CONST.NAVIGATION.CUSTOM_HISTORY_ENTRY_SIDE_PANEL; | ||
|
|
||
| // If the side panel history entry is not the last one and the modal is displayed, close it. | ||
| if (hasSidePanelBeenClosed && !shouldHideSidePanel) { | ||
| closeSidePanel(); | ||
| return; | ||
| } | ||
|
|
||
| const hasSidePanelBeenOpened = lastHistoryEntry === CONST.NAVIGATION.CUSTOM_HISTORY_ENTRY_SIDE_PANEL; | ||
|
|
||
| // If the side panel history entry is the last one and the modal is not displayed, open it. | ||
| if (hasSidePanelBeenOpened && shouldHideSidePanel) { | ||
| openSidePanel(); | ||
| } | ||
| }, [closeSidePanel, lastHistoryEntry, previousLastHistoryEntry, openSidePanel, shouldHideSidePanel, isExtraLargeScreenWidth]); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.