🥅 Add detection for accessing undefined props

This commit is contained in:
Philipp Stracker 2025-01-16 20:02:37 +01:00
parent 033b6e5b74
commit dac414433f
No known key found for this signature in database
2 changed files with 12 additions and 1 deletions

View file

@ -42,6 +42,11 @@ const useHooks = () => {
const getLocationProp = useCallback( const getLocationProp = useCallback(
( prop ) => { ( 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 ]; return persistentData[ location ]?.[ prop ];
}, },
[ location, persistentData ] [ location, persistentData ]

View file

@ -107,7 +107,13 @@ export const createHooksForStore = ( storeName ) => {
`Please create the selector "${ selector }" for store "${ 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 ] [ key ]
); );