-
Notifications
You must be signed in to change notification settings - Fork 384
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 checking for whether AMP query var is defined too late for Reader themes #4999
Add checking for whether AMP query var is defined too late for Reader themes #4999
Conversation
Plugin builds for 7574646 are ready 🛎️!
|
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.
This looks good and works in testing. I think we'd better merge this and the parent branch before my settings page branch is merged because this touches a couple of files that I've either gutted or moved in my branch. The React parts should work as is, though, and src/AmpSlugCustomizationWatcher.php looks right assuming @pierlon signs off as well.
/** | ||
* External Dependencies. | ||
*/ | ||
import { AMP_QUERY_VAR, DEFAULT_AMP_QUERY_VAR, LEGACY_THEME_SLUG, AMP_QUERY_VAR_CUSTOMIZED_LATE } from 'amp-setup'; // From WP inline script. |
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.
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.
Fixed in f3f27ad
? themes.map( ( { slug } ) => slug ).includes( readerTheme ) | ||
: readerTheme === LEGACY_THEME_SLUG | ||
) { | ||
setCanGoForward( true ); | ||
} | ||
}, [ canGoForward, setCanGoForward, readerTheme, themes, themeSupport ] ); | ||
|
||
// Separate available themes (both installed and installable) from those that need to be installed manually. | ||
const { availableThemes, unavailableThemes } = useMemo( | ||
() => themes.reduce( |
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.
An error occurred on this line while testing. To reproduce:
- Select developer background (choice doesn't matter here I suppose)
- Select Transitional template mode
- Go back to previous page
Looks like this a regression. Could we add a test to catch this, @johnwatkins0?
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.
As for a suggested fix:
--- assets/src/setup/pages/choose-reader-theme/index.js (revision 463bb866a789980a9437d8412767e9fd9f2e3096)
+++ assets/src/setup/pages/choose-reader-theme/index.js (date 1594173727100)
@@ -51,18 +51,20 @@
// Separate available themes (both installed and installable) from those that need to be installed manually.
const { availableThemes, unavailableThemes } = useMemo(
- () => themes.reduce(
- ( collections, theme ) => {
- if ( ( AMP_QUERY_VAR_CUSTOMIZED_LATE && theme.slug !== LEGACY_THEME_SLUG ) || theme.availability === 'non-installable' ) {
- collections.unavailableThemes.push( theme );
- } else {
- collections.availableThemes.push( theme );
- }
+ () => themes
+ ? themes.reduce(
+ ( collections, theme ) => {
+ if ( ( AMP_QUERY_VAR_CUSTOMIZED_LATE && theme.slug !== LEGACY_THEME_SLUG ) || theme.availability === 'non-installable' ) {
+ collections.unavailableThemes.push( theme );
+ } else {
+ collections.availableThemes.push( theme );
+ }
- return collections;
- },
- { availableThemes: [], unavailableThemes: [] },
- ),
+ return collections;
+ },
+ { availableThemes: [], unavailableThemes: [] },
+ )
+ : [],
[ themes ] );
if ( fetchingThemes ) {
@johnwatkins0 If you're able to identify a simpler fix that would be great 😄.
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.
Yeah, I caught this and fixed it on my branch. I would disregard it on this branch.
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.
Sounds good.
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.
FWIW, I do (themes || []).reduce
, although I don't feel great about it.
@@ -96,7 +106,10 @@ export function ChooseReaderTheme() { | |||
{ __( 'Unavailable themes', 'amp' ) } | |||
</h3> | |||
<p> | |||
{ __( 'The following themes are compatible but cannot be installed automatically. Please install them manually, or contact your host if you are not able to do so.', 'amp' ) } | |||
{ AMP_QUERY_VAR_CUSTOMIZED_LATE | |||
? sprintf( __( 'The following themes are not available because your site (probably the active theme) has customized the AMP query var too late (it is set to “%1$s” as opposed to the default of “%2$s”). Please make sure that any customizations done by defining the AMP_QUERY_VAR constant or adding an amp_query_var filter are done before the `plugins_loaded` action with priority 8.', 'amp' ), AMP_QUERY_VAR, DEFAULT_AMP_QUERY_VAR ) |
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.
Translator comment missing.
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.
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.
Oops. I meant to remove the backticks because I saw the same weirdness.
I wasn't sure how best to add code
in this case. I suppose it requires some dangerouslySetInnerHTML
?
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.
Addressed in 018d8d8
<p> | ||
<?php | ||
/* translators: %s is the reader theme */ | ||
echo esc_html( sprintf( __( 'The "%s" theme is currently selected in the wizard. The ability to change it from the admin screen will come soon.', 'amp' ), AMP_Options_Manager::get_option( Option::READER_THEME ) ) ); |
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.
I'm wondering if we should show the theme name here instead of its slug 🤔. I doubt the typical user would be familiar with the slugs for the installed themes, and in some cases the theme slug might not easily identify the theme in question.
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.
Agreed. This is just temporary since all of this will be eliminated with the work that @johnwatkins0 is doing.
|
||
<?php if ( AMP_Options_Manager::get_option( Option::READER_THEME ) === get_template() ) : ?> | ||
<p><?php esc_html_e( 'The currently-selected Reader theme is the same as the active theme. This means that Reader mode is disabled since it is no different from Transitional mode at this point.', 'amp' ); ?></p> | ||
<div class="notice notice-info notice-alt inline"> | ||
<p><?php esc_html_e( 'The currently-selected Reader theme is the same as the active theme. This means that Reader mode is disabled since it is no different from Transitional mode at this point.', 'amp' ); ?></p> |
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.
Should we put warnings above informational notices?
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.
Agreed. This is just temporary since all of this will be eliminated with the work that @johnwatkins0 is doing.
src/AmpSlugCustomizationWatcher.php
Outdated
* | ||
* @var string|null | ||
*/ | ||
protected $customized_slug = null; |
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.
Redundant null
default value.
protected $customized_slug = null; | |
protected $customized_slug; |
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.
Obsolete as of 52efa80
I have found this always to be the case on PRs against branches that are not |
It doesn't run because the PR is not targeting one of these branches: Lines 28 to 31 in 06f6636
|
Ah OK, noted. |
Maybe we should just remove that. |
Co-authored-by: Pierre Gordon <16200219+pierlon@users.noreply.github.com>
Summary
This is a sub-PR as part #4984 and closely related to theme compatibility scanning (#4795).
Addresses this todo:
It also makes this line mostly obsolete from the prototype PR #4644:
In other words, a site will be able to still customize their query var (as part of #2204) as long as they do it before the
plugins_loaded
action (at priority 8). If they don't, then they will see this warning at the moment in the settings screen:And then, importantly, all non-legacy themes will no longer be available (with the explanation why provided), and the Next button is disabled if the previously-selected Reader theme is now no longer available:
In order to test the failure condition introduced in this PR, add a plugin that does the following:
You could also just add a
define( 'AMP_QUERY_VAR', 'late' )
to the active theme'sfunctions.php
.By contrast, to customize the query var successfully with a Reader theme, use this plugin code (just defining the constant straight away in the plugin file):
Todo
Checklist