Skip to content

Commit

Permalink
chore: do not change beforeSend when undefined (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
feugy authored Nov 7, 2024
1 parent 857f881 commit b5d2980
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/web/src/react/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,18 @@ describe('<SpeedInsights />', () => {
expect(window.siq?.[0]).toEqual(['beforeSend', beforeSend2]);
expect(window.siq).toHaveLength(1);
});

it('does not change beforeSend when undefined', () => {
const beforeSend: Required<SpeedInsightsProps>['beforeSend'] = (event) =>
event;
const { rerender } = render(<SpeedInsights beforeSend={beforeSend} />);

expect(window.siq?.[0]).toEqual(['beforeSend', beforeSend]);
expect(window.siq).toHaveLength(1);
window.siq?.splice(0, 1);

rerender(<SpeedInsights />);
expect(window.siq).toHaveLength(0);
});
});
});
4 changes: 3 additions & 1 deletion packages/web/src/react/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b5d2980

Please sign in to comment.