From dac414433fffc8feda3b224f6fd97afdfbf19438 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 16 Jan 2025 20:02:37 +0100
Subject: [PATCH] =?UTF-8?q?=F0=9F=A5=85=20Add=20detection=20for=20accessin?=
=?UTF-8?q?g=20undefined=20props?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
modules/ppcp-settings/resources/js/data/styling/hooks.js | 5 +++++
modules/ppcp-settings/resources/js/data/utils.js | 8 +++++++-
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/modules/ppcp-settings/resources/js/data/styling/hooks.js b/modules/ppcp-settings/resources/js/data/styling/hooks.js
index 5cf07655e..cb0508247 100644
--- a/modules/ppcp-settings/resources/js/data/styling/hooks.js
+++ b/modules/ppcp-settings/resources/js/data/styling/hooks.js
@@ -42,6 +42,11 @@ const useHooks = () => {
const getLocationProp = useCallback(
( prop ) => {
+ if ( undefined === persistentData[ location ]?.[ prop ] ) {
+ console.error(
+ `Trying to access non-existent style property: ${ location }.${ prop }. Possibly wrong style name - review the reducer.`
+ );
+ }
return persistentData[ location ]?.[ prop ];
},
[ location, persistentData ]
diff --git a/modules/ppcp-settings/resources/js/data/utils.js b/modules/ppcp-settings/resources/js/data/utils.js
index 35d7bbbf9..7d3a14af7 100644
--- a/modules/ppcp-settings/resources/js/data/utils.js
+++ b/modules/ppcp-settings/resources/js/data/utils.js
@@ -107,7 +107,13 @@ export const createHooksForStore = ( storeName ) => {
`Please create the selector "${ selector }" for store "${ storeName }"`
);
}
- return store[ selector ]()?.[ key ];
+ const selectorResult = store[ selector ]();
+ if ( undefined === selectorResult?.[ key ] ) {
+ console.error(
+ `Warning: ${ selector }()[${ key }] is undefined in store "${ storeName }". This may indicate a bug.`
+ );
+ }
+ return selectorResult?.[ key ];
},
[ key ]
);