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

SPA with amp shadow DOM extras #4055

Conversation

mehigh
Copy link
Contributor

@mehigh mehigh commented Jan 10, 2020

Summary

Issued it against the branch part of this PR: #1519

This contains some improvements to amp-wp-app-shell.js contributed by Jonathan Barnett ( @indieisaconcept ). Consent was already provided.

Ensure .site-content-contain element exists

Rationale
A prior change introduced an early return for isHeaderVisible should the
site-branding element not be found in the document. However this early
return caused code to trigger elsewhere related to scrolling.

Changes

Ensure .site-content-contain document lookup is also guarded to prevent
calling scrollIntoView on a non-existing dom element.
Rationale
Due to caching restrictions with WPengine the use of a query-string parameter to
denote an inner shell request is problematic as it prevents the request from
being cached independently. The request needs to be distinctly different from
the outer shell in-order for it to be treated as a seperate cache item.

Changes

Query string parameter is now appended to the path instead of
Fixed bug where code was always expecting a .site-branding element to exist

Checklist

  • My pull request is addressing an open issue (please create one otherwise).
  • My code is tested and passes existing tests.
  • My code follows the Engineering Guidelines (updates are often made to the guidelines, check it out periodically).

@googlebot
Copy link

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added the cla: no Has not signed the Google CLA label Jan 10, 2020
@westonruter
Copy link
Member

You can now rebase against add/spa-amp-shadow-dom. Note I independently also fixed c5b6ee9 so you can omit that commit from being included.

@mehigh
Copy link
Contributor Author

mehigh commented Jan 22, 2020

Thank you for the feedback, glad to hear one of the items were already fixed. I'll only include the others.

mehigh and others added 4 commits January 22, 2020 17:07
Update amp-wp-app-shell.js

**Rationale**
Due to caching restrictions with WPengine the use of a query-string parameter to
denote an inner shell request is problematic as it prevents the request from
being cached independently. The request needs to be distinctly different from
the outer shell in-order for it to be treated as a seperate cache item.

**Changes**

- Query string parameter is now appended to the path instead of
- Fixed bug where code was always expecting a .site-branding element to exist
**Rationale**
A prior change introduced an early return for `isHeaderVisible` should the
`site-branding` element not be found in the document. However this early
return caused code to trigger elsewhere related to scrolling.

**Changes**

- Ensure `.site-content-contain` document lookup is also guarded to prevent
  calling scrollIntoView on a non-existing dom element.
@mehigh mehigh force-pushed the add/spa-amp-shadow-dom-extras branch from c5b6ee9 to bb371b1 Compare January 22, 2020 15:08
@mehigh
Copy link
Contributor Author

mehigh commented Jan 22, 2020

This was rebased, only the remaining 4 commits are present now.

@mehigh
Copy link
Contributor Author

mehigh commented Jan 22, 2020

I consent to this being merged, and Jonathan Barnett gave it in a different PR where I originally added this in, so we should be good with the consent needs.

@westonruter
Copy link
Member

@indieisaconcept sorry, I need you to do another @googlebot I consent.

@@ -2033,7 +2033,7 @@ public static function is_output_buffering() {
*/
public static function finish_output_buffering( $response ) {
self::$is_output_buffering = false;
return self::prepare_response( $response );
return apply_filters( 'amp_document_output', self::prepare_response( $response ) );
Copy link
Member

Choose a reason for hiding this comment

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

This is a very powerful filter that has the possibility of overriding AMP validity. Any such mutations to the document should rather be done through sanitizers, which the AMP plugin will then guarantee to be valid AMP since the tag-and-attribute sanitizer runs last. So I think bb371b1 should be reverted.

Choose a reason for hiding this comment

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

@westonruter we found this feature to be necessary in-order to integrate non AMP compatible code into our documents. This was a conscious decision on our part & we were well aware of the implications of such a change in terms of AMP validation. As a publisher this level of flexibility is really important as unfortunately AMP compatibility is not a priority for some third-party services.

As an aside I think AMP validation in general needs to be overhauled to provide a broader degree of opt-in/opt-out flexibility but I see that as a larger discussion outside of the scope of this specific PR & better suited to ampproject/amphtml.

Copy link
Member

@westonruter westonruter Jan 22, 2020

Choose a reason for hiding this comment

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

@indieisaconcept What specific changes did you need to make? There is now a way to do this officially via AMP dev mode, depending on your use case.

Copy link
Member

Choose a reason for hiding this comment

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

I've reverted this for now in f59a9c9.

@@ -124,7 +127,8 @@
*/
function fetchShadowDocResponse( url ) {
const ampUrl = new URL( url );
ampUrl.searchParams.set( ampAppShell.componentQueryVar, 'inner' );
const pathSuffix = '_' + ampAppShell.componentQueryVar + '_inner';
ampUrl.pathname = ampUrl.pathname + pathSuffix;
Copy link
Member

Choose a reason for hiding this comment

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

Does this not require the addition of new rewrite rules?

@indieisaconcept
Copy link

@googlebot I consent.

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes Signed the Google CLA and removed cla: no Has not signed the Google CLA labels Jan 22, 2020
@westonruter westonruter merged commit 4d0214b into ampproject:add/spa-amp-shadow-dom Apr 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Signed the Google CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants