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(suite): redirect to index from /start, /onboarding if not initialRun #17286

Merged
merged 1 commit into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 10 additions & 4 deletions packages/suite/src/components/suite/Preloader/Preloader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { ViewOnlyPromo } from 'src/views/view-only/ViewOnlyPromo';
import { DatabaseUpgradeModal } from './DatabaseUpgradeModal';
import { InitialLoading } from './InitialLoading';
import { RouterAppWithParams } from '../../../constants/suite/routes';
import { Redirect } from '../../../support/suite/Redirect';
import { PrerequisitesGuide } from '../PrerequisitesGuide/PrerequisitesGuide';
import { DeviceCompromised } from '../SecurityCheck/DeviceCompromised';
import { useReportDeviceCompromised } from '../SecurityCheck/useReportDeviceCompromised';
Expand All @@ -40,12 +41,17 @@ const ROUTES_TO_SKIP_FIRMWARE_CHECK: RouterAppWithParams['app'][] = [
'firmware-custom',
];

const getFullscreenApp = (route: AppState['router']['route']): FC | undefined => {
const RedirectToDashboard = () => <Redirect to="suite-index" />;

const getFullscreenApp = (
route: AppState['router']['route'],
isInitialRun: boolean,
): FC | undefined => {
switch (route?.app) {
case 'start':
return SuiteStart;
return isInitialRun ? SuiteStart : RedirectToDashboard;
case 'onboarding':
return Onboarding;
return isInitialRun ? Onboarding : RedirectToDashboard;
default:
return undefined;
}
Expand Down Expand Up @@ -118,7 +124,7 @@ export const Preloader = ({ children }: PropsWithChildren) => {
// TODO: murder the fullscreen app logic, there must be a better way
// i don't like how it's not clear which layout is used
// and that the prerequisite screen is handled multiple times
const FullscreenApp = getFullscreenApp(router.route);
const FullscreenApp = getFullscreenApp(router.route, initialRun);
if (FullscreenApp !== undefined) {
return <FullscreenApp />;
}
Expand Down
26 changes: 26 additions & 0 deletions packages/suite/src/support/suite/Redirect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useLayoutEffect } from 'react';

import { Route } from '@suite-common/suite-types';

import * as routerActions from '../../actions/suite/routerActions';
import { useDispatch } from '../../hooks/suite';

type RedirectProps = {
to: Route['name'];
};

/**
* Component that does nothing else but trigger redirection.
* This must be used instead of Redirect from react-router-dom, because we need redux state synced with react-router state!
* @param to destination route name, as named in our route config (not necessarily the actual location.pathname)
*/
export const Redirect = ({ to }: RedirectProps) => {
const dispatch = useDispatch();

// useLayoutEffect rather than useEffect to prevent flickering (rendering null while redirect is in progress)
useLayoutEffect(() => {
dispatch(routerActions.goto(to));
}, [dispatch, to]);

return null;
};