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

resources-impl: fix alwayFixed #30627

Merged
merged 4 commits into from
Oct 16, 2020
Merged

Conversation

samouri
Copy link
Member

@samouri samouri commented Oct 12, 2020

Fixes #30379.

Affected components:

  • amp-addthis
  • amp-analytics
  • amp-bind-macro
  • amp-state
  • amp-sticky-ad
  • amp-user-notifications

Root cause is related to intersect-resources experiment. Since measurement can (and often will) occur before the extension loads, measurement is then done while still a stub. At that moment, isAlwaysFixed is always false.

Therefore layoutBox computations were not adjusted for position:fixed and components would not be laid out. Band-aid fix in this PR is to recompute measurements once the extension loads using the same computed rect as earlier (but now taking the fixed position into account).

Future work: instead of relying upon some notion like isAlwaysFixed, we should have a simpler flag for shouldAlwaysLayout that doesn't need to fan out into more computations

Copy link
Contributor

@dvoytenko dvoytenko left a comment

Choose a reason for hiding this comment

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

I think this is ok as a bug plug while we are reviewing all measurements anyway. But need tests here.

@samouri samouri marked this pull request as ready for review October 12, 2020 20:18
@samouri samouri requested review from micajuine-ho and removed request for jridgewell October 12, 2020 20:18
@samouri samouri self-assigned this Oct 12, 2020
@samouri samouri marked this pull request as draft October 12, 2020 20:25
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.

Thanks for quick resolution Jake!

@samouri
Copy link
Member Author

samouri commented Oct 12, 2020

I put this back in draft mode because I'm seeing some issues with the current solution :(. Investigating now

@samouri
Copy link
Member Author

samouri commented Oct 12, 2020

Argh. Yep. It is possible (especially in this example with scroll: smooth) that the viewport scroll actually changes in between the measure and the time when we realize the resource needs to be fixed.

Theres no way around performing a remeasure.

@samouri samouri marked this pull request as ready for review October 12, 2020 21:48
@jridgewell
Copy link
Contributor

Can you actually reproduce with something like amp-user-notification?

For amp-analytics, amp-state, and amp-bind-macro, I'd rather we just remove this isAlwaysFixed. This was a legacy hack we added to force elements that were way down the page to appear as if they were in the first viewport. This forced us to call their layoutCallback regardless of how far away they were. This was always a hack, and a better solution would just be for us to provide a alwaysLayoutRegardlessOfDistance API that skips the usual distance to viewport checks.

@samouri
Copy link
Member Author

samouri commented Oct 12, 2020

Can you actually reproduce with something like amp-user-notification?

I haven't tried, but the logic is the same. When the measure happens before upgrade, then any fixed element may have its rect incorrect (esp. during a scroll event).

This was always a hack, and a better solution would just be for us to provide a...

I agree! In the PR description I actively called out the desire to replace the existing method with a flag like the one you mention (shouldAlwaysLayout), and that is definitely something I'm planning on doing. Given that it is a much further departure to the way of doing things than this fix though, I'd consider this to be a safer change. I'd like to defer the bigger scope change to future PRs (as opposed to at the same time as a bugfix).

@samouri
Copy link
Member Author

samouri commented Oct 14, 2020

@jridgewell: 🏓

@samouri samouri merged commit 17f592e into ampproject:master Oct 16, 2020
@samouri samouri deleted the fix-alwaysfixed branch October 16, 2020 16:50
ed-bird pushed a commit to ed-bird/amphtml that referenced this pull request Dec 10, 2020
* resources-impl: fix always fixed

* unit test

* alternative / better fix

* better comment
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.

amp-analytics skipped initialization leading no events are sent.
5 participants