Skip to content

Commit 6ded12c

Browse files
committed
Merge branch 'main' into SDK-640/fix-studio-mode-auth
2 parents 0fda85f + 3bf96f2 commit 6ded12c

File tree

9 files changed

+106
-112
lines changed

9 files changed

+106
-112
lines changed

packages/core/src/_exports/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ export {resolveProjection} from '../projection/resolveProjection'
123123
export {type ProjectionValuePending, type ValidProjection} from '../projection/types'
124124
export {getProjectsState, resolveProjects} from '../projects/projects'
125125
export {
126-
clearQueryError,
127-
getQueryErrorState,
128126
getQueryKey,
129127
getQueryState,
130128
parseQueryKey,

packages/core/src/query/queryStore.ts

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -317,29 +317,6 @@ const _getQueryState = bindActionByDataset(
317317
}),
318318
)
319319

320-
/**
321-
* Returns a state source for the top-level query store error (if any).
322-
*
323-
* Unlike {@link getQueryState}, this selector does not throw; it simply returns the error value.
324-
* Subscribe to this to be notified when a global query error occurs (e.g., CORS failures).
325-
*
326-
* @beta
327-
*/
328-
export function getQueryErrorState(instance: SanityInstance): StateSource<unknown | undefined> {
329-
return _getQueryErrorState(instance)
330-
}
331-
332-
const _getQueryErrorState = bindActionByDataset(
333-
queryStore,
334-
createStateSourceAction({
335-
selector: ({state}: SelectorContext<QueryStoreState>) => state.error,
336-
onSubscribe: () => {
337-
// No-op subscription as we don't track per-query subscribers here
338-
return () => {}
339-
},
340-
}),
341-
)
342-
343320
/**
344321
* Resolves the result of a query without registering a lasting subscriber.
345322
*
@@ -413,16 +390,3 @@ const _resolveQuery = bindActionByDataset(
413390
return firstValueFrom(race([resolved$, aborted$]))
414391
},
415392
)
416-
417-
/**
418-
* Clears the top-level query store error.
419-
* @beta
420-
*/
421-
export function clearQueryError(instance: SanityInstance): void
422-
export function clearQueryError(...args: Parameters<typeof _clearQueryError>): void {
423-
return _clearQueryError(...args)
424-
}
425-
426-
const _clearQueryError = bindActionByDataset(queryStore, ({state}) => {
427-
state.set('setError', {error: undefined})
428-
})

packages/react/src/components/auth/AuthBoundary.tsx

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {useAuthState} from '../../hooks/auth/useAuthState'
88
import {useLoginUrl} from '../../hooks/auth/useLoginUrl'
99
import {useVerifyOrgProjects} from '../../hooks/auth/useVerifyOrgProjects'
1010
import {useSanityInstance} from '../../hooks/context/useSanityInstance'
11-
import {useCorsOriginError} from '../../hooks/errors/useCorsOriginError'
1211
import {CorsErrorComponent} from '../errors/CorsErrorComponent'
1312
import {isInIframe} from '../utils'
1413
import {AuthError} from './AuthError'
@@ -109,38 +108,24 @@ export function AuthBoundary({
109108
LoginErrorComponent = LoginError,
110109
...props
111110
}: AuthBoundaryProps): React.ReactNode {
112-
const {error: corsError, projectId, clear: clearCorsError} = useCorsOriginError()
113-
114111
const FallbackComponent = useMemo(() => {
115112
return function LoginComponentWithLayoutProps(fallbackProps: FallbackProps) {
116113
if (fallbackProps.error instanceof CorsOriginError) {
117114
return (
118115
<CorsErrorComponent
119116
{...fallbackProps}
120117
projectId={getCorsErrorProjectId(fallbackProps.error)}
121-
resetErrorBoundary={() => {
122-
clearCorsError()
123-
fallbackProps.resetErrorBoundary()
124-
}}
125118
/>
126119
)
127120
}
128121
return <LoginErrorComponent {...fallbackProps} />
129122
}
130-
}, [LoginErrorComponent, clearCorsError])
123+
}, [LoginErrorComponent])
131124

132125
return (
133126
<ComlinkTokenRefreshProvider>
134127
<ErrorBoundary FallbackComponent={FallbackComponent}>
135-
{corsError ? (
136-
<CorsErrorComponent
137-
error={corsError}
138-
resetErrorBoundary={() => clearCorsError()}
139-
projectId={projectId}
140-
/>
141-
) : (
142-
<AuthSwitch {...props} />
143-
)}
128+
<AuthSwitch {...props} />
144129
</ErrorBoundary>
145130
</ComlinkTokenRefreshProvider>
146131
)

packages/react/src/components/auth/LoginError.tsx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {type FallbackProps} from 'react-error-boundary'
55

