Skip to content

Commit 3bbfe06

Browse files
committed
fix modal support
1 parent 303eebc commit 3bbfe06

3 files changed

Lines changed: 17 additions & 12 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openstax/ui-components",
3-
"version": "1.23.6",
3+
"version": "1.23.7",
44
"license": "MIT",
55
"os": [ "darwin", "linux" ],
66
"repository": "https://github.com/openstax/ui-components.git",

src/components/ErrorBoundary.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const ErrorBoundary = ({
4040
children?: React.ReactNode;
4141
}) => {
4242
const parentContext = React.useContext(ErrorContext);
43-
const [error, setThisError] = React.useState<SentryError | null>(null);
43+
const [error, setThisError] = React.useState<(SentryError & {isInline?: boolean}) | null>(null);
4444
const errorFallbacks: { [_: string]: JSX.Element } = React.useMemo(() => ({
4545
...(includeDefaultHandlers ? defaultErrorFallbacks : {}),
4646
...props.errorFallbacks
@@ -91,11 +91,14 @@ export const ErrorBoundary = ({
9191
}
9292
}, [props.userUuid]);
9393

94-
const setError = React.useCallback((input: unknown, componentStack?: string) => {
94+
const setError = React.useCallback((input: unknown, componentStack?: string, isInline?: boolean) => {
9595

9696
if (input === null) {
9797
setThisError(null);
98-
parentContext.setError(null);
98+
99+
if (parentContext.initialized) {
100+
parentContext.setError(null);
101+
}
99102
return;
100103
}
101104

@@ -104,7 +107,7 @@ export const ErrorBoundary = ({
104107

105108
if (type in errorFallbacks || !parentContext.initialized) {
106109
setThisError({
107-
error, type, componentStack,
110+
error, type, componentStack, isInline,
108111
eventId: Sentry.captureException(error, {
109112
level: errorLevels[type] ?? 'error'
110113
})
@@ -120,18 +123,20 @@ export const ErrorBoundary = ({
120123
initialized: true
121124
}), [error, setError]);
122125

126+
const errorDisplay = typedFallback || defaultErrorFallbacks.generic;
127+
123128
// ErrorBoundary is not an actual ErrorBoundary becuase writing class components
124129
// is too annoying, we delegate just the catching part to RenderErrorCatcher
125130
return <ErrorContext.Provider value={contextValue}>
126-
{error
127-
? (typedFallback || defaultErrorFallbacks.generic)
128-
: <RenderErrorCatcher catch={setError}>{children}</RenderErrorCatcher>
131+
{error && error.isInline
132+
? errorDisplay
133+
: <RenderErrorCatcher catch={setError}>{error ? errorDisplay : children}</RenderErrorCatcher>
129134
}
130135
</ErrorContext.Provider>;
131136
};
132137

133138
type RenderErrorCatcherProps = {
134-
catch: (error: unknown, componentStack: string) => void;
139+
catch: (error: unknown, componentStack: string, isInline: boolean) => void;
135140
children?: React.ReactNode;
136141
};
137142
// according to https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary
@@ -147,7 +152,7 @@ class RenderErrorCatcher extends React.Component<RenderErrorCatcherProps, { hasE
147152
}
148153

149154
componentDidCatch(error: unknown, info: React.ErrorInfo) {
150-
this.props.catch(error, info.componentStack);
155+
this.props.catch(error, info.componentStack, true);
151156
}
152157

153158
render() {

0 commit comments

Comments
 (0)