From 304bc6db865c6671b3689b41c1b667da33579c9a Mon Sep 17 00:00:00 2001 From: Nar Saynorath Date: Tue, 23 Jul 2024 12:51:32 -0400 Subject: [PATCH 1/2] fix(insights): Cache page alert re-rendering --- static/app/views/insights/cache/views/cacheLandingPage.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/static/app/views/insights/cache/views/cacheLandingPage.tsx b/static/app/views/insights/cache/views/cacheLandingPage.tsx index 61a2e01b327978..33b75138120610 100644 --- a/static/app/views/insights/cache/views/cacheLandingPage.tsx +++ b/static/app/views/insights/cache/views/cacheLandingPage.tsx @@ -12,6 +12,7 @@ import PageFilterBar from 'sentry/components/organizations/pageFilterBar'; import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter'; import {PageHeadingQuestionTooltip} from 'sentry/components/pageHeadingQuestionTooltip'; import {t} from 'sentry/locale'; +import {defined} from 'sentry/utils'; import type {EventsMetaType} from 'sentry/utils/discover/eventView'; import { DismissId, @@ -151,7 +152,7 @@ export function CacheLandingPage() { cacheMissRateError?.message === CACHE_ERROR_MESSAGE || transactionsListError?.message === CACHE_ERROR_MESSAGE; - if (onboardingProject || !hasData) { + if (defined(pageAlert?.message) && (onboardingProject || !hasData)) { setPageInfo(undefined); return; } From 0ac82622997487c02c5b2ca85925531c1149919d Mon Sep 17 00:00:00 2001 From: Nar Saynorath Date: Tue, 23 Jul 2024 13:16:33 -0400 Subject: [PATCH 2/2] Use useCallback --- .../utils/performance/contexts/pageAlert.tsx | 23 ++++++++++--------- .../insights/cache/views/cacheLandingPage.tsx | 3 +-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/static/app/utils/performance/contexts/pageAlert.tsx b/static/app/utils/performance/contexts/pageAlert.tsx index c1ffb24e8fa2f0..68e87d6041b54b 100644 --- a/static/app/utils/performance/contexts/pageAlert.tsx +++ b/static/app/utils/performance/contexts/pageAlert.tsx @@ -1,5 +1,5 @@ import type React from 'react'; -import {createContext, Fragment, useContext, useState} from 'react'; +import {createContext, Fragment, useCallback, useContext, useState} from 'react'; import type {Theme} from '@emotion/react'; import {Alert} from 'sentry/components/alert'; @@ -45,24 +45,25 @@ const pageErrorContext = createContext<{ export function PageAlertProvider({children}: {children: React.ReactNode}) { const [pageAlert, setPageAlert] = useState(); - const setPageInfo: PageAlertSetter = (message, options) => { + const setPageInfo: PageAlertSetter = useCallback((message, options) => { setPageAlert({message, type: 'info', ...options}); - }; - const setPageMuted: PageAlertSetter = (message, options) => { + }, []); + + const setPageMuted: PageAlertSetter = useCallback((message, options) => { setPageAlert({message, type: 'muted', ...options}); - }; + }, []); - const setPageSuccess: PageAlertSetter = (message, options) => { + const setPageSuccess: PageAlertSetter = useCallback((message, options) => { setPageAlert({message, type: 'success', ...options}); - }; + }, []); - const setPageWarning: PageAlertSetter = (message, options) => { + const setPageWarning: PageAlertSetter = useCallback((message, options) => { setPageAlert({message, type: 'warning', ...options}); - }; + }, []); - const setPageError: PageAlertSetter = (message, options) => { + const setPageError: PageAlertSetter = useCallback((message, options) => { setPageAlert({message, type: 'error', ...options}); - }; + }, []); return (