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(placement): fix firing multiple impressions #9631

Merged
merged 7 commits into from
Sep 15, 2023
Merged

Conversation

fiji-flo
Copy link
Contributor

Summary

Unify sendViewed and empty placement.

Problem

We did not cancel our timer properly.

Solution

Use an unified sendViewed function.


How did you test this change?

Locally

@fiji-flo fiji-flo requested a review from LeoMcA September 11, 2023 10:40
Copy link
Member

@LeoMcA LeoMcA left a comment

Choose a reason for hiding this comment

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

Sorry, took me a little while to figure out why I was getting confused - skip straight to my last comment about reactifying the intersection observer, it should massively simplify the logic here

Copy link
Member

@LeoMcA LeoMcA left a comment

Choose a reason for hiding this comment

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

Most of these are comments on my own code, haha - see what you think, but I think they all counts as nits (maybe apart from the test comment, if we want to ensure things don't error out on browsers which don't support IntersectionObserver)

timer.current = { timeout: -1 };
}, [pong, gleanClick, typ]);

const place = useCallback((node: HTMLElement | null) => {
Copy link
Member

Choose a reason for hiding this comment

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

nit (in my own code): we already have a node const declared in the scope above. We could do what I did with the intersection observer hook and do something like: const [nodeState, setNodeState] = useState<HTMLElement>(); instead

import { render, waitFor } from "@testing-library/react";

import { Document } from "./index";

declare var global: Window;

// TODO: move this somewhere better once we have more use cases.
class IntersectionObserver {
Copy link
Member

Choose a reason for hiding this comment

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

Considering our chat about progressive enhancement the other day, might it be better to remove this from the tests, and just ensure we wrap our code with if (typeof IntersectionObserver !== "undefined") or similar, as necessary?

@fiji-flo fiji-flo merged commit b8da642 into main Sep 15, 2023
@fiji-flo fiji-flo deleted the fix-placement-ping branch September 15, 2023 10:02
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.

2 participants