diff --git a/packages/web/src/react/index.test.tsx b/packages/web/src/react/index.test.tsx
index fdcdcab..2320eee 100644
--- a/packages/web/src/react/index.test.tsx
+++ b/packages/web/src/react/index.test.tsx
@@ -60,5 +60,18 @@ describe('', () => {
expect(window.siq?.[0]).toEqual(['beforeSend', beforeSend2]);
expect(window.siq).toHaveLength(1);
});
+
+ it('does not change beforeSend when undefined', () => {
+ const beforeSend: Required['beforeSend'] = (event) =>
+ event;
+ const { rerender } = render();
+
+ expect(window.siq?.[0]).toEqual(['beforeSend', beforeSend]);
+ expect(window.siq).toHaveLength(1);
+ window.siq?.splice(0, 1);
+
+ rerender();
+ expect(window.siq).toHaveLength(0);
+ });
});
});
diff --git a/packages/web/src/react/index.tsx b/packages/web/src/react/index.tsx
index 2200281..8214f8b 100644
--- a/packages/web/src/react/index.tsx
+++ b/packages/web/src/react/index.tsx
@@ -9,7 +9,9 @@ export function SpeedInsights(
},
): JSX.Element | null {
useEffect(() => {
- window.si?.('beforeSend', props.beforeSend);
+ if (props.beforeSend) {
+ window.si?.('beforeSend', props.beforeSend);
+ }
}, [props.beforeSend]);
const setScriptRoute = useRef<((path: string) => void) | null>(null);