fix: prevent asset conflicts between React and Grid.js versions

Add coexistence checks to all enqueue methods to prevent loading
both React and Grid.js assets simultaneously.

Changes:
- ReactAdmin.php: Only enqueue React assets when ?react=1
- Init.php: Skip Grid.js when React active on admin pages
- Form.php, Coupon.php, Access.php: Restore classic assets when ?react=0
- Customer.php, Product.php, License.php: Add coexistence checks

Now the toggle between Classic and React versions works correctly.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
dwindown
2026-04-18 17:02:14 +07:00
parent bd9cdac02e
commit e8fbfb14c1
74973 changed files with 6658406 additions and 71 deletions

View File

@@ -0,0 +1,34 @@
import { createElement } from "react";
/**
* External dependencies
*/
/**
* Internal dependencies
*/
import { useToolsPanelItem } from './hook';
import { View } from '../../view';
import { contextConnect } from '../../context';
// This wraps controls to be conditionally displayed within a tools panel. It
// prevents props being applied to HTML elements that would make them invalid.
const UnconnectedToolsPanelItem = (props, forwardedRef) => {
const {
children,
isShown,
shouldRenderPlaceholder,
...toolsPanelItemProps
} = useToolsPanelItem(props);
if (!isShown) {
return shouldRenderPlaceholder ? createElement(View, {
...toolsPanelItemProps,
ref: forwardedRef
}) : null;
}
return createElement(View, {
...toolsPanelItemProps,
ref: forwardedRef
}, children);
};
export const ToolsPanelItem = contextConnect(UnconnectedToolsPanelItem, 'ToolsPanelItem');
export default ToolsPanelItem;
//# sourceMappingURL=component.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["useToolsPanelItem","View","contextConnect","UnconnectedToolsPanelItem","props","forwardedRef","children","isShown","shouldRenderPlaceholder","toolsPanelItemProps","createElement","ref","ToolsPanelItem"],"sources":["@wordpress/components/src/tools-panel/tools-panel-item/component.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef } from 'react';\n\n/**\n * Internal dependencies\n */\nimport { useToolsPanelItem } from './hook';\nimport { View } from '../../view';\nimport type { WordPressComponentProps } from '../../context';\nimport { contextConnect } from '../../context';\nimport type { ToolsPanelItemProps } from '../types';\n\n// This wraps controls to be conditionally displayed within a tools panel. It\n// prevents props being applied to HTML elements that would make them invalid.\nconst UnconnectedToolsPanelItem = (\n\tprops: WordPressComponentProps< ToolsPanelItemProps, 'div' >,\n\tforwardedRef: ForwardedRef< any >\n) => {\n\tconst {\n\t\tchildren,\n\t\tisShown,\n\t\tshouldRenderPlaceholder,\n\t\t...toolsPanelItemProps\n\t} = useToolsPanelItem( props );\n\n\tif ( ! isShown ) {\n\t\treturn shouldRenderPlaceholder ? (\n\t\t\t<View { ...toolsPanelItemProps } ref={ forwardedRef } />\n\t\t) : null;\n\t}\n\n\treturn (\n\t\t<View { ...toolsPanelItemProps } ref={ forwardedRef }>\n\t\t\t{ children }\n\t\t</View>\n\t);\n};\n\nexport const ToolsPanelItem = contextConnect(\n\tUnconnectedToolsPanelItem,\n\t'ToolsPanelItem'\n);\n\nexport default ToolsPanelItem;\n"],"mappings":";AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,SAASA,iBAAiB,QAAQ,QAAQ;AAC1C,SAASC,IAAI,QAAQ,YAAY;AAEjC,SAASC,cAAc,QAAQ,eAAe;AAG9C;AACA;AACA,MAAMC,yBAAyB,GAAGA,CACjCC,KAA4D,EAC5DC,YAAiC,KAC7B;EACJ,MAAM;IACLC,QAAQ;IACRC,OAAO;IACPC,uBAAuB;IACvB,GAAGC;EACJ,CAAC,GAAGT,iBAAiB,CAAEI,KAAM,CAAC;EAE9B,IAAK,CAAEG,OAAO,EAAG;IAChB,OAAOC,uBAAuB,GAC7BE,aAAA,CAACT,IAAI;MAAA,GAAMQ,mBAAmB;MAAGE,GAAG,EAAGN;IAAc,CAAE,CAAC,GACrD,IAAI;EACT;EAEA,OACCK,aAAA,CAACT,IAAI;IAAA,GAAMQ,mBAAmB;IAAGE,GAAG,EAAGN;EAAc,GAClDC,QACG,CAAC;AAET,CAAC;AAED,OAAO,MAAMM,cAAc,GAAGV,cAAc,CAC3CC,yBAAyB,EACzB,gBACD,CAAC;AAED,eAAeS,cAAc"}

View File

