Skip to content

Commit

Permalink
chore: do not change beforeSend when undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
feugy committed Nov 7, 2024
1 parent a8a52ed commit 9f25f05
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.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ describe('<Analytics />', () => {
expect(window.vaq?.[0]).toEqual(['beforeSend', beforeSend2]);
expect(window.vaq).toHaveLength(1);
});

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

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

rerender(<Analytics />);
expect(window.vaq).toHaveLength(0);
});
});

describe('track custom events', () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/web/src/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ function Analytics(
}
): null {
useEffect(() => {
window.va?.('beforeSend', props.beforeSend);
if (props.beforeSend) {
window.va?.('beforeSend', props.beforeSend);
}
}, [props.beforeSend]);

// biome-ignore lint/correctness/useExhaustiveDependencies: only run once
Expand Down

0 comments on commit 9f25f05

Please sign in to comment.