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,21 @@
/**
* @license Copyright 2019 The Lighthouse Authors. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
/**
* An extension of Error that includes any stdout or stderr from a child
* process. Based on the error thrown by `child_process.exec()`.
* https://github.com/nodejs/node/blob/3aeae8d81b7b78668c37f7a07a72d94781126d49/lib/child_process.js#L150-L176
*/
export class ChildProcessError extends Error {
/**
* @param {string} message
* @param {string=} stdout
* @param {string=} stderr
*/
constructor(message: string, stdout?: string | undefined, stderr?: string | undefined);
stdout: string;
stderr: string;
}
//# sourceMappingURL=child-process-error.d.ts.map

View File

@@ -0,0 +1,25 @@
/**
* @license Copyright 2019 The Lighthouse Authors. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
/**
* An extension of Error that includes any stdout or stderr from a child
* process. Based on the error thrown by `child_process.exec()`.
* https://github.com/nodejs/node/blob/3aeae8d81b7b78668c37f7a07a72d94781126d49/lib/child_process.js#L150-L176
*/
class ChildProcessError extends Error {
/**
* @param {string} message
* @param {string=} stdout
* @param {string=} stderr
*/
constructor(message, stdout = '', stderr = '') {
super(message);
this.stdout = stdout;
this.stderr = stderr;
}
}
export {ChildProcessError};

View File

@@ -0,0 +1,78 @@
/**
* @license Copyright 2019 The Lighthouse Authors. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
/**
* A class that maintains a concurrency pool to coordinate many jobs that should
* only be run `concurrencyLimit` at a time.
* API inspired by http://bluebirdjs.com/docs/api/promise.map.html, but
* independent callers of `concurrentMap()` share the same concurrency limit.
*/
export class ConcurrentMapper {
/**
* Runs callbackfn on `values` in parallel, at a max of `concurrency` at a
* time. Resolves to an array of the results or rejects with the first
* rejected result. Default `concurrency` limit is `Infinity`.
* @template T, U
* @param {Array<T>} values
* @param {(value: T, index: number, array: Array<T>) => Promise<U>} callbackfn
* @param {{concurrency: number}} [options]
* @return {Promise<Array<U>>}
*/
static map<T_1, U_2>(values: T_1[], callbackfn: (value: T_1, index: number, array: T_1[]) => Promise<U_2>, options?: {
concurrency: number;
} | undefined): Promise<U_2[]>;
/** @type {Set<Promise<unknown>>} */
_promisePool: Set<Promise<unknown>>;
/**
* The limits of all currently running jobs. There will be duplicates.
* @type {Array<number>}
*/
_allConcurrencyLimits: Array<number>;
/**
* Returns whether there are fewer running jobs than the minimum current
* concurrency limit and the proposed new `concurrencyLimit`.
* @param {number} concurrencyLimit
*/
_canRunMoreAtLimit(concurrencyLimit: number): boolean;
/**
* Add a job to pool.
* @param {Promise<unknown>} job
* @param {number} concurrencyLimit
*/
_addJob(job: Promise<unknown>, concurrencyLimit: number): void;
/**
* Remove a job from pool.
* @param {Promise<unknown>} job
* @param {number} concurrencyLimit
*/
_removeJob(job: Promise<unknown>, concurrencyLimit: number): void;
/**
* Runs callbackfn on `values` in parallel, at a max of `concurrency` at
* a time across all callers on this instance. Resolves to an array of the
* results (for each caller separately) or rejects with the first rejected
* result. Default `concurrency` limit is `Infinity`.
* @template T, U
* @param {Array<T>} values
* @param {(value: T, index: number, array: Array<T>) => Promise<U>} callbackfn
* @param {{concurrency: number}} [options]
* @return {Promise<Array<U>>}
*/
pooledMap<T, U>(values: T[], callbackfn: (value: T, index: number, array: T[]) => Promise<U>, options?: {
concurrency: number;
} | undefined): Promise<U[]>;
/**
* Runs `fn` concurrent to other operations in the pool, at a max of
* `concurrency` at a time across all callers on this instance. Default
* `concurrency` limit is `Infinity`.
* @template U
* @param {() => Promise<U>} fn
* @param {{concurrency: number}} [options]
* @return {Promise<U>}
*/
runInPool<U_1>(fn: () => Promise<U_1>, options?: {
concurrency: number;
} | undefined): Promise<U_1>;
}
//# sourceMappingURL=concurrent-mapper.d.ts.map

View File