66
import {useAuthState} from '../../hooks/auth/useAuthState'
77
import {useLogOut} from '../../hooks/auth/useLogOut'
8+
import {Error} from '../errors/Error'
89
import {AuthError} from './AuthError'
910
import {ConfigurationError} from './ConfigurationError'
1011
/**
@@ -59,17 +60,13 @@ export function LoginError({error, resetErrorBoundary}: LoginErrorProps): React.
5960
}, [authState, handleRetry, error])
6061

6162
return (
62-
<div className="sc-login-error">
63-
<div className="sc-login-error__content">
64-
<h2 className="sc-login-error__title">
65-
{error instanceof AuthError ? 'Authentication Error' : 'Configuration Error'}
66-
</h2>
67-
<p className="sc-login-error__description">{authErrorMessage}</p>
68-
</div>
69-
70-
<button className="sc-login-error__button" onClick={handleRetry}>
71-
Retry
72-
</button>
73-
</div>
63+
<Error
64+
heading={error instanceof AuthError ? 'Authentication Error' : 'Configuration Error'}
65+
description={authErrorMessage}
66+
cta={{
67+
text: 'Retry',
68+
onClick: handleRetry,
69+
}}
70+
/>
7471
)
7572
}

packages/react/src/components/errors/CorsErrorComponent.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('CorsErrorComponent', () => {
2121
/>,
2222
)
2323

24-
expect(screen.getByText('Before you continue...')).toBeInTheDocument()
24+
expect(screen.getByText('Before you continue')).toBeInTheDocument()
2525
expect(screen.getByText(origin)).toBeInTheDocument()
2626

2727
const link = screen.getByRole('link', {name: 'Manage CORS configuration'}) as HTMLAnchorElement
@@ -41,7 +41,7 @@ describe('CorsErrorComponent', () => {
4141
const error = new Error('some error message')
4242
render(<CorsErrorComponent projectId={null} error={error} resetErrorBoundary={() => {}} />)
4343

44-
expect(screen.getByText('Before you continue...')).toBeInTheDocument()
44+
expect(screen.getByText('Before you continue')).toBeInTheDocument()
4545
expect(screen.getByText('some error message')).toBeInTheDocument()
4646
expect(screen.queryByRole('link', {name: 'Manage CORS configuration'})).toBeNull()
4747
})
Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {useMemo} from 'react'
22
import {type FallbackProps} from 'react-error-boundary'
33

4+
import {Error} from './Error'
5+
46
type CorsErrorComponentProps = FallbackProps & {
57
projectId: string | null
68
}
@@ -15,26 +17,21 @@ export function CorsErrorComponent({projectId, error}: CorsErrorComponentProps):
1517
return url.toString()
1618
}, [origin, projectId])
1719
return (
18-
<div className="sc-login-error">
19-
<div className="sc-login-error__content">
20-
<h1>Before you continue...</h1>
21-
<p>
22-
To access your content, you need to <b>add the following URL as a CORS origin</b> to your
23-
Sanity project.
24-
</p>
25-
<p>
26-
<code>{origin}</code>
27-
</p>
28-
{projectId ? (
29-
<p>
30-
<a href={corsUrl ?? ''} target="_blank" rel="noopener noreferrer">
31-
Manage CORS configuration
32-
</a>
33-
</p>
34-
) : (
35-
<p>{error?.message}</p>
36-
)}
37-
</div>
38-
</div>
20+
<Error
21+
heading="Before you continue…"
22+
{...(projectId
23+
? {
24+
description:
25+
'To access your content, you need to <strong>add the following URL as a CORS origin</strong> to your Sanity project.',
26+
code: origin,
27+
cta: {
28+
text: 'Manage CORS configuration',
29+
href: corsUrl,
30+
},
31+
}
32+
: {
33+
description: error?.message,
34+
})}
35+
/>
3936
)
4037
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const FONT_SANS_SERIF = `-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Helvetica, Arial, system-ui, sans-serif`
2+
const FONT_MONOSPACE = `-apple-system-ui-monospace, 'SF Mono', Menlo, Monaco, Consolas, monospace`
3+
4+
const styles: Record<string, React.CSSProperties> = {
5+
container: {
6+
padding: '28px',
7+
fontFamily: FONT_SANS_SERIF,
8+
display: 'flex',
9+
flexDirection: 'column',
10+
gap: '21px',
11+
fontSize: '14px',
12+
},
13+
heading: {
14+
margin: 0,
15+
fontSize: '28px',
16+
fontWeight: 700,
17+
},
18+
paragraph: {
19+
margin: 0,
20+
},
21+
link: {
22+
appearance: 'none',
23+
background: 'transparent',
24+
border: 0,
25+
padding: 0,
26+
font: 'inherit',
27+
textDecoration: 'underline',
28+
cursor: 'pointer',
29+
},
30+
code: {
31+
fontFamily: FONT_MONOSPACE,
32+
},
33+
}
34+
35+
export default styles
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import styles from './Error.styles'
2+
3+
type ErrorProps = {
4+
heading: string
5+
description?: string
6+
code?: string
7+
cta?: {
8+
text: string
9+
href?: string
10+
onClick?: () => void
11+
}
12+
}
13+
14+
export function Error({heading, description, code, cta}: ErrorProps): React.ReactNode {
15+
return (
16+
<div style={styles['container']}>
17+
<h1 style={styles['heading']}>{heading}</h1>
18+
19+
{description && (
20+
<p style={styles['paragraph']} dangerouslySetInnerHTML={{__html: description}} />
21+
)}
22+
23+
{code && <code style={styles['code']}>{code}</code>}
24+
25+
{cta && (cta.href || cta.onClick) && (
26+
<p style={styles['paragraph']}>
27+
{cta.href ? (
28+
<a style={styles['link']} href={cta.href} target="_blank" rel="noopener noreferrer">
29+
{cta.text}
30+
</a>
31+
) : (
32+
<button style={styles['link']} onClick={cta.onClick}>
33+
{cta.text}
34+
</button>
35+
)}
36+
</p>
37+
)}
38+
</div>
39+
)
40+
}

packages/react/src/hooks/errors/useCorsOriginError.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)