Files
formipay/node_modules/webpack/lib/javascript/EnableChunkLoadingPlugin.js
dwindown e8fbfb14c1 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>
2026-04-18 17:02:14 +07:00

131 lines
3.8 KiB
JavaScript

/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
/** @typedef {import("../../declarations/WebpackOptions").ChunkLoadingType} ChunkLoadingType */
/** @typedef {import("../Compiler")} Compiler */
/** @typedef {Set<ChunkLoadingType>} ChunkLoadingTypes */
/** @type {WeakMap<Compiler, ChunkLoadingTypes>} */
const enabledTypes = new WeakMap();
/**
* Returns enabled types.
* @param {Compiler} compiler compiler
* @returns {ChunkLoadingTypes} enabled types
*/
const getEnabledTypes = (compiler) => {
let set = enabledTypes.get(compiler);
if (set === undefined) {
/** @type {ChunkLoadingTypes} */
set = new Set();
enabledTypes.set(compiler, set);
}
return set;
};
class EnableChunkLoadingPlugin {
/**
* Creates an instance of EnableChunkLoadingPlugin.
* @param {ChunkLoadingType} type library type that should be available
*/
constructor(type) {
this.type = type;
}
/**
* Updates enabled using the provided compiler.
* @param {Compiler} compiler the compiler instance
* @param {ChunkLoadingType} type type of library
* @returns {void}
*/
static setEnabled(compiler, type) {
getEnabledTypes(compiler).add(type);
}
/**
* Checks enabled.
* @param {Compiler} compiler the compiler instance
* @param {ChunkLoadingType} type type of library
* @returns {void}
*/
static checkEnabled(compiler, type) {
if (!getEnabledTypes(compiler).has(type)) {
throw new Error(
`Chunk loading type "${type}" is not enabled. ` +
"EnableChunkLoadingPlugin need to be used to enable this type of chunk loading. " +
'This usually happens through the "output.enabledChunkLoadingTypes" option. ' +
'If you are using a function as entry which sets "chunkLoading", you need to add all potential chunk loading types to "output.enabledChunkLoadingTypes". ' +
`These types are enabled: ${[...getEnabledTypes(compiler)].join(", ")}`
);
}
}
/**
* Applies the plugin by registering its hooks on the compiler.
* @param {Compiler} compiler the compiler instance
* @returns {void}
*/
apply(compiler) {
const { type } = this;
// Only enable once
const enabled = getEnabledTypes(compiler);
if (enabled.has(type)) return;
enabled.add(type);
if (typeof type === "string") {
switch (type) {
case "jsonp": {
const JsonpChunkLoadingPlugin = require("../web/JsonpChunkLoadingPlugin");
new JsonpChunkLoadingPlugin().apply(compiler);
break;
}
case "import-scripts": {
const ImportScriptsChunkLoadingPlugin = require("../webworker/ImportScriptsChunkLoadingPlugin");
new ImportScriptsChunkLoadingPlugin().apply(compiler);
break;
}
case "require": {
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
const CommonJsChunkLoadingPlugin = require("../node/CommonJsChunkLoadingPlugin");
new CommonJsChunkLoadingPlugin({
asyncChunkLoading: false
}).apply(compiler);
break;
}
case "async-node": {
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
const CommonJsChunkLoadingPlugin = require("../node/CommonJsChunkLoadingPlugin");
new CommonJsChunkLoadingPlugin({
asyncChunkLoading: true
}).apply(compiler);
break;
}
case "import": {
const ModuleChunkLoadingPlugin = require("../esm/ModuleChunkLoadingPlugin");
new ModuleChunkLoadingPlugin().apply(compiler);
break;
}
default:
throw new Error(`Unsupported chunk loading type ${type}.
Plugins which provide custom chunk loading types must call EnableChunkLoadingPlugin.setEnabled(compiler, type) to disable this error.`);
}
} else {
// TODO support plugin instances here
// apply them to the compiler
}
}
}
module.exports = EnableChunkLoadingPlugin;