Commit bd38a384afb for woocommerce

commit bd38a384afbbe1f0fe5ad83598c8ead2f94e3e8a
Author: Raluca Stan <ralucastn@gmail.com>
Date:   Fri Aug 28 17:14:58 2026 +0200

    Guard every hook.doc read in the Blocks hook docs builder (#68151)

    * Guard every hook.doc read in the doc builder

    actions/index.js and filters/index.js guarded with `hook.doc || []`
    and then dereferenced hook.doc.long_description anyway, so the guard
    never did anything; the same unguarded reads sit in
    generate-hook-name.js, generate-introduction.js and generate-toc.js.
    Read through the local hookDocs everywhere, and default to {} — the []
    default only worked because [].tags is undefined.

    The generator always emits doc for the hooks it keeps, so this changes
    no output: build:docs leaves actions.md and filters.md byte-identical.

    Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

    * Add changelog entry for the doc builder guards

    Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

    ---------

    Co-authored-by: Claude Opus 5 <noreply@anthropic.com>

diff --git a/plugins/woocommerce/changelog/67855-hook-docs-generator-guards b/plugins/woocommerce/changelog/67855-hook-docs-generator-guards
new file mode 100644
index 00000000000..6bf6f8496ed
--- /dev/null
+++ b/plugins/woocommerce/changelog/67855-hook-docs-generator-guards
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+
+Guard every hook.doc read in the Blocks hook docs generator. No change to the generated reference.
diff --git a/plugins/woocommerce/client/blocks/bin/hook-docs/actions/index.js b/plugins/woocommerce/client/blocks/bin/hook-docs/actions/index.js
index 979f3de3e12..c182336148e 100644
--- a/plugins/woocommerce/client/blocks/bin/hook-docs/actions/index.js
+++ b/plugins/woocommerce/client/blocks/bin/hook-docs/actions/index.js
@@ -39,13 +39,13 @@ const generate = ( hooks ) => {
 		...generateToc( hooks ),
 		{ hr: '' },
 		...hooks.map( ( hook ) => {
-			const hookDocs = hook.doc || [];
+			const hookDocs = hook.doc || {};

 			return [
 				...generateHookName( hook ),
 				...generateIntroduction( hook ),
 				...contentWithHeading(
-					hook.doc.long_description,
+					hookDocs.long_description,
 					'Description'
 				),
 				...sectionWithHeading( params( hookDocs ), 'Parameters' ),
diff --git a/plugins/woocommerce/client/blocks/bin/hook-docs/filters/index.js b/plugins/woocommerce/client/blocks/bin/hook-docs/filters/index.js
index 296f603727a..6ef0de6c2a2 100644
--- a/plugins/woocommerce/client/blocks/bin/hook-docs/filters/index.js
+++ b/plugins/woocommerce/client/blocks/bin/hook-docs/filters/index.js
@@ -39,13 +39,13 @@ const generate = ( hooks ) => {
 		...generateToc( hooks ),
 		{ hr: '' },
 		...hooks.map( ( hook ) => {
-			const hookDocs = hook.doc || [];
+			const hookDocs = hook.doc || {};

 			return [
 				...generateHookName( hook ),
 				...generateIntroduction( hook ),
 				...contentWithHeading(
-					hook.doc.long_description,
+					hookDocs.long_description,
 					'Description'
 				),
 				...sectionWithHeading( params( hookDocs ), 'Parameters' ),
diff --git a/plugins/woocommerce/client/blocks/bin/hook-docs/utilities/generate-hook-name.js b/plugins/woocommerce/client/blocks/bin/hook-docs/utilities/generate-hook-name.js
index 97eb0dbb16c..18eb612f1ac 100644
--- a/plugins/woocommerce/client/blocks/bin/hook-docs/utilities/generate-hook-name.js
+++ b/plugins/woocommerce/client/blocks/bin/hook-docs/utilities/generate-hook-name.js
@@ -1,6 +1,7 @@
 const generateHookName = ( hook ) => {
 	const hookName = hook.name;
-	const tags = hook.doc.tags || [];
+	const hookDocs = hook.doc || {};
+	const tags = hookDocs.tags || [];

 	const isDeprecated = tags.find(
 		( { name: tagName } ) => tagName === 'deprecated'
diff --git a/plugins/woocommerce/client/blocks/bin/hook-docs/utilities/generate-introduction.js b/plugins/woocommerce/client/blocks/bin/hook-docs/utilities/generate-introduction.js
index 45574fa4681..1379aeb7808 100644
--- a/plugins/woocommerce/client/blocks/bin/hook-docs/utilities/generate-introduction.js
+++ b/plugins/woocommerce/client/blocks/bin/hook-docs/utilities/generate-introduction.js
@@ -14,8 +14,9 @@ const getHookFunction = ( hookType ) => {
 const generateIntroduction = ( hook ) => {
 	const hookName = hook.name;
 	const hookType = hook.type;
+	const hookDocs = hook.doc || {};
 	const hookFunction = getHookFunction( hookType );
-	const tags = hook.doc.tags || [];
+	const tags = hookDocs.tags || [];

 	const deprecated =
 		tags.filter( ( { name: tagName } ) => tagName === 'deprecated' )[ 0 ] ||
@@ -40,7 +41,7 @@ const generateIntroduction = ( hook ) => {
 		: '';

 	return [
-		{ p: hook.doc.description },
+		{ p: hookDocs.description },
 		{
 			code: {
 				language: 'php',
diff --git a/plugins/woocommerce/client/blocks/bin/hook-docs/utilities/generate-toc.js b/plugins/woocommerce/client/blocks/bin/hook-docs/utilities/generate-toc.js
index 807a95f820c..32a97e69fc6 100644
--- a/plugins/woocommerce/client/blocks/bin/hook-docs/utilities/generate-toc.js
+++ b/plugins/woocommerce/client/blocks/bin/hook-docs/utilities/generate-toc.js
@@ -5,7 +5,8 @@ const generateToc = ( hooks ) => {
 		{
 			ul: hooks.map( ( hook ) => {
 				const hookName = hook.name;
-				const tags = hook.doc.tags || [];
+				const hookDocs = hook.doc || {};
+				const tags = hookDocs.tags || [];
 				const isDeprecated = tags.find(
 					( { name: tagName } ) => tagName === 'deprecated'
 				);