mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
fix (perf): background flickering on page load #305
This commit is contained in:
@@ -20,6 +20,8 @@ export async function appendBackgroundToUI() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let lastLoadedId: string | null = null;
|
||||||
|
|
||||||
export async function loadBackground() {
|
export async function loadBackground() {
|
||||||
if (!isIndexedDBSupported()) {
|
if (!isIndexedDBSupported()) {
|
||||||
console.error("IndexedDB is not supported. Unable to load background.");
|
console.error("IndexedDB is not supported. Unable to load background.");
|
||||||
@@ -33,12 +35,21 @@ export async function loadBackground() {
|
|||||||
if (backgroundContainer) {
|
if (backgroundContainer) {
|
||||||
backgroundContainer.remove();
|
backgroundContainer.remove();
|
||||||
}
|
}
|
||||||
|
lastLoadedId = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const background = await getDataById(selectedBackgroundId);
|
const background = await getDataById(selectedBackgroundId);
|
||||||
if (!background) return;
|
if (!background) return;
|
||||||
|
|
||||||
|
// Skip reload if background hasn't changed and media element already exists
|
||||||
|
if (
|
||||||
|
selectedBackgroundId === lastLoadedId &&
|
||||||
|
document.querySelector("#media-container > .background")
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let backgroundContainer = document.querySelector(".imageBackground");
|
let backgroundContainer = document.querySelector(".imageBackground");
|
||||||
if (!backgroundContainer) {
|
if (!backgroundContainer) {
|
||||||
backgroundContainer = document.createElement("div");
|
backgroundContainer = document.createElement("div");
|
||||||
@@ -77,6 +88,7 @@ export async function loadBackground() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mediaContainer.appendChild(mediaElement);
|
mediaContainer.appendChild(mediaElement);
|
||||||
|
lastLoadedId = selectedBackgroundId;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error loading background:", error);
|
console.error("Error loading background:", error);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user