Skip to content

Commit d7d22ab

Browse files
fix(components): reset error when the component props have changed
* Take the "Text input - Default" story * change the `lapisField` to "hos" (i.e. making it an invalid field) * The component will show an error, because LAPIS shows an error * change the `lapisField` to "host" (i.e. making it a valid field again) Before: It would still show an error until you click "Try again" Now: It rerenders and doesn't show an error anymore Related to GenSpectrum/dashboards#530
1 parent b24d6be commit d7d22ab

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

components/src/preact/components/error-boundary.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type RenderableProps } from 'preact';
2-
import { useErrorBoundary, useMemo } from 'preact/hooks';
2+
import { useEffect, useErrorBoundary, useMemo } from 'preact/hooks';
33
import { type ZodSchema } from 'zod';
44

55
import { ErrorDisplay, type ErrorDisplayProps, InvalidPropsError } from './error-display';
@@ -22,6 +22,16 @@ export const ErrorBoundary = <T extends Record<string, unknown>>({
2222
const [internalError, resetError] = useErrorBoundary();
2323
const componentPropsParseError = useCheckComponentProps(schema, componentProps);
2424

25+
useEffect(
26+
() => {
27+
if (internalError) {
28+
resetError();
29+
}
30+
},
31+
// eslint-disable-next-line react-hooks/exhaustive-deps -- this should run if and only if the props of the component change
32+
[componentProps],
33+
);
34+
2535
if (internalError) {
2636
return (
2737
<ResizeContainer size={size}>

0 commit comments

Comments
 (0)