feat: initialize API key on module import for improved async handling

- Start API key initialization immediately upon importing the HTTP API client module to ensure the init promise is created early.
- Log errors during API key initialization to aid in debugging.

Additionally, added a version field to the setup store for proper state hydration, aligning with the app-store pattern.
This commit is contained in:
Test User
2025-12-31 20:00:54 -05:00
parent 38f0b16530
commit 3f4f2199eb
2 changed files with 8 additions and 0 deletions

View File

@@ -1630,3 +1630,10 @@ export function getHttpApiClient(): HttpApiClient {
} }
return httpApiClientInstance; return httpApiClientInstance;
} }
// Start API key initialization immediately when this module is imported
// This ensures the init promise is created early, even before React components mount
// The actual async work happens in the background and won't block module loading
initApiKey().catch((error) => {
console.error('[HTTP Client] Failed to initialize API key:', error);
});

View File

@@ -172,6 +172,7 @@ export const useSetupStore = create<SetupState & SetupActions>()(
}), }),
{ {
name: 'automaker-setup', name: 'automaker-setup',
version: 1, // Add version field for proper hydration (matches app-store pattern)
partialize: (state) => ({ partialize: (state) => ({
isFirstRun: state.isFirstRun, isFirstRun: state.isFirstRun,
setupComplete: state.setupComplete, setupComplete: state.setupComplete,