aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVendicated <vendicated@riseup.net>2023-03-01 05:45:09 +0100
committerVendicated <vendicated@riseup.net>2023-03-01 05:45:17 +0100
commit37003edae94c2caa9904af3ca2adf5975bdd156a (patch)
tree2150ff4631a272231bd6485586669dffbafa7586 /src
parentfaa90eccd363b635b84be2162376645d6a83ad55 (diff)
downloadVencord-37003edae94c2caa9904af3ca2adf5975bdd156a.tar.gz
Vencord-37003edae94c2caa9904af3ca2adf5975bdd156a.tar.bz2
Vencord-37003edae94c2caa9904af3ca2adf5975bdd156a.zip
fix(Notifications): Correctly close errored notifications
Diffstat (limited to 'src')
-rw-r--r--src/api/Notifications/NotificationComponent.tsx2
-rw-r--r--src/components/ErrorBoundary.tsx15
2 files changed, 11 insertions, 6 deletions
diff --git a/src/api/Notifications/NotificationComponent.tsx b/src/api/Notifications/NotificationComponent.tsx
index 65d4c43..036cacd 100644
--- a/src/api/Notifications/NotificationComponent.tsx
+++ b/src/api/Notifications/NotificationComponent.tsx
@@ -89,4 +89,6 @@ export default ErrorBoundary.wrap(function NotificationComponent({
)}
</button>
);
+}, {
+ onError: ({ props }) => props.onClose!()
});
diff --git a/src/components/ErrorBoundary.tsx b/src/components/ErrorBoundary.tsx
index 1eb2eb8..62b92a0 100644
--- a/src/components/ErrorBoundary.tsx
+++ b/src/components/ErrorBoundary.tsx
@@ -23,15 +23,18 @@ import { React } from "@webpack/common";
import { ErrorCard } from "./ErrorCard";
-interface Props {
+interface Props<T = any> {
/** Render nothing if an error occurs */
noop?: boolean;
/** Fallback component to render if an error occurs */
fallback?: React.ComponentType<React.PropsWithChildren<{ error: any; message: string; stack: string; }>>;
- /** called when an error occurs */
- onError?(error: Error, errorInfo: React.ErrorInfo): void;
+ /** called when an error occurs. The props property is only available if using .wrap */
+ onError?(data: { error: Error, errorInfo: React.ErrorInfo, props: T; }): void;
/** Custom error message */
message?: string;
+
+ /** The props passed to the wrapped component. Only used by wrap */
+ wrappedProps?: T;
}
const color = "#e78284";
@@ -66,7 +69,7 @@ const ErrorBoundary = LazyComponent(() => {
}
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
- this.props.onError?.(error, errorInfo);
+ this.props.onError?.({ error, errorInfo, props: this.props.wrappedProps });
logger.error("A component threw an Error\n", error);
logger.error("Component Stack", errorInfo.componentStack);
}
@@ -102,11 +105,11 @@ const ErrorBoundary = LazyComponent(() => {
};
}) as
React.ComponentType<React.PropsWithChildren<Props>> & {
- wrap<T extends object = any>(Component: React.ComponentType<T>, errorBoundaryProps?: Props): React.ComponentType<T>;
+ wrap<T extends object = any>(Component: React.ComponentType<T>, errorBoundaryProps?: Omit<Props<T>, "wrappedProps">): React.ComponentType<T>;
};
ErrorBoundary.wrap = (Component, errorBoundaryProps) => props => (
- <ErrorBoundary {...errorBoundaryProps}>
+ <ErrorBoundary {...errorBoundaryProps} wrappedProps={props}>
<Component {...props} />
</ErrorBoundary>
);