diff --git a/packages/interactivity/src/directives.js b/packages/interactivity/src/directives.js index c09cecb4afc127..b3ffd8d404e128 100644 --- a/packages/interactivity/src/directives.js +++ b/packages/interactivity/src/directives.js @@ -13,6 +13,7 @@ import { deepSignal, peek } from 'deepsignal'; import { useWatch, useInit } from './utils'; import { directive, getScope, getEvaluate } from './hooks'; import { kebabToCamelCase } from './utils/kebab-to-camelcase'; +import { isDebug } from './constants'; // Assigned objects should be ignore during proxification. const contextAssignedObjects = new WeakMap(); @@ -242,11 +243,7 @@ export default () => { if ( defaultEntry ) { const { namespace, value } = defaultEntry; // Check that the value is a JSON object. Send a console warning if not. - if ( - typeof SCRIPT_DEBUG !== 'undefined' && - SCRIPT_DEBUG === true && - ! isPlainObject( value ) - ) { + if ( isDebug && ! isPlainObject( value ) ) { // eslint-disable-next-line no-console console.warn( `The value of data-wp-context in "${ namespace }" store must be a valid stringified JSON object.` diff --git a/packages/interactivity/src/hooks.tsx b/packages/interactivity/src/hooks.tsx index 76356f04d886e6..4463a455ac81f3 100644 --- a/packages/interactivity/src/hooks.tsx +++ b/packages/interactivity/src/hooks.tsx @@ -286,7 +286,7 @@ const resolve = ( path, namespace ) => { if ( isDebug ) { // eslint-disable-next-line no-console console.warn( - `The namespace "${ namespace }" defined in "data-wp-interactive" does not match with the store.` + `There was an error when trying to resolve the path "${ path }" in the namespace "${ namespace }".` ); } } diff --git a/packages/interactivity/src/vdom.ts b/packages/interactivity/src/vdom.ts index 9e6221bb871f4f..dcd4bde60fb414 100644 --- a/packages/interactivity/src/vdom.ts +++ b/packages/interactivity/src/vdom.ts @@ -5,7 +5,7 @@ import { h } from 'preact'; /** * Internal dependencies */ -import { directivePrefix as p } from './constants'; +import { isDebug, directivePrefix as p } from './constants'; const ignoreAttr = `data-${ p }-ignore`; const islandAttr = `data-${ p }-interactive`; @@ -120,12 +120,7 @@ export function toVdom( root ) { ( obj, [ name, ns, value ] ) => { const directiveMatch = directiveParser.exec( name ); if ( directiveMatch === null ) { - if ( - // @ts-expect-error This is a debug-only warning. - typeof SCRIPT_DEBUG !== 'undefined' && - // @ts-expect-error This is a debug-only warning. - SCRIPT_DEBUG === true - ) { + if ( isDebug ) { // eslint-disable-next-line no-console console.warn( `Invalid directive: ${ name }.` ); }