fix: snapshot estable en store del indice (evita re-renders infinitos)
This commit is contained in:
1 parent
d30374729c
commit
5c6d6bc46e
1 file changed
+9
-1
+9
-1
@@ -15,6 +15,10 @@ import {
|
||||
let cache: ApiResponse | null = null;
|
||||
let loadError: string | null = null;
|
||||
let started = false;
|
||||
let snap: { data: ApiResponse | null; error: string | null } = {
|
||||
data: null,
|
||||
error: null,
|
||||
};
|
||||
const listeners = new Set<() => void>();
|
||||
|
||||
function notify() {
|
||||
@@ -30,6 +34,10 @@ async function load() {
|
||||
} catch (e) {
|
||||
loadError = e instanceof Error ? e.message : "Error al cargar módulos";
|
||||
}
|
||||
// Referencia estable: solo cambia si cambian los datos (evita loops)
|
||||
if (snap.data !== cache || snap.error !== loadError) {
|
||||
snap = { data: cache, error: loadError };
|
||||
}
|
||||
notify();
|
||||
}
|
||||
|
||||
@@ -46,7 +54,7 @@ function subscribe(cb: () => void) {
|
||||
}
|
||||
|
||||
function snapshot(): { data: ApiResponse | null; error: string | null } {
|
||||
return { data: cache, error: loadError };
|
||||
return snap;
|
||||
}
|
||||
|
||||
export default function Home() {
|
||||
|
||||
Reference in new issue
Block a user