@@ -0,0 +1,139 @@
/**
* WordPress dependencies
*/
import { usePrevious } from '@wordpress/compose';
import { useCallback, useEffect, useLayoutEffect, useMemo } from '@wordpress/element';
/**
* Internal dependencies
*/
import * as styles from '../styles';
import { useToolsPanelContext } from '../context';
import { useContextSystem } from '../../context';
import { useCx } from '../../utils/hooks/use-cx';
const noop = () => {};
export function useToolsPanelItem(props) {
const {
className,
hasValue,
isShownByDefault = false,
label,
panelId,
resetAllFilter = noop,
onDeselect,
onSelect,
...otherProps
} = useContextSystem(props, 'ToolsPanelItem');
const {
panelId: currentPanelId,
menuItems,
registerResetAllFilter,
deregisterResetAllFilter,
registerPanelItem,
deregisterPanelItem,
flagItemCustomization,
isResetting,
shouldRenderPlaceholderItems: shouldRenderPlaceholder,
firstDisplayedItem,
lastDisplayedItem,
__experimentalFirstVisibleItemClass,
__experimentalLastVisibleItemClass
} = useToolsPanelContext();
// hasValue is a new function on every render, so do not add it as a
// dependency to the useCallback hook! If needed, we should use a ref.
// eslint-disable-next-line react-hooks/exhaustive-deps
const hasValueCallback = useCallback(hasValue, [panelId]);
// resetAllFilter is a new function on every render, so do not add it as a
// dependency to the useCallback hook! If needed, we should use a ref.
// eslint-disable-next-line react-hooks/exhaustive-deps
const resetAllFilterCallback = useCallback(resetAllFilter, [panelId]);
const previousPanelId = usePrevious(currentPanelId);
const hasMatchingPanel = currentPanelId === panelId || currentPanelId === null;
// Registering the panel item allows the panel to include it in its
// automatically generated menu and determine its initial checked status.
//
// This is performed in a layout effect to ensure that the panel item
// is registered before it is rendered preventing a rendering glitch.
// See: https://github.com/WordPress/gutenberg/issues/56470
useLayoutEffect(() => {
if (hasMatchingPanel && previousPanelId !== null) {
registerPanelItem({
hasValue: hasValueCallback,
isShownByDefault,
label,
panelId
});
}
return () => {
if (previousPanelId === null && !!currentPanelId || currentPanelId === panelId) {
deregisterPanelItem(label);
}
};
}, [currentPanelId, hasMatchingPanel, isShownByDefault, label, hasValueCallback, panelId, previousPanelId, registerPanelItem, deregisterPanelItem]);
useEffect(() => {
if (hasMatchingPanel) {
registerResetAllFilter(resetAllFilterCallback);
}
return () => {
if (hasMatchingPanel) {
deregisterResetAllFilter(resetAllFilterCallback);
}
};
}, [registerResetAllFilter, deregisterResetAllFilter, resetAllFilterCallback, hasMatchingPanel]);
// Note: `label` is used as a key when building menu item state in
// `ToolsPanel`.
const menuGroup = isShownByDefault ? 'default' : 'optional';
const isMenuItemChecked = menuItems?.[menuGroup]?.[label];
const wasMenuItemChecked = usePrevious(isMenuItemChecked);
const isRegistered = menuItems?.[menuGroup]?.[label] !== undefined;
const isValueSet = hasValue();
const wasValueSet = usePrevious(isValueSet);
const newValueSet = isValueSet && !wasValueSet;
// Notify the panel when an item's value has been set.
useEffect(() => {
if (!newValueSet) {
return;
}
flagItemCustomization(label, menuGroup);
}, [newValueSet, menuGroup, label, flagItemCustomization]);
// Determine if the panel item's corresponding menu is being toggled and
// trigger appropriate callback if it is.
useEffect(() => {
// We check whether this item is currently registered as items rendered
// via fills can persist through the parent panel being remounted.
// See: https://github.com/WordPress/gutenberg/pull/45673
if (!isRegistered || isResetting || !hasMatchingPanel) {
return;
}
if (isMenuItemChecked && !isValueSet && !wasMenuItemChecked) {
onSelect?.();
}
if (!isMenuItemChecked && wasMenuItemChecked) {
onDeselect?.();
}
}, [hasMatchingPanel, isMenuItemChecked, isRegistered, isResetting, isValueSet, wasMenuItemChecked, onSelect, onDeselect]);
// The item is shown if it is a default control regardless of whether it
// has a value. Optional items are shown when they are checked or have
// a value.
const isShown = isShownByDefault ? menuItems?.[menuGroup]?.[label] !== undefined : isMenuItemChecked;
const cx = useCx();
const classes = useMemo(() => {
const shouldApplyPlaceholderStyles = shouldRenderPlaceholder && !isShown;
const firstItemStyle = firstDisplayedItem === label && __experimentalFirstVisibleItemClass;
const lastItemStyle = lastDisplayedItem === label && __experimentalLastVisibleItemClass;
return cx(styles.ToolsPanelItem, shouldApplyPlaceholderStyles && styles.ToolsPanelItemPlaceholder, !shouldApplyPlaceholderStyles && className, firstItemStyle, lastItemStyle);
}, [isShown, shouldRenderPlaceholder, className, cx, firstDisplayedItem, lastDisplayedItem, __experimentalFirstVisibleItemClass, __experimentalLastVisibleItemClass, label]);
return {
...otherProps,
isShown,
shouldRenderPlaceholder,
className: classes
};
}
//# sourceMappingURL=hook.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,3 @@
export { default } from './component';
export { useToolsPanelItem } from './hook';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["default","useToolsPanelItem"],"sources":["@wordpress/components/src/tools-panel/tools-panel-item/index.ts"],"sourcesContent":["export { default } from './component';\nexport { useToolsPanelItem } from './hook';\n"],"mappings":"AAAA,SAASA,OAAO,QAAQ,aAAa;AACrC,SAASC,iBAAiB,QAAQ,QAAQ"}