Commit f3eac49e1d for woocommerce

commit f3eac49e1d8bd39fbfde10bc9a037e5131a27775
Author: Luigi Teschio <gigitux@gmail.com>
Date:   Thu Apr 17 14:52:27 2025 +0200

    Block Patterns cache: ensure that relative path are used (#57333)

    * Block Patterns cache: ensure that relative path are used

    * fix: only register pattern with valid content

    * fix logic

    * Add changefile(s) from automation for the following project(s): woocommerce

    * add comment

    * add comment

    ---------

    Co-authored-by: Tung Du <dinhtungdu@gmail.com>
    Co-authored-by: github-actions <github-actions@github.com>

diff --git a/plugins/woocommerce/changelog/57333-wooplug-2826-block-patterns-cache-transient-may-contain-incorrect-paths b/plugins/woocommerce/changelog/57333-wooplug-2826-block-patterns-cache-transient-may-contain-incorrect-paths
new file mode 100644
index 0000000000..84cc5e63e3
--- /dev/null
+++ b/plugins/woocommerce/changelog/57333-wooplug-2826-block-patterns-cache-transient-may-contain-incorrect-paths
@@ -0,0 +1,4 @@
+Significance: minor
+Type: fix
+
+Block Patterns cache: ensure that relative path are used.
\ No newline at end of file
diff --git a/plugins/woocommerce/src/Blocks/BlockPatterns.php b/plugins/woocommerce/src/Blocks/BlockPatterns.php
index febd81c9ef..2f0c8e757c 100644
--- a/plugins/woocommerce/src/Blocks/BlockPatterns.php
+++ b/plugins/woocommerce/src/Blocks/BlockPatterns.php
@@ -114,7 +114,18 @@ class BlockPatterns {

 		$patterns = $this->get_block_patterns();
 		foreach ( $patterns as $pattern ) {
-			$this->pattern_registry->register_block_pattern( $pattern['source'], $pattern, $this->get_patterns_dictionary() );
+			/**
+			 * Handle backward compatibility for pattern source paths.
+			 * Previously, patterns were stored with absolute paths. Now we store relative paths.
+			 * If we encounter a pattern with an absolute path (containing $patterns_path),
+			 * we keep it as is. Otherwise, we construct the full path from the relative source.
+			 *
+			 * Remove the backward compatibility logic in the WooCommerce 10.1 lifecycle: https://github.com/woocommerce/woocommerce/issues/57354.
+			 */
+			$pattern_path      = str_contains( $pattern['source'], $this->patterns_path ) ? $pattern['source'] : $this->patterns_path . '/' . $pattern['source'];
+			$pattern['source'] = $pattern_path;
+
+			$this->pattern_registry->register_block_pattern( $pattern_path, $pattern, $this->get_patterns_dictionary() );
 		}
 	}

@@ -155,8 +166,9 @@ class BlockPatterns {
 		$patterns = array();

 		foreach ( $files as $file ) {
-			$data           = get_file_data( $file, $default_headers );
-			$data['source'] = $file;
+			$data = get_file_data( $file, $default_headers );
+			// We want to store the relative path in the cache, so we can use it later to register the pattern.
+			$data['source'] = str_replace( $this->patterns_path . '/', '', $file );
 			$patterns[]     = $data;
 		}

diff --git a/plugins/woocommerce/src/Blocks/Patterns/PatternRegistry.php b/plugins/woocommerce/src/Blocks/Patterns/PatternRegistry.php
index 61c2528e59..1539e15158 100644
--- a/plugins/woocommerce/src/Blocks/Patterns/PatternRegistry.php
+++ b/plugins/woocommerce/src/Blocks/Patterns/PatternRegistry.php
@@ -176,9 +176,10 @@ class PatternRegistry {
 			include $source;
 			$pattern_data['content'] = ob_get_clean();

-			if ( ! $pattern_data['content'] ) {
-				return;
-			}
+		}
+
+		if ( empty( $pattern_data['content'] ) ) {
+			return;
 		}

 		$category_labels = $this->get_category_labels();