Skip to content

Commit

Permalink
[Synthetics UI] Remove 404 check (#147694)
Browse files Browse the repository at this point in the history
Fixes #147659

We were using a hook in a non-React context and that was messing up with
how React kept state internally. That caused some other hooks to not
save their own state and trigger infinite re-renders down the line in
some scenarios.

We will need to revisit how we check for 404 errors.

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
Alejandro Fernández Gómez and kibanamachine authored Dec 19, 2022
1 parent cc33a3c commit e03f8f0
Showing 1 changed file with 7 additions and 29 deletions.
36 changes: 7 additions & 29 deletions x-pack/plugins/synthetics/public/apps/synthetics/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { APP_WRAPPER_CLASS } from '@kbn/core/public';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { useInspectorContext } from '@kbn/observability-plugin/public';
import type { LazyObservabilityPageTemplateProps } from '@kbn/observability-plugin/public';
import { NotFoundPrompt } from '@kbn/shared-ux-prompt-not-found';
import { getSettingsRouteConfig } from './components/settings/route_config';
import { TestRunDetails } from './components/test_run_details/test_run_details';
import { ErrorDetailsPage } from './components/error_details/error_details_page';
Expand Down Expand Up @@ -59,14 +58,12 @@ import { MonitorSummary } from './components/monitor_details/monitor_summary/mon
import { MonitorHistory } from './components/monitor_details/monitor_history/monitor_history';
import { MonitorErrors } from './components/monitor_details/monitor_errors/monitor_errors';
import { StepDetailPage } from './components/step_details_page/step_detail_page';
import { useSelectedMonitor } from './components/monitor_details/hooks/use_selected_monitor';

export type RouteProps = LazyObservabilityPageTemplateProps & {
path: string;
component: React.FC;
dataTestSubj: string;
title: string;
is404?: () => boolean;
};

const baseTitle = i18n.translate('xpack.synthetics.routes.baseTitle', {
Expand Down Expand Up @@ -106,10 +103,6 @@ const getRoutes = (
values: { baseTitle },
}),
path: MONITOR_ROUTE,
is404: function useIs404() {
const { error } = useSelectedMonitor();
return error?.body.statusCode === 404;
},
component: () => (
<MonitorDetailsPage>
<MonitorSummary />
Expand All @@ -124,10 +117,6 @@ const getRoutes = (
values: { baseTitle },
}),
path: MONITOR_HISTORY_ROUTE,
is404: function useIs404() {
const { error } = useSelectedMonitor();
return error?.body.statusCode === 404;
},
component: () => (
<MonitorDetailsPage>
<MonitorHistory />
Expand All @@ -142,10 +131,6 @@ const getRoutes = (
values: { baseTitle },
}),
path: MONITOR_ERRORS_ROUTE,
is404: function useIs404() {
const { error } = useSelectedMonitor();
return error?.body.statusCode === 404;
},
component: () => (
<MonitorDetailsPage>
<MonitorErrors />
Expand Down Expand Up @@ -428,25 +413,18 @@ export const PageRouter: FC = () => {
component: RouteComponent,
dataTestSubj,
pageHeader,
is404,
...pageTemplateProps
}: RouteProps) => (
<Route path={path} key={dataTestSubj} exact={true}>
<div className={APP_WRAPPER_CLASS} data-test-subj={dataTestSubj}>
<RouteInit title={title} path={path} />
{is404?.() ? (
<SyntheticsPageTemplateComponent path={path} {...pageTemplateProps}>
<NotFoundPrompt />
</SyntheticsPageTemplateComponent>
) : (
<SyntheticsPageTemplateComponent
path={path}
pageHeader={pageHeader}
{...pageTemplateProps}
>
<RouteComponent />
</SyntheticsPageTemplateComponent>
)}
<SyntheticsPageTemplateComponent
path={path}
pageHeader={pageHeader}
{...pageTemplateProps}
>
<RouteComponent />
</SyntheticsPageTemplateComponent>
</div>
</Route>
)
Expand Down

0 comments on commit e03f8f0

Please sign in to comment.