Move sidebar and offline imports to lazy loading
CI / lint (push) Failing after 21s
CI / test (push) Has been skipped
CI / build (push) Has been skipped
CI / e2e (push) Has been skipped
CI / security (push) Failing after 10s

This commit is contained in:
2026-07-20 22:31:07 -04:00
parent 790f97e501
commit c3c5f11e9b
2 changed files with 17 additions and 4 deletions
+5 -1
View File
@@ -4,7 +4,6 @@ import { safeCreateIcons } from './utils.js';
import { showToast, closeHeaderMenu } from './ui.js';
import { t, getLocale, setLocale } from './i18n.js';
import { showWelcome } from './viewer.js';
import { loadVaults, loadTags } from './sidebar.js';
// ── Global logout handler for header dropdown onclick ────────────────────
// Defined at module top level so it's always available, even if
@@ -317,10 +316,15 @@ function initLoginForm() {
// Load app data after successful login
try {
// Dynamic imports to avoid circular dependency with sidebar.js
const { loadVaults, loadTags } = await import('./sidebar.js');
await Promise.all([loadVaults(), loadTags()]);
// Start SSE sync now that auth cookie is set (dynamic import to avoid circular dep)
const { IndexUpdateManager } = await import('./sync.js');
IndexUpdateManager.connect();
// Sync offline file index now that we're authenticated
const { syncFileIndexFromServer } = await import('./offline.js');
syncFileIndexFromServer();
// Show dashboard
showWelcome();
} catch (err) {
+12 -3
View File
@@ -2,7 +2,7 @@
import { state } from './state.js';
import { t } from './i18n.js';
import { showToast } from './ui.js';
import { api } from './auth.js';
import { api, AuthManager } from './auth.js';
import { loadVaults, loadTags, refreshTagsForContext, refreshSidebarTreePreservingState } from './sidebar.js';
import { loadRecentFiles, initAboutModal } from './config.js';
import { openFile } from './viewer.js';
@@ -591,8 +591,17 @@ export function init() {
initOffline();
initThemes();
initAboutModal();
// Sync file index after a short delay (let vaults load first)
setTimeout(() => syncFileIndexFromServer(), 3000);
// Sync file index after a short delay (let vaults load first).
// Gate on auth at execution time (not scheduling time) so that
// initAuth() has a chance to complete and set _authEnabled / token.
// The login handler triggers syncFileIndexFromServer explicitly on
// fresh login, so we only do it here for already-authenticated or
// auth-disabled sessions.
setTimeout(() => {
if (!AuthManager._authEnabled || AuthManager.getToken()) {
syncFileIndexFromServer();
}
}, 3000);
initDashboardTabs();
// Listen for Forge editor rename events