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

Clear Used CSS after a Theme update #6217

Closed
alfonso100 opened this issue Oct 11, 2023 · 9 comments
Closed

Clear Used CSS after a Theme update #6217

alfonso100 opened this issue Oct 11, 2023 · 9 comments
Labels
needs: product direction type: enhancement Improvements that slightly enhance existing functionality and are fast to implement

Comments

@alfonso100
Copy link
Contributor

Is your feature request related to a problem? Please describe.
When a theme is updated by the user we don't clear the used CSS

Describe the solution you'd like
Since a theme update might contain modified/new CSS, we should clear the used css

Describe alternatives you've considered
Hook a usedcss cleanup here

function rocket_clean_cache_theme_update( $wp_upgrader, $hook_extra ) {
if ( ! isset( $hook_extra['action'] ) || 'update' !== $hook_extra['action'] ) {
return;
}
if ( ! isset( $hook_extra['type'] ) || 'theme' !== $hook_extra['type'] ) {
return;
}
if ( ! isset( $hook_extra['themes'] ) || ! is_array( $hook_extra['themes'] ) ) {
return;
}
$current_theme = wp_get_theme();
$themes = [
$current_theme->get_template(), // Parent theme.
$current_theme->get_stylesheet(), // Child theme.
];
// Bail out if the current theme or its parent is not updating.
if ( empty( array_intersect( $hook_extra['themes'], $themes ) ) ) {
return;
}
rocket_clean_domain();
}
add_action( 'upgrader_process_complete', 'rocket_clean_cache_theme_update', 10, 2 ); // When a theme is updated.

Can be achieved with a helper plugin:
https://github.com/wp-media/wp-rocket-snippets/blob/main/wp-rocket/wp-rocket-clear-usedcss-after-theme-update.php

Additional context
ticket: https://secure.helpscout.net/conversation/2387301118/447830?folderId=2683093
slack: https://wp-media.slack.com/archives/C43T1AYMQ/p1697054621682859

@tatof
Copy link

tatof commented Oct 16, 2023

Extra feature question:
Does the "clear used CSS" get triggered on a automatic theme update?

@worldwildweb
Copy link
Contributor

Would be nice to clear the Used CSS after a plugin update also
slack: https://wp-media.slack.com/archives/C08N8J6VC/p1697530071237479

@webtrainingwheels
Copy link

webtrainingwheels commented Oct 17, 2023

I'd personally prefer it to be manually triggered, but maybe we can show a notice to suggest it if needed (like we do with cache clearing after plugin updates). Regenerating the CSS is too time-consuming of a process and should only be done when absolutely necessary, IMO.

@tatof
Copy link

tatof commented Oct 17, 2023

I'm running one theme with updates on multiple websites 40+ and I would like to clear the Used CSS after I push a necessary theme update. Now I have to login to every client and press the clear button...

If there is a hook to trigger it from within my theme its also a solution :)

@piotrbak piotrbak added type: enhancement Improvements that slightly enhance existing functionality and are fast to implement needs: product direction labels Oct 23, 2023
@piotrbak
Copy link
Contributor

@DahmaniAdame What do you think about this? Automatically clearing Used CSS after each theme/plugin update seems to be a huge waste of resources.

@tatof
Copy link

tatof commented Oct 23, 2023

@piotrbak CSS is one of the most important parts of a theme. Theme updates should trigger a regenerate of cache & used CSS.

Tor example: The theme developer fixed html of a button and needed to alter the CSS to maintain the styling. Theme update rolls out, Cache is deleted but Used CSS is not. Then you have a button with new html but broken styling. Don't think that's what you want.

@DahmaniAdame
Copy link
Contributor

@piotrbak the risk is that if the update has a front-end change. That would result in a broken element.

A notification about the change to the customer with them taking action if necessary will do.

Just like with do when adding/removing a plugin. We prompt a message to ask the customer clear cache if they know there is a change on the frontend. That will reduce the risk of something breaking.

@tatof

CSS is one of the most important parts of a theme.

It's not always the case.

But I agree that we need to provide a clearer way to communicate the risk and help the customer take action.

@piotrbak
Copy link
Contributor

@DahmaniAdame So, when the currently used theme is updated, we should display a notice similar to this one?
image

@piotrbak
Copy link
Contributor

We did not have enough feedback from customers related to this issue. We might reopen this in the future.

For now the solution is to use the helper plugin. Theme's updates should not cause the changes in the UI.

@piotrbak piotrbak closed this as not planned Won't fix, can't repro, duplicate, stale Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: product direction type: enhancement Improvements that slightly enhance existing functionality and are fast to implement
Projects
None yet
Development

No branches or pull requests

6 participants