question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

amp-google-doc-embed fails to display multiple documents

See original GitHub issue

Description

This page is valid: https://afdsi.com/__amp-issues/_google-doc-embed/

It uses amp-google-doc-embed to feature PDFs, Google Sheets, and Word (docx) files.

However, only the first instance of amp-google-doc-embed works.

All document types work, but only when assigned to the first tab.

Are we doing something wrong, or can only one instance of amp-google-doc-embed be displayed on a page?

Reproduction Steps

https://afdsi.com/__amp-issues/_google-doc-embed/

Browser(s) Affected

Chrome, Firefox

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
jridgewellcommented, Jul 27, 2021

First, we have a requirement that things that are display: none do not cause a layout. This is easiest to understand when discussing Ads: if an ad cannot be seen, we cannot make a network request to fill the ad slot. This is both a resource win (less network/CPU usage), and a privacy win.

So, when doing initial detection on the document, we record whether an element is displayable. Ideally, when an element becomes displayed, we want to trigger layout. But it’s extremely difficult to detect changes in display: none, because there’s no Observer in JS that will tell us when computed styles change.

We do have a MutationObserver that listens to changes to the hidden attribute, which is our approved way to handle this. We can cause mutations of hidden via amp-bind, or an on="tap:el.hide handler on the checkboxes.

1reaction
samouricommented, Jul 28, 2021

I was able to get this example working by adding on=tap:sectionN.show to each of the <input> elements. See here.

<input id="tab1" type="radio" name="tabs" on="tap:content1.show" checked>
<input id="tab2" type="radio" name="tabs" on="tap:content2.show">
<input id="tab3" type="radio" name="tabs" on="tap:content3.show">
<input id="tab4" type="radio" name="tabs" on="tap:content4.show">
<input id="tab5" type="radio" name="tabs" on="tap:content5.show">

The .show action is a workaround to force the Runtime to remeasure the element and trigger a layout if required.

Read more comments on GitHub >

github_iconTop Results From Across the Web

amp-google-document-embed
The amp-google-document-embed component displays document files like Word documents, Excel spreadsheets, and PDFs. Example: <amp-google-document-embed ...
Read more >
amphtml/amp-google-document-embed.md at main - GitHub
The amp-google-document-embed component displays document files like Word documents, Excel spreadsheets, and PDFs. Example: <amp-google-document-embed ...
Read more >
Display bug when embedding multiple Google Docs wi...
When I embed multiple Google Docs under separated {expand} macros, only the first embedded document that you click to expand will display.
Read more >
Embedding with Google AMP - Overview - Embedly
From the amp-frame docs: `amp-iframe` may not appear close to the top of the document (except for iframes that use placeholder as described...
Read more >
Embeds in Google AMP pages - Audioboom
Google AMP will refuse to load iframes near the top of the page, unless the iframe has a placeholder. (From the docs: "They...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found