Defer media loading and strengthen persistence tests
All checks were successful
Deploy Sokko G / deploy (push) Successful in 18s

This commit is contained in:
Shinuwa 2026-09-12 23:28:05 +02:00
parent 09a2d4b71a
commit d0e1fd73b1
19 changed files with 459 additions and 71 deletions

View file

@ -0,0 +1,28 @@
// Rôle : attend les médias persistés avant de monter un outil éditable et propose une reprise locale en cas d'échec.
import { useEffect, useState } from "react";
import { Icon } from "../../../components/Icon.jsx";
export function ModuleDataGate({ context, toolboxId, moduleId, children }) {
const ready = context.isModuleDataReady?.(toolboxId, moduleId) ?? true;
const load = context.ensureModuleData;
const [error, setError] = useState("");
const [attempt, setAttempt] = useState(0);
useEffect(() => {
if (ready || !load) return;
let cancelled = false;
void load(toolboxId, moduleId).catch((error) => {
if (!cancelled) setError(error?.message || context.storageStatus.errorTitle);
});
return () => { cancelled = true; };
}, [ready, load, toolboxId, moduleId, attempt, context.storageStatus?.errorTitle]);
if (ready) return children;
return (
<div className="empty nds-empty-state" aria-busy={!error}>
<p role={error ? "alert" : "status"}>{error || context.storageStatus.mediaLoadingMessage}</p>
{error && <button className="nds-button" data-size="sm" type="button" onClick={() => {
setError("");
setAttempt((value) => value + 1);
}}><Icon name="refresh" />{context.storageStatus.retryLabel}</button>}
</div>
);
}

View file

@ -5,6 +5,7 @@ import { useGroupedReorder } from "../../../hooks/useGroupedReorder.js";
import { useInlineEdit } from "../../../hooks/useInlineEdit.js";
import { supportsTextExchange } from "./textImport.js";
import { MODULE_COMPONENTS } from "./toolboxModuleComponents.jsx";
import { ModuleDataGate } from "./ModuleDataGate.jsx";
const MODULE_COLUMN_IDS = ["left", "right"];
@ -264,7 +265,9 @@ function ModuleShell({ toolbox, module, context, reorder, itemGroup = "", onRena
</header>
<div className={`module-content ${scrollable ? "is-scrollable legacy-scrollbar" : ""}`}>
<Suspense fallback={<ModuleLoadingFallback label={label} />}>
<Component {...componentProps} />
<ModuleDataGate key={`${toolbox.id}:${module.id}`} context={context} toolboxId={toolbox.id} moduleId={module.id}>
<Component {...componentProps} />
</ModuleDataGate>
</Suspense>
</div>
</article>