@@ -0,0 +1,125 @@
/**
* @license Copyright 2019 The Lighthouse Authors. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
/**
* A class that maintains a concurrency pool to coordinate many jobs that should
* only be run `concurrencyLimit` at a time.
* API inspired by http://bluebirdjs.com/docs/api/promise.map.html, but
* independent callers of `concurrentMap()` share the same concurrency limit.
*/
class ConcurrentMapper {
constructor() {
/** @type {Set<Promise<unknown>>} */
this._promisePool = new Set();
/**
* The limits of all currently running jobs. There will be duplicates.
* @type {Array<number>}
*/
this._allConcurrencyLimits = [];
}
/**
* Runs callbackfn on `values` in parallel, at a max of `concurrency` at a
* time. Resolves to an array of the results or rejects with the first
* rejected result. Default `concurrency` limit is `Infinity`.
* @template T, U
* @param {Array<T>} values
* @param {(value: T, index: number, array: Array<T>) => Promise<U>} callbackfn
* @param {{concurrency: number}} [options]
* @return {Promise<Array<U>>}
*/
static async map(values, callbackfn, options) {
const cm = new ConcurrentMapper();
return cm.pooledMap(values, callbackfn, options);
}
/**
* Returns whether there are fewer running jobs than the minimum current
* concurrency limit and the proposed new `concurrencyLimit`.
* @param {number} concurrencyLimit
*/
_canRunMoreAtLimit(concurrencyLimit) {
return this._promisePool.size < concurrencyLimit &&
this._promisePool.size < Math.min(...this._allConcurrencyLimits);
}
/**
* Add a job to pool.
* @param {Promise<unknown>} job
* @param {number} concurrencyLimit
*/
_addJob(job, concurrencyLimit) {
this._promisePool.add(job);
this._allConcurrencyLimits.push(concurrencyLimit);
}
/**
* Remove a job from pool.
* @param {Promise<unknown>} job
* @param {number} concurrencyLimit
*/
_removeJob(job, concurrencyLimit) {
this._promisePool.delete(job);
const limitIndex = this._allConcurrencyLimits.indexOf(concurrencyLimit);
if (limitIndex === -1) {
throw new Error('No current limit found for finishing job');
}
this._allConcurrencyLimits.splice(limitIndex, 1);
}
/**
* Runs callbackfn on `values` in parallel, at a max of `concurrency` at
* a time across all callers on this instance. Resolves to an array of the
* results (for each caller separately) or rejects with the first rejected
* result. Default `concurrency` limit is `Infinity`.
* @template T, U
* @param {Array<T>} values
* @param {(value: T, index: number, array: Array<T>) => Promise<U>} callbackfn
* @param {{concurrency: number}} [options]
* @return {Promise<Array<U>>}
*/
async pooledMap(values, callbackfn, options = {concurrency: Infinity}) {
const {concurrency} = options;
const result = [];
for (let i = 0; i < values.length; i++) {
// Wait until concurrency allows another run.
while (!this._canRunMoreAtLimit(concurrency)) {
// Unconditionally catch since we only care about our own failures
// (caught in the Promise.all below), not other callers.
await Promise.race(this._promisePool).catch(() => {});
}
// innerPromise removes itself from the pool and resolves on return from callback.
const innerPromise = callbackfn(values[i], i, values)
.finally(() => this._removeJob(innerPromise, concurrency));
this._addJob(innerPromise, concurrency);
result.push(innerPromise);
}
return Promise.all(result);
}
/**
* Runs `fn` concurrent to other operations in the pool, at a max of
* `concurrency` at a time across all callers on this instance. Default
* `concurrency` limit is `Infinity`.
* @template U
* @param {() => Promise<U>} fn
* @param {{concurrency: number}} [options]
* @return {Promise<U>}
*/
async runInPool(fn, options = {concurrency: Infinity}) {
// Let pooledMap handle the pool management for the cost of boxing a fake `value`.
const result = await this.pooledMap([''], fn, options);
return result[0];
}
}
export {ConcurrentMapper};

View File

@@ -0,0 +1,33 @@
/**
* @license Copyright 2019 The Lighthouse Authors. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
/**
* A simple buffered log to use in place of `console`.
*/
export class LocalConsole {
_log: string;
/**
* @param {string} str
*/
log(str: string): void;
/**
* Log but without the ending newline.
* @param {string} str
*/
write(str: string): void;
/**
* @return {string}
*/
getLog(): string;
/**
* Append a stdout and stderr to this log.
* @param {{stdout: string, stderr: string}} stdStrings
*/
adoptStdStrings(stdStrings: {
stdout: string;
stderr: string;
}): void;
}
//# sourceMappingURL=local-console.d.ts.map

View File

@@ -0,0 +1,50 @@
/**
* @license Copyright 2019 The Lighthouse Authors. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
/**
* A simple buffered log to use in place of `console`.
*/
class LocalConsole {
constructor() {
this._log = '';
}
/**
* @param {string} str
*/
log(str) {
this._log += str + '\n';
}
/**
* Log but without the ending newline.
* @param {string} str
*/
write(str) {
this._log += str;
}
/**
* @return {string}
*/
getLog() {
return this._log;
}
/**
* Append a stdout and stderr to this log.
* @param {{stdout: string, stderr: string}} stdStrings
*/
adoptStdStrings(stdStrings) {
this.write(stdStrings.stdout);
// stderr accrues many empty lines. Don't log unless there's content.
if (/\S/.test(stdStrings.stderr)) {
this.write(stdStrings.stderr);
}
}
}
export {LocalConsole};