-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Themes: Add Dialog when Switching From Retired Theme #40793
Conversation
@@ -102,7 +123,7 @@ class AutoLoadingHomepageModal extends Component { | |||
}, | |||
{ | |||
action: 'activeTheme', | |||
label: translate( 'Yes, Activate %(themeName)s', { | |||
label: translate( 'Yes, activate %(themeName)s', { |
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 change will be queued for retranslation. We'll use the existing translations in the meantime.
Bit stick on fixing the remaining three tests; it isn't the only thing dispatched, but I'm not sure how to ensure the tests recognise that.
|
@Aurorum Would you be up for a refresh on this one? |
Will try to give it a go! There's a lot of conflicts though, so I think this will take some time (or it might just be worth creating a new branch instead). |
👋 Hey @Aurorum ! Let us know if you want to try rebasing this or just create a new PR. :) |
Yes, sorry, I'll probably fix this up over the weekend (assuming it's not urgent!) :) |
@Aurorum No, certainly not urgent, we're happy for whatever time you have to contribute. ❤️ |
This reverts commit 70bb5a6.
…ite-button' into add/retired-theme-dialog
Thanks @sixhours! Uhm, I can't immediately see a solution to that. Is there any way which I'm able to run those tests locally? I've tried updating the branch and rewriting the |
@Aurorum : Try |
Thanks @mreishus! I've been looking into this a lot over the weekend, and I don't feel like I'm any closer to identifying the issue; even if you remove the |
client/state/themes/actions/activate.js -> Change line 44 to I'm not completely sure what's going on, but it's possibly that calling activate on a theme in a test used to fetch its data, but after the changes made, it does not, it only shows a warning instead.
|
I was wondering about this -- it's funny because the site ID we pass to the test is a very old site using a retired theme. I bet that could product unexpected results when we show a modal but we're expecting to activate a theme instead. I'll dig into this more. |
Nope, changing the site ID to one that uses a theme that is not already retired doesn't seem to make a difference. I'm stumped. |
is-using-retired-theme is crashing when it calls get-active-theme, because activeThemes are not defined and it assumes that activeThemes[siteId] exists diff --git a/client/state/themes/selectors/get-active-theme.js b/client/state/themes/selectors/get-active-theme.js
index 5a7afdff91..fa05b88cac 100644
--- a/client/state/themes/selectors/get-active-theme.js
+++ b/client/state/themes/selectors/get-active-theme.js
@@ -19,7 +19,10 @@ import 'calypso/state/themes/init';
* @returns {?string} Theme ID
*/
export function getActiveTheme( state, siteId ) {
+ console.log( { activeThemes: state.themes.activeThemes, siteId } );
+ console.log( 'before crash 2' );
const activeTheme = state.themes.activeThemes[ siteId ] ?? null;
+ console.log( 'after crash 2' );
// If the theme ID is suffixed with -wpcom, remove that string. This is because
// we want to treat WP.com themes identically, whether or not they're installed
// on a given Jetpack site (where the -wpcom suffix would be appended).
diff --git a/client/state/themes/selectors/is-using-retired-theme.js b/client/state/themes/selectors/is-using-retired-theme.js
index ee052390e0..05de6623b7 100644
--- a/client/state/themes/selectors/is-using-retired-theme.js
+++ b/client/state/themes/selectors/is-using-retired-theme.js
@@ -14,5 +14,9 @@ import 'calypso/state/themes/init';
* @returns {?boolean} Whether the current theme is retired.
*/
export function isUsingRetiredTheme( state, siteId ) {
- return getCanonicalTheme( state, siteId, getActiveTheme( state, siteId ) )?.retired;
+ console.log( 'before crash' );
+ console.log( getActiveTheme( state, siteId ) );
+ console.log( 'after crash' );
+ // console.log( getCanonicalTheme( state, siteId, getActiveTheme( state, siteId ) ) );
+ return false;
} |
Thanks for looking into this. I'm still unclear as to how other selectors can rely on
I feel like I'm probably missing something quite obvious but I'm not sure what? |
It may have to do with the state set up in the tests. I think adding safe navigation operators may be sufficient: diff --git a/client/state/themes/selectors/get-active-theme.js b/client/state/themes/selectors/get-active-theme.js
index 5a7afdff91..d23e4d8c7b 100644
--- a/client/state/themes/selectors/get-active-theme.js
+++ b/client/state/themes/selectors/get-active-theme.js
@@ -19,7 +19,7 @@ import 'calypso/state/themes/init';
* @returns {?string} Theme ID
*/
export function getActiveTheme( state, siteId ) {
- const activeTheme = state.themes.activeThemes[ siteId ] ?? null;
+ const activeTheme = state.themes?.activeThemes?.[ siteId ] ?? null;
// If the theme ID is suffixed with -wpcom, remove that string. This is because
// we want to treat WP.com themes identically, whether or not they're installed
// on a given Jetpack site (where the -wpcom suffix would be appended).
You'd want to test this out when actually using the site as well |
Yay, tests are passing! But I found another bug. 🙃 I don't think we can ship this until it's fixed. When you switch from a retired theme to another non-auto-loading-homepage theme in the Trending tab, the modal doesn't appear and the theme doesn't activate. This behavior is working on production but not with this PR. Going to dig into it and see if I can find the cause. |
Urgh, it's related to the bug I patched temporarily in #54648 -- updating the number of themes to show by default to a ridiculous number like 300 fixes the bug. Because Twenty Eleven appears in the All Themes view somewhere within the top 300 themes, but not the top 30, so it doesn't "count" when viewing a non-paginated static query like Trending, even if it appears close to the top of that query. |
I spent all afternoon chasing this bug down, and I think I finally found it. I've been able to trace this back to I confirmed the dispatch action is happening as intended and passing the correct https://github.com/Automattic/wp-calypso/blob/trunk/client/state/themes/selectors/get-theme.js#L23 Any theme outside the first 30 results for that query is This may be partly fixed in this PR by rebasing to include this recent bug fix -- the query might be pulling back the wrong first 30 themes because it's a merged query with the Trending themes and Recommended themes -- but it won't fix the larger issue, which is finding a way to load all the theme results for a particular query into state. That could involve enabling pagination for custom queries, or setting the static integer value high enough to include all the themes we expect to pull back in a particular custom query. I think in the interim, since we have a relatively small number of custom queries, we can pass a prop to |
This PR also breaks theme activations for FSE themes when you enable the flag Again, because those themes aren't pulled into state with the initial Recommended query. 🙃 I think rebasing to include #54770 might fix that, though. |
Sorry for the additional ping while resolving conflicts - didn't realise that would happen! This doesn't impact that codebase, it was just for updating the branch. |
Unfortunately it's still breaking activations for some themes when you're switching away from a retired theme using the Trending section. 🙃 I don't know if this is edge-case enough for it to be considered a blocker. @kwight what do you think? Continue holding on this or ship it and document the bug? I'm hoping @mreishus forays into using React Query will have the happy side effect of fixing this bug. |
@sixhours If the broken behaviour isn't in prod, let's not introduce the regression. If I understand correctly, the issue is that it's possible to have an empty Hm, retired or not, it seems like the current theme needs to be where it's expected in the state tree, and FSE themes would all be in state for the tab to display properly (and a theme to get selected)? @blackjackkent @mreishus is there something we're missing here? 🙃 |
I'm so sorry @Aurorum ; after some internal discussion about retired themes and tooling, I think we're better off leaving this dialog as-is (so, dropping this PR). Again, so sorry this one didn't work out, we do really appreciate all of your work. ❤️ |
No worries - thanks to everyone who spent time helping to try and figure this out, and sorry it couldn't work in the end. :) |
Changes proposed in this Pull Request
This converts the dialog that displays when activating a theme that has a Homepage Layout to one that serves that purpose, as well as warning when switching from a retired theme. I don't think that I'm able to change a few other cases of the previous name as it appears they involve conditions outside this repo, but I don't think that's a big deal.
Testing instructions
I took immense care here to ensure that nothing is changed when switching to a Homepage Layout, but feel free to verify this just in case! The same dialog should still appear.
This just adds a message when switching to a retired theme. Select a retired theme through WP-Admin (eg. Harmonic) and attempt to activate another theme. This should appear, and clicking the primary button should activate the theme as usual. Verify that this dialog doesn't appear in other cases.
cc @lancewillett
Fixes #40310