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

🚀 [Page Attachments] Ensure that the page attachment container is not inadvertently rendered by the AMP Resources manager #37961

Merged
merged 13 commits into from
Apr 1, 2022

Conversation

coreymasanto
Copy link
Contributor

@coreymasanto coreymasanto commented Mar 25, 2022


The existing setOwner() call ensures that the page attachment manages its own resources instead of them being handled by the AMP Resources manager. However, it's likely that this call is running after AMP has already loaded the contents of the attachment. This PR hides the attachment container by default, which ensures that its content is not inadvertently rendered/loaded too early. The end result is that page attachment images remain unloaded until the scheduleLayout() call when the attachment fully opens.

…hide the element the first time the user starts dragging the attachment open
@coreymasanto coreymasanto marked this pull request as ready for review March 25, 2022 20:20
@amp-owners-bot
Copy link

Hey @gmajoulet, @newmuis, @mszylkowski! These files were changed:

extensions/amp-story-page-attachment/0.1/amp-story-draggable-drawer.js
extensions/amp-story-page-attachment/0.1/amp-story-page-attachment.js

Copy link
Contributor

@gmajoulet gmajoulet left a comment

Choose a reason for hiding this comment

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

const walker = this.win.document.createTreeWalker(
this.element,
NodeFilter.SHOW_ELEMENT,
null /** filter */,
false /** entityReferenceExpansion */
);
while (walker.nextNode()) {
const el = dev().assertElement(walker.currentNode);
if (isAmpElement(el)) {
this.ampComponents_.push(el);
Services.ownersForDoc(this.element).setOwner(el, this.element);
}
}

This code claims ownership over the lifecycle of all AMP elements within it. My guess is that the code runs AFTER AMP has already built images, which is why they load.

A few fixes are possible:

  1. Use CSS to hide the attachment content till layoutCallback ran. If the content is hidden, AMP will not build it
  2. Same but use JS to do so (hidden by default with CSS, made visible AFTER we claim ownership)

@coreymasanto coreymasanto changed the title 🚀 [Page Attachments] Only load page attachment images upon attachment open instead of upon story load 🚀 [Page Attachments] Ensure that the page attachment container is not inadvertently rendered by the AMP Resources manager Mar 29, 2022
@coreymasanto
Copy link
Contributor Author

A few fixes are possible:

  1. Use CSS to hide the attachment content till layoutCallback ran. If the content is hidden, AMP will not build it
  2. Same but use JS to do so (hidden by default with CSS, made visible AFTER we claim ownership)

I've taken the 2nd approach and I've updated the code, description, and title to reflect this

@gmajoulet
Copy link
Contributor

cc @processprocess to help test all draggable-drawer uses

@coreymasanto
Copy link
Contributor Author

cc processprocess to help test all draggable-drawer uses

I've tested attachments that contain a mix of images and text, on both desktop and mobile. I'll also check any other cases that we deem necessary

@processprocess
Copy link
Contributor

processprocess commented Mar 30, 2022

cc processprocess to help test all draggable-drawer uses

I've tested attachments that contain a mix of images and text, on both desktop and mobile. I'll also check any other cases that we deem necessary

Thanks for manually testing these @coreymasanto :)

@gmajoulet Our drawer visual diff tests open the attachment, which should cover this but agree it's good to manually test as well:
https://github.com/ampproject/amphtml/blob/main/examples/visual-tests/amp-story/amp-story-shopping.js#L26
https://github.com/ampproject/amphtml/blob/main/examples/visual-tests/amp-story/amp-story-page-attachment.js#L238

Copy link
Contributor

@mszylkowski mszylkowski left a comment

Choose a reason for hiding this comment

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

Looks good, make sure the network tab shows the images loading later as expected and 🚢

@coreymasanto coreymasanto enabled auto-merge (squash) March 31, 2022 17:56
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.

[Story performance] Not load all page attachment images when loading story
5 participants