Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: type error accessing null object and added test case #1620

Merged
merged 3 commits into from
Dec 19, 2024

Conversation

supermar1010
Copy link
Contributor

@supermar1010 supermar1010 commented Dec 19, 2024

Changes

We stumbled onto this bug, with rxdb dispatching mouse events without data and thus producing a posthog crash.

This typecast is why the error wasn't spotted by ts. The type of e.target is originally EventTarget | null, but looses the | null in this cast.

Checklist

  • Tests for new code (see advice on the tests we use)
  • Accounted for the impact of any changes across different browsers
  • Accounted for backwards compatibility of any changes (no breaking changes in posthog-js!)

Copy link

vercel bot commented Dec 19, 2024

@supermar1010 is attempting to deploy a commit to the PostHog Team on Vercel.

A member of the Team first needs to authorize it.

@benjackwhite benjackwhite added the bump patch Bump patch version when this PR gets merged label Dec 19, 2024
Copy link
Member

@pauldambra pauldambra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 question and 1 requested change

but this is 💯, absolutely love you took the time to PR 🙌

src/utils/element-utils.ts Outdated Show resolved Hide resolved
@@ -1,8 +1,8 @@
import { TOOLBAR_CONTAINER_CLASS, TOOLBAR_ID } from '../constants'

export function isElementInToolbar(el: Element): boolean {
export function isElementInToolbar(el: Element | null): boolean {
// NOTE: .closest is not supported in IE11 hence the operator check
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totally fly-by note for myself that this comment is probably out of date now that we're making ES6 and ES5 bundles separately

$heatmap_data: {
'http://replaced/': [
{
target_fixed: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, does this mean that the mousemove event has no clientX or clientY?

if so we're actually better ignoring them completely since the data is invalid without a coordinate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's a mouse move event without any clientX or clientY. According to mozilla dev everything is optional, so it is valid to send an event with any data.

Yeah ignoring is probably a good call!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're welcome to add that to this PR - if you're interested?

i can do as follow-up otherwise

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're already dropping events with no x and y during ingestion, so it's only a nice-to-have not to omit them (although good to not do work)

so only open question for me is if you'd like to handle that in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd leave that to you, I'm not sure where you'd implement that filtering.

src/utils/element-utils.ts Show resolved Hide resolved
src/utils/element-utils.ts Show resolved Hide resolved
src/utils/element-utils.ts Show resolved Hide resolved
@pauldambra pauldambra changed the title Fixed type error accessing null object and added test case fix: type error accessing null object and added test case Dec 19, 2024
@supermar1010
Copy link
Contributor Author

Unit tests should run successful now!

@pauldambra pauldambra removed the bump patch Bump patch version when this PR gets merged label Dec 19, 2024
Copy link
Member

@pauldambra pauldambra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@pauldambra pauldambra merged commit 142dad1 into PostHog:main Dec 19, 2024
8 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants