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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Report zero visibility for zero size element #30105

Merged
merged 3 commits into from Sep 4, 2020

Conversation

zhouyx
Copy link
Contributor

@zhouyx zhouyx commented Sep 3, 2020

Closes #29946

Copy link
Contributor

@micajuine-ho micajuine-ho left a comment

Choose a reason for hiding this comment

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

Great catch!

Comment on lines +656 to +665
// zero element size, high resolution screen.
inOb.callback([
{
target,
intersectionRatio: 0.8,
intersectionRect: layoutRectLtwh(0, 0, 1, 1),
boundingClientRect: layoutRectLtwh(1, 1, 10, 0.452),
},
]);
expect(model.getVisibility_()).to.equal(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice check!

@@ -872,7 +872,6 @@ export class VisibilityManagerForDoc extends VisibilityManager {
Number(intersection.width),
Number(intersection.height)
);
// TODO(#29618): Remove after ampim investigation
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any more cleanup needed?

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. We need to move all the related error logs.
I removed this TODO because boundingClientRect needs to stay because we need element's width/height value.

@@ -908,6 +906,12 @@ export class VisibilityManagerForDoc extends VisibilityManager {
intersectionRatio = Math.min(Math.max(intersectionRatio, 0), 1);
const id = getElementId(target);
const trackedElement = this.trackedElements_[id];
if (boundingClientRect.width < 1 || boundingClientRect.height < 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be collapsed with the declaration above?

if (width<1 || height<1) {
  // Set intersectionRatio to 0 when the element is not visible.
  // Use < 1 because the width/height can be a double values.
  intersectionRatio = 0;
} else {
  intersectionRatio = Math.min(Math.max(intersectionRatio, 0), 1);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@zhouyx zhouyx merged commit 584158c into ampproject:master Sep 4, 2020
@zhouyx zhouyx deleted the zero-area branch September 4, 2020 01:09
zhouyx added a commit that referenced this pull request Sep 17, 2020
zhouyx added a commit that referenced this pull request Sep 17, 2020
ampprojectbot pushed a commit that referenced this pull request Sep 18, 2020
ed-bird pushed a commit to ed-bird/amphtml that referenced this pull request Dec 10, 2020
* check belement size before setting visible percentage

* fix test

* nit
ed-bird pushed a commit to ed-bird/amphtml that referenced this pull request Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Analytics: Do not report visibility when element size is 0
4 participants