Fix selectedClient persistence bug on page refresh

Issue: When refreshing the page after selecting a client, saved files
would not display because init() was called without await, causing a
race condition where loadSavedFiles() could execute before selectedClient
was properly set.

Fix: Added await to init() call in DOMContentLoaded handler (line 3280)
to ensure init() completes before continuing. This guarantees that
loadSavedFiles() is called after selectedClient is properly set.

Also added debug logging to trace selectedClient value through the
initialization process for easier troubleshooting.

Testing: After this fix, refreshing the page should properly restore
the selected client and display their saved files.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
nickviljoen 2026-02-02 12:15:32 +02:00
parent 08a9901d70
commit 564ee96ac7

View file

@ -755,10 +755,12 @@
try {
console.log('About to load profiles...');
console.log('selectedClient in init():', selectedClient);
await loadProfiles(selectedClient);
console.log('Profiles loaded successfully');
console.log('About to load saved files...');
console.log('selectedClient before loadSavedFiles():', selectedClient);
await loadSavedFiles();
console.log('Saved files loaded successfully');
@ -3277,7 +3279,7 @@
console.log('Stored client found:', storedClient);
selectedClient = storedClient;
await loadProfiles(storedClient);
init();
await init();
updateReferenceAssetsDropdown();
document.getElementById('mainApp').style.display = 'block';
} else if (storedClient) {