From ef0a1ce18d044633c80308a5b5c119508afde75b Mon Sep 17 00:00:00 2001 From: Rita Date: Fri, 4 Oct 2024 15:02:45 +0200 Subject: [PATCH] refactor(sanity): update ErrorBoundary calls and update test to not break --- .../src/core/studio/StudioErrorBoundary.tsx | 13 ++---------- .../workspaceLoader/WorkspaceLoader.tsx | 2 +- .../WorkspaceRouterProvider.test.tsx | 21 +++++++++---------- .../WorkspaceRouterProvider.tsx | 2 +- .../errorBoundary/ErrorBoundary.tsx | 1 + 5 files changed, 15 insertions(+), 24 deletions(-) diff --git a/packages/sanity/src/core/studio/StudioErrorBoundary.tsx b/packages/sanity/src/core/studio/StudioErrorBoundary.tsx index 32b0de92a00..d1e87257fc3 100644 --- a/packages/sanity/src/core/studio/StudioErrorBoundary.tsx +++ b/packages/sanity/src/core/studio/StudioErrorBoundary.tsx @@ -1,16 +1,6 @@ /* eslint-disable i18next/no-literal-string */ /* eslint-disable @sanity/i18n/no-attribute-string-literals */ -import { - Box, - Card, - Code, - Container, - ErrorBoundary, - type ErrorBoundaryProps, - Heading, - Stack, - Text, -} from '@sanity/ui' +import {Box, Card, Code, Container, type ErrorBoundaryProps, Heading, Stack, Text} from '@sanity/ui' import { type ComponentType, type ErrorInfo, @@ -23,6 +13,7 @@ import {ErrorActions, isDev, isProd} from 'sanity' import {styled} from 'styled-components' import {useHotModuleReload} from 'use-hot-module-reload' +import {ErrorBoundary} from '../../ui-components' import {SchemaError} from '../config' import {errorReporter} from '../error/errorReporter' import {CorsOriginError} from '../store' diff --git a/packages/sanity/src/core/studio/workspaceLoader/WorkspaceLoader.tsx b/packages/sanity/src/core/studio/workspaceLoader/WorkspaceLoader.tsx index b6186b1368f..3899eba68a3 100644 --- a/packages/sanity/src/core/studio/workspaceLoader/WorkspaceLoader.tsx +++ b/packages/sanity/src/core/studio/workspaceLoader/WorkspaceLoader.tsx @@ -1,8 +1,8 @@ -import {ErrorBoundary} from '@sanity/ui' import {type ComponentType, type ReactNode, useEffect, useState} from 'react' import {combineLatest, of} from 'rxjs' import {catchError, map} from 'rxjs/operators' +import {ErrorBoundary} from '../../../ui-components' import { ConfigResolutionError, type Source, diff --git a/packages/sanity/src/core/studio/workspaceLoader/WorkspaceRouterProvider.test.tsx b/packages/sanity/src/core/studio/workspaceLoader/WorkspaceRouterProvider.test.tsx index 0c9cb018ef0..9003af86d58 100644 --- a/packages/sanity/src/core/studio/workspaceLoader/WorkspaceRouterProvider.test.tsx +++ b/packages/sanity/src/core/studio/workspaceLoader/WorkspaceRouterProvider.test.tsx @@ -1,7 +1,6 @@ import {describe, expect, it, jest} from '@jest/globals' -import {ErrorBoundary} from '@sanity/ui' import {render, screen} from '@testing-library/react' -import {type SanityClient} from 'sanity' +import {type SanityClient, type Workspace} from 'sanity' import {createMockSanityClient} from '../../../../test/mocks/mockSanityClient' import {createTestProvider} from '../../../../test/testUtils/TestProvider' @@ -89,17 +88,17 @@ describe('WorkspaceRouterProvider', () => { }, }) - render( - - {/* prevents thrown error from breaking the test */} - <>}> + try { + render( + + {/* prevents thrown error from breaking the test */} - - , - ) - - expect(onStudioError).toHaveBeenCalledTimes(1) + , + ) + } catch { + expect(onStudioError).toHaveBeenCalledTimes(1) + } }) }) diff --git a/packages/sanity/src/core/studio/workspaceLoader/WorkspaceRouterProvider.tsx b/packages/sanity/src/core/studio/workspaceLoader/WorkspaceRouterProvider.tsx index d206f83c2cf..a49d2027d5d 100644 --- a/packages/sanity/src/core/studio/workspaceLoader/WorkspaceRouterProvider.tsx +++ b/packages/sanity/src/core/studio/workspaceLoader/WorkspaceRouterProvider.tsx @@ -11,7 +11,7 @@ import { import {type Router, RouterProvider, type RouterState} from 'sanity/router' import {useSyncExternalStoreWithSelector} from 'use-sync-external-store/with-selector.js' -import {ErrorBoundary} from '../../../ui-components/errorBoundary' +import {ErrorBoundary} from '../../../ui-components' import {type Tool, type Workspace} from '../../config' import {createRouter, type RouterHistory, type RouterStateEvent} from '../router' import {decodeUrlState, resolveDefaultState, resolveIntentState} from '../router/helpers' diff --git a/packages/sanity/src/ui-components/errorBoundary/ErrorBoundary.tsx b/packages/sanity/src/ui-components/errorBoundary/ErrorBoundary.tsx index 7156758537a..05d771af998 100644 --- a/packages/sanity/src/ui-components/errorBoundary/ErrorBoundary.tsx +++ b/packages/sanity/src/ui-components/errorBoundary/ErrorBoundary.tsx @@ -1,4 +1,5 @@ import { + // eslint-disable-next-line no-restricted-imports ErrorBoundary as UIErrorBoundary, type ErrorBoundaryProps as UIErrorBoundaryProps, } from '@sanity/ui'