Skip to content

Commit f159bd4

Browse files
ENvironmentSetanakin_karrot
andauthored
feat(react): Add an option for customizing error boundary in structured activity components (#659)
Co-authored-by: anakin_karrot <anakin@daangn.com>
1 parent 0a55459 commit f159bd4

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

.changeset/eager-emus-sort.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@stackflow/react": minor
3+
---
4+
5+
Add an option for customizing error boundary in ErrorHandler of structured activity components

integrations/react/src/__internal__/PluginRenderer.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,22 @@ function renderStructuredActivityComponent(
9898
) : (
9999
node
100100
),
101-
(node) =>
102-
errorHandler?.component ? (
103-
<StructuredActivityComponentErrorBoundary
101+
(node) => {
102+
if (!errorHandler) return node;
103+
104+
const ErrorBoundary =
105+
errorHandler.boundary ?? StructuredActivityComponentErrorBoundary;
106+
107+
return (
108+
<ErrorBoundary
104109
renderFallback={(err, reset) => (
105110
<errorHandler.component params={params} error={err} reset={reset} />
106111
)}
107112
>
108113
{node}
109-
</StructuredActivityComponentErrorBoundary>
110-
) : (
111-
node
112-
),
114+
</ErrorBoundary>
115+
);
116+
},
113117
(node) =>
114118
layout?.component ? (
115119
<layout.component params={params}>{node}</layout.component>

integrations/react/src/__internal__/StructuredActivityComponentType.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,23 @@ export function loading<ActivityName extends RegisteredActivityName>(
105105

106106
export interface ErrorHandler<P extends {}> {
107107
component: ComponentType<{ params: P; error: unknown; reset: () => void }>;
108+
boundary?: CustomErrorBoundary;
108109
}
109110

111+
export type CustomErrorBoundary = ComponentType<{
112+
children: ReactNode;
113+
renderFallback: (error: unknown, reset: () => void) => ReactNode;
114+
}>;
115+
110116
export function errorHandler<ActivityName extends RegisteredActivityName>(
111117
component: ComponentType<{
112118
params: InferActivityParams<ActivityName>;
113119
error: unknown;
114120
reset: () => void;
115121
}>,
122+
options?: {
123+
boundary?: CustomErrorBoundary;
124+
},
116125
): ErrorHandler<InferActivityParams<ActivityName>> {
117-
return { component };
126+
return { component, boundary: options?.boundary };
118127
}

0 commit comments

Comments
 (0)