Skip to content

Commit 358f6ec

Browse files
fix: Fix rendered header error (#3590)
1 parent 96d9efe commit 358f6ec

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/layouts/BaseLayout/BaseLayout.test.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ beforeAll(() => {
208208
server.listen({ onUnhandledRequest: 'warn' })
209209
})
210210

211+
beforeEach(() => {
212+
vi.resetModules()
213+
vi.restoreAllMocks()
214+
})
215+
211216
afterEach(() => {
212217
queryClient.clear()
213218
queryClientV5.clear()
@@ -588,4 +593,27 @@ describe('BaseLayout', () => {
588593
expect(errorMainAppUI).toBeInTheDocument()
589594
})
590595
})
596+
597+
describe('When Header has a network call error', async () => {
598+
it('renders nothing for the errored header', async () => {
599+
vi.spyOn(
600+
await import('layouts/Header'),
601+
'default'
602+
).mockImplementationOnce(() => {
603+
throw new Error('Simulated Header Error')
604+
})
605+
606+
setup({ currentUser: userHasDefaultOrg })
607+
render(<BaseLayout>hello</BaseLayout>, { wrapper: wrapper() })
608+
609+
const header = screen.queryByText(/Header/)
610+
expect(header).not.toBeInTheDocument()
611+
612+
const mainAppContent = await screen.findByText('hello')
613+
expect(mainAppContent).toBeInTheDocument()
614+
615+
const footerContent = await screen.findByText(/Footer/)
616+
expect(footerContent).toBeInTheDocument()
617+
})
618+
})
591619
})

src/layouts/BaseLayout/BaseLayout.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Header from 'layouts/Header'
77
import ErrorBoundary from 'layouts/shared/ErrorBoundary'
88
import { EmptyErrorComponent } from 'layouts/shared/ErrorBoundary/ErrorBoundary'
99
import NetworkErrorBoundary from 'layouts/shared/NetworkErrorBoundary'
10+
import SilentNetworkErrorWrapper from 'layouts/shared/SilentNetworkErrorWrapper'
1011
import ToastNotifications from 'layouts/ToastNotifications'
1112
import { RepoBreadcrumbProvider } from 'pages/RepoPage/context'
1213
import { useImpersonate } from 'services/impersonate'
@@ -110,7 +111,7 @@ function BaseLayout({ children }: React.PropsWithChildren) {
110111
{/* Header */}
111112
<Suspense>
112113
<ErrorBoundary errorComponent={<EmptyErrorComponent />}>
113-
<NetworkErrorBoundary>
114+
<SilentNetworkErrorWrapper>
114115
{isFullExperience || isImpersonating ? (
115116
<>
116117
<GlobalTopBanners />
@@ -121,7 +122,7 @@ function BaseLayout({ children }: React.PropsWithChildren) {
121122
{showDefaultOrgSelector ? <InstallationHelpBanner /> : null}
122123
</>
123124
)}
124-
</NetworkErrorBoundary>
125+
</SilentNetworkErrorWrapper>
125126
</ErrorBoundary>
126127
</Suspense>
127128

0 commit comments

Comments
 (0)