mirror of
https://github.com/aculix/negotium.git
synced 2026-09-11 07:28:17 +00:00
fix: load tasks before first render, not in onMount
Removing the splash exposed something it had been covering. Tasks loaded in onMount, so every launch rendered one frame of the empty state first. localStorage is synchronous, so there was never a reason to wait. Migration and rollover run during initialisation and the first render has the real list. onMount keeps only the rollover triggers.
This commit is contained in:
+12
-5
@@ -13,14 +13,21 @@
|
|||||||
const storage = createStorage();
|
const storage = createStorage();
|
||||||
const undoStack = createUndoStack();
|
const undoStack = createUndoStack();
|
||||||
|
|
||||||
let tasks = $state([]);
|
// Storage is synchronous, so the first render can already have the real list.
|
||||||
|
// Loading in onMount instead meant one frame of the empty state on every
|
||||||
|
// launch — previously hidden behind the splash screen, and very visible once
|
||||||
|
// that went away.
|
||||||
|
storage.migrateLegacyKeys();
|
||||||
|
const bootNow = new Date();
|
||||||
|
|
||||||
|
let tasks = $state(rollover(storage, bootNow));
|
||||||
let newTask = $state('');
|
let newTask = $state('');
|
||||||
// Seeded from the class the pre-paint script in index.html already set, so
|
// Seeded from the class the pre-paint script in index.html already set, so
|
||||||
// there is one source of truth and no post-mount correction to flash.
|
// there is one source of truth and no post-mount correction to flash.
|
||||||
let darkMode = $state(document.documentElement.classList.contains('dark'));
|
let darkMode = $state(document.documentElement.classList.contains('dark'));
|
||||||
let isInitialized = false;
|
let isInitialized = false;
|
||||||
let todayKey = $state(toKey(new Date()));
|
let todayKey = $state(toKey(bootNow));
|
||||||
let selectedKey = $state(toKey(new Date()));
|
let selectedKey = $state(toKey(bootNow));
|
||||||
let draggedItem = $state(null);
|
let draggedItem = $state(null);
|
||||||
let draggedOverIndex = $state(null);
|
let draggedOverIndex = $state(null);
|
||||||
let midnightTimer = null;
|
let midnightTimer = null;
|
||||||
@@ -286,8 +293,8 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
storage.migrateLegacyKeys();
|
// State is already loaded above; this only opens the write path and lets
|
||||||
runRollover();
|
// the theme effect run once without persisting on a plain page load.
|
||||||
isInitialized = true;
|
isInitialized = true;
|
||||||
|
|
||||||
// Four triggers, because no single one is sufficient. The timer covers a
|
// Four triggers, because no single one is sufficient. The timer covers a
|
||||||
|
|||||||
Reference in New Issue
Block a user