Skip to content

Bug: Changingtitle of Pattern file (in /patterns dir) is not reflected in the Editor UI - that shows the previous state #64173

Closed

Description

@tresorama

Description

NOTE: the only workaround I found to let the Editor show the current pattern title is to change theme and then switch back to twentytwentyfour.
I tested 2 block themes , so it is not related to twentytwentyfour

Step-by-step reproduction instructions

  1. Install a fresh TwentyTwentyFour theme
  2. Go to Apperence > Editor > Patterns > Featured (category)
  3. Check that the name of the "FAQ" pattern is "FAQ"
  4. Go to /patterns/text-faq and update like so
<?php
/**
- * Title: FAQ
+ * Title: FAQ Hello
* Slug: twentytwentyfour/text-faq
* Categories: text, about, featured
* Keywords: faq, about, frequently asked
* Viewport width: 1400
* Description: A FAQ section with a large FAQ heading and list of toggle questions and answers.
*/
?>
  1. Reload the page of step 2
  2. Check that the name of the "FAQ" pattern is still "FAQ" and not expected "FAQ Hello"

Screenshots, screen recording, code snippet

No response

Environment info

  • WP 6.6.1

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Activity

  1. added
    [Type] BugAn existing feature does not function as intended
    on Aug 1, 2024
  2. tresorama commented on Aug 1, 2024

    @tresorama
    Author

    It happens also with Categories property other than Title

  3. Rishit30G commented on Aug 1, 2024

    @Rishit30G
    Contributor

    Hi @tresorama
    I was going through your issue, I was able to replicate till Step 3..
    But I'm unable to find where this text-faq pattern is in code, can you please help me with the same
    Thanks

  4. tresorama commented on Aug 1, 2024

    @tresorama
    Author

    Yep.
    In wp-content/themes/twentytwentyfour/patterns/text-faq.php

  5. changed the title [-]Bug: Change `title` of `Pattern` file (in `/patterns` dir) is not reflected in the Editor UI - that shows the previous state[/-] [+]Bug: Changing`title` of `Pattern` file (in `/patterns` dir) is not reflected in the Editor UI - that shows the previous state[/+] on Aug 1, 2024
  6. t-hamano commented on Aug 2, 2024

    @t-hamano
    Contributor

    Thanks for the report.

    I think this issue is related to patterns being cached.

    If you want to see changes to your theme patterns immediately, defining WP_DEVELOPMENT_MODE may help. Try defining one of the following in wp-config.php:

    define( 'WP_DEVELOPMENT_MODE', 'theme' );
    define( 'WP_DEVELOPMENT_MODE', 'all' );
  7. added
    [Type] Help RequestHelp with setup, implementation, or "How do I?" questions.
    [Feature] PatternsA collection of blocks that can be synced (previously reusable blocks) or unsynced
    and removed
    [Type] BugAn existing feature does not function as intended
    on Aug 2, 2024
  8. tresorama commented on Aug 2, 2024

    @tresorama
    Author

    Thanks @t-hamano .
    It works if I do what you suggested. But now I have other questions 😎

    Question 1

    What happens if

    • dev create a block theme for a client on day 1 and deploy it
    • on day 2 developer update some Patterns inside /patterns of the theme and deploy the theme to the production site

    The client will see old or new metadata of patterns ?? Assuming the in production the WP_DEVELOPMENT_MODE constant is false

    Question 2

    Also, which is the reason to caching these kind of stuff ? It is for IO performance?

    Thanks in advance

  9. t-hamano commented on Aug 3, 2024

    @t-hamano
    Contributor

    The client will see old or new metadata of patterns ??

    Yes, looking at the source code, the pattern should be cached for 1800 seconds (30 minutes).

    https://github.com/t-hamano/wordpress-develop/blob/a799101e46ef0a042814c189a6331c23a52a100c/src/wp-includes/class-wp-theme.php#L236

    Also, which is the reason to caching these kind of stuff ? It is for IO performance?

    Probably so, and the comments in the core changeset below and the associated linked ticket may give you some idea why.

    Changeset 58025 - Themes: Cache block theme patterns in a transient.

  10. tresorama commented on Aug 3, 2024

    @tresorama
    Author

    Thanks @t-hamano for this detailed response.

    Will take a look into this, along with this article that speak about WP_DEVELOPMENT_MODE introduction.
    https://make.wordpress.org/core/2023/07/14/configuring-development-mode-in-6-3/

    Closing this issue.

  11. Andrew-Starr commented on Aug 5, 2024

    @Andrew-Starr

    What happens if

    * dev create a block theme for a client on day 1 and deploy it
    
    * on day 2 developer update some Patterns inside `/patterns` of the theme and deploy the theme to the production site
    

    @tresorama if the developer also increases the theme version, this should refresh the cache and the updated pattern will display as expected.

  12. tresorama commented on Aug 5, 2024

    @tresorama
    Author

    It makes sense!
    Thanks for clarification @Andrew-Starr

  13. margarita-boomCodes commented on Sep 18, 2024

    @margarita-boomCodes

    What happens if

    * dev create a block theme for a client on day 1 and deploy it
    
    * on day 2 developer update some Patterns inside `/patterns` of the theme and deploy the theme to the production site
    

    @tresorama if the developer also increases the theme version, this should refresh the cache and the updated pattern will display as expected.

    @Andrew-Starr Thanks for this! This sounds like an appropriate solution for production environments.

    Although I would expect, that there must be also a way to clear the cache from the backend.

  14. t-hamano commented on Sep 18, 2024

    @t-hamano
    Contributor

    @margarita-boomCodes

    We should be able to clear the pattern cache with the following code:

    $theme = wp_get_theme();
    $theme->delete_pattern_cache();
  15. nabrown commented on Dec 18, 2024

    @nabrown

    $theme = wp_get_theme();
    $theme->delete_pattern_cache();

    This does not seem to work for me. Is this actual code or just what would be ideal? The only thing I've found that works is going into the database and deleting the transient option. Changing theme version number, supposedly deleting transients with WP-Optimize, or using this code do not work. When I try to set WP_DEVELOPMENT_MODE I get an error saying it's already been set, though I can't find anywhere else it's set other than where I put it in wp-config.php.

  16. tresorama commented on Dec 18, 2024

    @tresorama
    Author

    I have no response but I'll open again
    Edit : I cannot re open it in mobile app. We'll do it later. Or maybe a maintainer can do it in the meanwhile ...

  17. margarita-boomCodes commented on Dec 18, 2024

    @margarita-boomCodes

    $theme = wp_get_theme();
    $theme->delete_pattern_cache();

    This does not seem to work for me. Is this actual code or just what would be ideal? The only thing I've found that works is going into the database and deleting the transient option. Changing theme version number, supposedly deleting transients with WP-Optimize, or using this code do not work. When I try to set WP_DEVELOPMENT_MODE I get an error saying it's already been set, though I can't find anywhere else it's set other than where I put it in wp-config.php.

    This is how I use it and it works by making this GET request: /wp-admin/?purge-theme-cache

    add_action( 'admin_init', 'boom_purge_themes_cache' );
    
    function boom_purge_themes_cache() {
    	if ( isset( $_GET['purge-theme-cache'] ) ) {
    		$theme = wp_get_theme();
    		$theme->delete_pattern_cache();
    	}
    }
    
  18. t-hamano commented on Dec 19, 2024

    @t-hamano
    Contributor

    $theme = wp_get_theme();
    $theme->delete_pattern_cache();

    This does not seem to work for me. Is this actual code or just what would be ideal?

    This is the code that actually works.

    When I try to set WP_DEVELOPMENT_MODE I get an error saying it's already been set, though I can't find anywhere else it's set other than where I put it in wp-config.php.

    You cannot declare a constant twice. If the WP_DEVELOPMENT_MODE constant already exists in the wp-config.php file, change its value.

    Another easy way to clear the pattern cache is to switch the active theme to a different one. This is because the switch_theme() function contains a process for deleting patterns cache:

    https://github.com/t-hamano/wordpress-develop/blob/a27e6a8ecd5279a45e47ef88d048643740d07b5a/src/wp-includes/theme.php#L853-L857

  19. nabrown commented on Dec 19, 2024

    @nabrown

    This is how I use it and it works by making this GET request: /wp-admin/?purge-theme-cache

    Thanks so much -- this works great.
    @t-hamano thank you for your reply as well. Although I still can't figure out where WP_DEVELOPMENT_MODE is already being set, I'm happy with the delete_pattern_cache() solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] PatternsA collection of blocks that can be synced (previously reusable blocks) or unsynced[Type] Help RequestHelp with setup, implementation, or "How do I?" questions.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions