-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Conversation
…hide the element the first time the user starts dragging the attachment open
Hey @gmajoulet, @newmuis, @mszylkowski! These files were changed:
|
extensions/amp-story-page-attachment/0.1/amp-story-draggable-drawer.js
Outdated
Show resolved
Hide resolved
extensions/amp-story-page-attachment/0.1/amp-story-page-attachment.js
Outdated
Show resolved
Hide resolved
extensions/amp-story-page-attachment/0.1/amp-story-draggable-drawer.js
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
amphtml/extensions/amp-story-page-attachment/0.1/amp-story-draggable-drawer.js
Lines 167 to 179 in 12ba200
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:
- Use CSS to hide the attachment content till layoutCallback ran. If the content is hidden, AMP will not build it
- Same but use JS to do so (hidden by default with CSS, made visible AFTER we claim ownership)
…en the attachment's owner has been set to itself
I've taken the 2nd approach and I've updated the code, description, and title to reflect this |
extensions/amp-story-page-attachment/0.1/amp-story-draggable-drawer.js
Outdated
Show resolved
Hide resolved
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: |
There was a problem hiding this 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 🚢
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 thescheduleLayout()
call when the attachment fully opens.