diff --git a/package-lock.json b/package-lock.json index b8492ce8..69b28c09 100644 --- a/package-lock.json +++ b/package-lock.json @@ -167,9 +167,9 @@ } }, "@surma/rollup-plugin-off-main-thread": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/@surma/rollup-plugin-off-main-thread/-/rollup-plugin-off-main-thread-1.4.1.tgz", - "integrity": "sha512-ZPBWYQDdO4JZiTmTP3DABsHhIPA7bEJk9Znk7tZsrbPGanoGo8YxMv//WLx5Cvb+lRgS42+6yiOIYYHCKDmkpQ==", + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/@surma/rollup-plugin-off-main-thread/-/rollup-plugin-off-main-thread-1.4.2.tgz", + "integrity": "sha512-yBMPqmd1yEJo/280PAMkychuaALyQ9Lkb5q1ck3mjJrFuEobIfhnQ4J3mbvBoISmR3SWMWV+cGB/I0lCQee79A==", "dev": true, "requires": { "ejs": "^2.6.1", @@ -1671,6 +1671,12 @@ "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", "dev": true }, + "esm": { + "version": "3.2.25", + "resolved": "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz", + "integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==", + "dev": true + }, "esprima": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", @@ -2313,10 +2319,13 @@ "dev": true }, "linkstate": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/linkstate/-/linkstate-1.1.1.tgz", - "integrity": "sha512-5SICdxQG9FpWk44wSEoM2WOCUNuYfClp10t51XAIV5E7vUILF/dTYxf0vJw6bW2dUd2wcQon+LkNtRijpNLrig==", - "dev": true + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/linkstate/-/linkstate-2.0.0.tgz", + "integrity": "sha512-ti9WqRjpLqUd8wv4vUDjeqMeAObSieeEJA7QHpUKTDr75gkuWTsgm4+Tngg/3uTogSz68hJ/c+676rLfSgqHUg==", + "dev": true, + "requires": { + "esm": "^3.2.25" + } }, "lint-staged": { "version": "10.5.1", diff --git a/package.json b/package.json index b2bb6600..1583238e 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "@rollup/plugin-commonjs": "^15.1.0", "@rollup/plugin-node-resolve": "^9.0.0", "@rollup/plugin-replace": "^2.3.4", - "@surma/rollup-plugin-off-main-thread": "^1.4.1", + "@surma/rollup-plugin-off-main-thread": "^1.4.2", "@types/node": "^14.14.7", "comlink": "^4.3.0", "cssnano": "^4.1.10", @@ -21,7 +21,7 @@ "file-drop-element": "^1.0.1", "husky": "^4.3.0", "idb-keyval": "^3.2.0", - "linkstate": "^1.1.1", + "linkstate": "^2.0.0", "lint-staged": "^10.5.1", "lodash.camelcase": "^4.3.0", "mime-types": "^2.1.27", diff --git a/src/client/lazy-app/Compress/index.tsx b/src/client/lazy-app/Compress/index.tsx index 80bb6547..8fb708e4 100644 --- a/src/client/lazy-app/Compress/index.tsx +++ b/src/client/lazy-app/Compress/index.tsx @@ -230,6 +230,24 @@ async function processSvg( ); } +/** + * If two processors are disabled, they're considered equivalent, otherwise + * equivalence is based on === + */ +function processorStateEquivalent(a: ProcessorState, b: ProcessorState) { + // Quick exit + if (a === b) return true; + + // All processors have the same keys + for (const key of Object.keys(a) as Array) { + // If both processors are disabled, they're the same. + if (!a[key].enabled && !b[key].enabled) continue; + if (a !== b) return false; + } + + return true; +} + // These are only used in the mobile view const resultTitles = ['Top', 'Bottom'] as const; // These are only used in the desktop view @@ -476,7 +494,11 @@ export default class Compress extends Component { const sideWorksNeeded = latestSideJobStates.map((latestSideJob, i) => { const needsProcessing = needsPreprocessing || - latestSideJob.processorState !== sideJobStates[i].processorState; + !latestSideJob.processorState || + !processorStateEquivalent( + latestSideJob.processorState, + sideJobStates[i].processorState, + ); return { processing: needsProcessing, @@ -505,6 +527,7 @@ export default class Compress extends Component { } if (!jobNeeded) return; + console.log('Processing'); const mainSignal = this.mainAbortController.signal; const sideSignals = this.sideAbortControllers.map((ac) => ac.signal);