Skip to content

Commit b8169a0

Browse files
committed
Explicitly request AMP document when fetching inner app shell component
In the original app shell implementation proposed in ampproject/amp-wp#1519 the is_amp_endpoint() function was modified in order to return true if an inner component was requested. In order to achieve the same effect without altering the original is_amp_endpoint() implementation, we're explicitly asking for an AMP document when requesting the inner component. Simply, an AMP slug is appended to a URL when fetching a new page.
1 parent 54dbc6f commit b8169a0

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

assets/src/js/amp-wp-app-shell.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,24 +140,23 @@ function isHeaderVisible() {
140140
* @return {Promise<Response>} Response promise.
141141
*/
142142
function fetchShadowDocResponse( url ) {
143-
const { componentQueryVar } = ampAppShell;
143+
const { ampSlug, componentQueryVar } = ampAppShell;
144144
const componentUrl = new URL( url );
145145
componentUrl.searchParams.set( componentQueryVar, 'inner' );
146+
componentUrl.searchParams.set( ampSlug, 1 );
146147

147148
/**
148149
* Filters the inner component URL.
149150
*
150151
* This filter is useful in case a format of the inner component URL has to
151152
* be changed.
152153
*
153-
* @param {string} componentUrl Inner component URL.
154-
* @param {string} url Document base URL.
154+
* @param {URL} componentUrl Inner component URL.
155155
* @param {string} componentQueryVar Component query parameter name.
156156
*/
157157
const ampUrl = ampAppShell.hooks.applyFilters(
158158
'amp.appShell.innerComponentUrl',
159159
componentUrl,
160-
url,
161160
componentQueryVar
162161
);
163162

includes/class-amp-app-shell.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ function() use ( $requested_app_shell_component ) {
118118
'contentElementId' => self::CONTENT_ELEMENT_ID,
119119
'homeUrl' => home_url( '/' ),
120120
'adminUrl' => admin_url( '/' ),
121+
'ampSlug' => amp_get_slug(),
121122
'componentQueryVar' => self::COMPONENT_QUERY_VAR,
122123
'isOuterAppShell' => 'outer' === $requested_app_shell_component,
123124
];

0 commit comments

Comments
 (0)