From afc4148448d18f46b43ce4f7d9112b5be8e08990 Mon Sep 17 00:00:00 2001 From: Luc <8822552+luc-github@users.noreply.github.com> Date: Thu, 5 Dec 2024 12:51:17 +0800 Subject: [PATCH] fix race condition that make extension to be loaded twice, use isLoadedState[id] instead of isLoading to prevent it --- info.json | 2 +- src/components/App/version.js | 2 +- src/components/ExtraContent/extraContentItem.js | 11 ++++++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/info.json b/info.json index 23433675..d3c7c76a 100644 --- a/info.json +++ b/info.json @@ -1,3 +1,3 @@ { - "version": "3.0.0-a81" + "version": "3.0.0-a82" } diff --git a/src/components/App/version.js b/src/components/App/version.js index cd0e9a75..289befab 100644 --- a/src/components/App/version.js +++ b/src/components/App/version.js @@ -17,7 +17,7 @@ */ import { h } from "preact" import { webUIbuild } from "../../targets" -export const webUIversion = "3.0.0-a81" +export const webUIversion = "3.0.0-a82" export const Esp3dVersion = () => ( {webUIversion}.{webUIbuild} diff --git a/src/components/ExtraContent/extraContentItem.js b/src/components/ExtraContent/extraContentItem.js index 0321ea1c..1372c016 100644 --- a/src/components/ExtraContent/extraContentItem.js +++ b/src/components/ExtraContent/extraContentItem.js @@ -82,6 +82,7 @@ const ExtraContentItem = ({ setContentUrl(url) setHasError(false) setIsLoading(false) + isLoadedState[id] = true; }, [type]) const handleContentError = useCallback((error) => { @@ -103,13 +104,16 @@ const ExtraContentItem = ({ return } //console.log("Loading content for " + id) - setIsLoading(true) if (source.startsWith("http")) { setContentUrl(source) setHasError(false) setIsLoading(false) - isLoadedState[id] = true; + isLoadedState[id] = true } else { + if (isLoadedState[id]){ + return + } + setIsLoading(true) const idquery = type === "content" ? type + id : "download" + id let url = source if (url.endsWith(".gz")) { @@ -117,7 +121,7 @@ const ExtraContentItem = ({ } createNewRequest( espHttpURL(url), - { method: "GET", id: idquery, max: 2 }, + { method: "GET", id: idquery, max: 1 }, { onSuccess: handleContentSuccess, onFail: handleContentError, @@ -138,6 +142,7 @@ const ExtraContentItem = ({ const element = document.getElementById(id) if ( 'forceRefresh' in msg && msg.forceRefresh) { //console.log(`Processing forceRefresh for ${id}`); + isLoadedState[id] = false; loadContent() } if ('isVisible' in msg) {