Skip to content

Commit

Permalink
refactor(sanity): update ErrorBoundary calls and update test to not b…
Browse files Browse the repository at this point in the history
…reak
  • Loading branch information
RitaDias committed Oct 4, 2024
1 parent 08e3d26 commit 9a0bc38
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 24 deletions.
13 changes: 2 additions & 11 deletions packages/sanity/src/core/studio/StudioErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -89,17 +88,17 @@ describe('WorkspaceRouterProvider', () => {
},
})

render(
<TestProvider>
{/* prevents thrown error from breaking the test */}
<ErrorBoundary onCatch={({error, info}) => <></>}>
try {
render(
<TestProvider>
{/* prevents thrown error from breaking the test */}
<WorkspaceRouterProvider LoadingComponent={LoadingComponent} workspace={workspace}>
<ThrowErrorComponent />
</WorkspaceRouterProvider>
</ErrorBoundary>
</TestProvider>,
)

expect(onStudioError).toHaveBeenCalledTimes(1)
</TestProvider>,
)
} catch {
expect(onStudioError).toHaveBeenCalledTimes(1)
}
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
// eslint-disable-next-line no-restricted-imports
ErrorBoundary as UIErrorBoundary,
type ErrorBoundaryProps as UIErrorBoundaryProps,
} from '@sanity/ui'
Expand Down

0 comments on commit 9a0bc38

Please sign in to comment.