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

Add support for app shell navigation via AMP Shadow DOM #1519

Open
wants to merge 86 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
399c90a
Add query var to isolate app shell inner/outer
westonruter Oct 22, 2018
9ddac9e
Preserve admin bar for inner shell requests
westonruter Oct 22, 2018
039ef47
Fix builds after Gutenberg merged into core
westonruter Oct 22, 2018
95fe84d
Merge branch 'develop' of https://github.com/Automattic/amp-wp into a…
westonruter Oct 23, 2018
4e3afce
Preserve styles when isolating inner content element
westonruter Oct 23, 2018
46ae4fd
Inject amp-shadow into outer app shell document
westonruter Oct 23, 2018
bb160a4
Prevent outer app shell doc from being served with amp attribute
westonruter Oct 23, 2018
33cc5b7
Serve shadow-v0 instead of v0 as runtime in outer app shells
westonruter Oct 23, 2018
423bbf7
Populate shadow root with content for given URL to test
westonruter Oct 24, 2018
01e6a50
Switch back to using ID for identifying content container
westonruter Oct 24, 2018
5a0d644
Add workaround for :root pesudo selectors in shadow documents
westonruter Oct 24, 2018
ba76bbf
Preserve SVG defs when isolating inner content
westonruter Oct 24, 2018
01d76d1
Merge branch 'develop' of https://github.com/Automattic/amp-wp into a…
westonruter Oct 24, 2018
3bff41d
Merge branch 'develop' of https://github.com/Automattic/amp-wp into a…
westonruter Oct 27, 2018
adb939a
Use template tags to demarcate app shell content
westonruter Oct 28, 2018
d6a4fc2
Add app shell content placeholder
westonruter Oct 28, 2018
6c23a17
Force outer app shell to be served from non-AMP version
westonruter Oct 28, 2018
8cca74c
Move app shell setup logic into separate method
westonruter Oct 28, 2018
84a2749
Enqueue amp-shadow and amp-wp-app-shell script in non-inner requests
westonruter Oct 28, 2018
09f7875
Load AMP into shadow doc when clicking links
westonruter Oct 29, 2018
79aeeb1
Preserve purged query vars in canonical redirects
westonruter Oct 29, 2018
df6ad6a
Add handling of GET form submissions
westonruter Oct 29, 2018
1d1e05f
Upate nav menu class names based on current URL
westonruter Oct 29, 2018
2b1bd18
Prevent finishing initialization if not on frontend
westonruter Oct 29, 2018
ab9afc1
Let admin bar from shadow doc take over initial app shell admin bar
westonruter Nov 2, 2018
dc26b22
Prevent event default at end of event handler
westonruter Nov 2, 2018
9349440
Prevent enqueueing app shell JS in an AMP page
westonruter Nov 2, 2018
4dc6b1d
Prevent intercepting clicks and form submits in admin bar
westonruter Nov 2, 2018
50d9702
Prevent loading non-AMP documents into the shadow DOM
westonruter Nov 2, 2018
1a6cace
Improve XHR integration
westonruter Nov 3, 2018
d952e5e
Add popstate support and improve condition for scrolling
westonruter Nov 3, 2018
7f02f38
Merge branch 'develop' of https://github.com/Automattic/amp-wp into a…
westonruter Nov 5, 2018
fa156ac
Triger events for app-shell navigate, load, and ready
westonruter Nov 6, 2018
76dd089
Do not show fallback source as active theme if no validation errors
westonruter Nov 7, 2018
b5200e8
Temporarily add cache-busting query param for sake of XHR
westonruter Nov 8, 2018
60bf614
Preserve purged query vars during canonical redirect
westonruter Nov 8, 2018
afc46ba
Preserve purged query args on all redirects not just canonical ones
westonruter Nov 8, 2018
77b5ddc
Use AMP shadow streaming API with fetch intead of XHR
westonruter Nov 8, 2018
56e7f66
Add Web Components polyfill if Shadow DOM is not natively available
westonruter Nov 8, 2018
60b3bca
Use IIFE to support Safari
miina Nov 8, 2018
bb3f9bd
Remove unused fetchDocument function
westonruter Nov 8, 2018
b37353e
Remove unused amp_script_attributes data; allow amp_script_attributes…
westonruter Nov 8, 2018
7302a8a
Add amp-wp-app-shell to precache and use md5 as revision when WP_DEBUG
westonruter Nov 8, 2018
a2585e7
Force AMP endpoint whenever requesting inner app shell
westonruter Nov 10, 2018
8692d3e
Export isOuterAppShell to page
westonruter Nov 10, 2018
aecf9f8
Use Loading as document title for app shell
westonruter Nov 10, 2018
b9faeec
Fix serving error templates for app shell
westonruter Nov 11, 2018
d52c995
Fix adding current nav menu item class on initial app shell load
westonruter Nov 12, 2018
4252c22
Add service worker code removed from PWA plugin in https://github.com…
westonruter Nov 12, 2018
aa15ce9
Make sure offline template is included among supportable templates
westonruter Nov 12, 2018
12932c0
Update todo comments
westonruter Nov 12, 2018
1e77c6e
Fix background sync for offline comments in Workbox 4
westonruter Nov 28, 2018
ee465e7
Fix passing request to queue.pushRequest
westonruter Nov 28, 2018
ddc5b7d
Merge develop & resolve conflicts.
miina Apr 2, 2019
4ea54d8
Update ignoring phpcs rule.
miina Apr 2, 2019
854250e
Fix more phpcs issues.
miina Apr 2, 2019
993637a
Merge branch 'develop' into add/spa-amp-shadow-dom
mehigh Dec 14, 2019
d867902
Add missing changes to style sanitizer; remove duplicated autoloader …
westonruter Jan 10, 2020
8caa8db
Merge branch 'develop' of github.com:ampproject/amp-wp into add/spa-a…
westonruter Jan 10, 2020
c2667f7
Fix phpcs linting issues
westonruter Jan 10, 2020
4c7595b
Restore missing live_list_offline_commenting to AMP_Service_Worker
westonruter Jan 10, 2020
0621882
Make use of new Amp\AmpWP\Document methods; add line breaks
westonruter Jan 10, 2020
280ae0b
Fix build and unit tests by preserving uncompiled scripts
westonruter Jan 10, 2020
69afdbd
Fix eslint issues
westonruter Jan 10, 2020
659a23c
Merge pull request #3931 from xwp/add/spa-amp-shadow-dom-updated
westonruter Jan 10, 2020
0c73fa3
AppShell polyfill: Update to latest version - 2.4.0
mehigh Dec 14, 2019
6054285
Amp-Wp-App-Shell - Improve flexibility for different types of caching
mehigh Dec 14, 2019
e6d97fd
Ensure .site-content-contain element exists
indieisaconcept Nov 27, 2019
bb371b1
Add a filter to allow altering AMP output from themes
mehigh Dec 14, 2019
b7ec7dc
AppShell polyfill: Update to latest version - 2.4.1
mehigh Jan 22, 2020
f13a442
attachShadowDocAsStream expects a string type variable
dero Feb 10, 2020
87afea2
Merge pull request #4261 from dero/add/spa-amp-shadow-dom
westonruter Feb 10, 2020
f59a9c9
Revert introduction of amp_document_output filter for now
westonruter Apr 16, 2020
4d0214b
Merge pull request #4055 from xwp/add/spa-amp-shadow-dom-extras
westonruter Apr 16, 2020
c4f6760
Reuse constant
westonruter Jul 20, 2020
30e9faa
Improve copy in comment and error message
westonruter Jul 20, 2020
6d6d2af
Compile app shell JS as part of the webpack build process
delawski Jul 23, 2020
5fbc277
Use query param for inner component URL (revert 6054285f382b60790a0a4…
delawski Jul 23, 2020
3b9e07b
Allow filter of the inner component URL
delawski Jul 23, 2020
c1cfd21
Fix lint issues
delawski Jul 23, 2020
ca3c404
Merge pull request #5087 from xwp/fix/spa-amp-fetch-inner
westonruter Jul 23, 2020
7559130
Merge branch 'develop' into add/spa-amp-shadow-dom
delawski Jul 27, 2020
fd23c00
Fix indentation
delawski Jul 28, 2020
25045a7
Use proper method name
delawski Jul 28, 2020
7b9077d
Fix lint issues
delawski Jul 28, 2020
77fca7d
Merge pull request #5117 from xwp/add/spa-amp-shadow-dom
westonruter Jul 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"react"
],
"env": {
"browser": true
"browser": true,
"es6": true
},
"globals": {
"wp": true,
Expand Down
5 changes: 4 additions & 1 deletion .jshintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
**/*.min.js
**/node_modules/**
**/vendor/**
**/assets/js/*-compiled.js
**/assets/js/*-compiled.js
**/assets/js/amp-wp-app-shell.js
**/assets/js/amp-service-worker-offline-commenting.js
**/assets/js/amp-service-worker-runtime-precaching.js
6 changes: 6 additions & 0 deletions amp.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,14 @@ function amp_init() {
*/
do_action( 'amp_init' );

global $amp_service_worker;
$amp_service_worker = new AMP_Service_Worker();
$amp_service_worker->init();

add_rewrite_endpoint( amp_get_slug(), EP_PERMALINK );

add_filter( 'allowed_redirect_hosts', array( 'AMP_HTTP', 'filter_allowed_redirect_hosts' ) );
add_filter( 'wp_redirect', array( 'AMP_HTTP', 'add_purged_query_vars' ) );
AMP_HTTP::purge_amp_query_vars();
AMP_HTTP::send_cors_headers();
AMP_HTTP::handle_xhr_request();
Expand Down Expand Up @@ -509,6 +514,7 @@ function _amp_bootstrap_customizer() {
* Redirects the old AMP URL to the new AMP URL.
*
* If post slug is updated the amp page with old post slug will be redirected to the updated url.
* Also includes all original query vars.
*
* @since 0.5
* @deprecated This function is irrelevant when 'amp' theme support is added.
Expand Down
45 changes: 45 additions & 0 deletions assets/js/amp-service-worker-offline-commenting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* global ERROR_MESSAGES, SITE_URL */
{
const queue = new wp.serviceWorker.backgroundSync.Queue( 'amp-wpPendingComments' );
const errorMessages = ERROR_MESSAGES;

const commentHandler = ( { event } ) => {
const clonedRequest = event.request.clone();
return fetch( event.request ).catch( () => {
return clonedRequest.blob().then( ( body ) => {
const queuedRequest = new Request( event.request.url, {
method: event.request.method,
headers: event.request.headers,
mode: event.request.mode,
credentials: event.request.credentials,
referrer: event.request.referrer,
redirect: 'follow',
body: body
} );

// Add request to queue. @todo Replace when upgrading to Workbox v4!
westonruter marked this conversation as resolved.
Show resolved Hide resolved
queue.addRequest( queuedRequest );

const jsonBody = JSON.stringify( { message: errorMessages.comment } );
return new Response( jsonBody, {
status: 202,
statusText: 'Accepted',
headers: {
'Access-Control-Allow-Origin': SITE_URL,
'Access-Control-Allow-Credentials': 'true',
'Content-Type': 'application/json; charset=UTF-8',
'Access-Control-Expose-Headers': 'AMP-Access-Control-Allow-Source-Origin',
'AMP-Access-Control-Allow-Source-Origin': SITE_URL,
'Cache-Control': 'no-cache, must-revalidate, max-age=0'
}
} );
} );
} );
};

wp.serviceWorker.routing.registerRoute(
/\/wp-comments-post\.php\?.*_wp_amp_action_xhr_converted.*/,
commentHandler,
'POST'
);
}
9 changes: 9 additions & 0 deletions assets/js/amp-service-worker-runtime-precaching.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* global URLS */
// See AMP_Service_Workers::add_amp_runtime_caching() and <https://github.com/ampproject/amp-by-example/blob/a4d798cac6a534e0c46e78944a2718a8dab3c057/boilerplate-generator/templates/files/serviceworkerJs.js#L9-L22>.
{
self.addEventListener( 'install', event => {
event.waitUntil(
caches.open( wp.serviceWorker.core.cacheNames.runtime ).then( cache => cache.addAll( URLS ) )
);
} );
}
Loading