@@ -936,41 +936,53 @@ function initializeWithDefaultKeyStates(): Promise<void> {
936936 // This is faster than lazy-loading individual keys because:
937937 // 1. One DB transaction instead of hundreds
938938 // 2. All subsequent reads are synchronous cache hits
939- return Storage . getAll ( ) . then ( ( pairs ) => {
940- const allDataFromStorage : Record < string , unknown > = { } ;
941-
942- for ( const [ key , value ] of pairs ) {
943- // RAM-only keys should never be loaded from storage as they may have stale persisted data
944- // from before the key was migrated to RAM-only.
945- if ( isRamOnlyKey ( key ) ) {
946- continue ;
939+ return Storage . getAll ( )
940+ . then ( ( pairs ) => {
941+ const allDataFromStorage : Record < string , unknown > = { } ;
942+ for ( const [ key , value ] of pairs ) {
943+ // RAM-only keys should never be loaded from storage as they may have stale persisted data
944+ // from before the key was migrated to RAM-only.
945+ if ( isRamOnlyKey ( key ) ) {
946+ continue ;
947+ }
948+ allDataFromStorage [ key ] = value ;
947949 }
948- allDataFromStorage [ key ] = value ;
949- }
950950
951- // Load all storage data into cache silently (no subscriber notifications)
952- cache . setAllKeys ( Object . keys ( allDataFromStorage ) ) ;
953- cache . merge ( allDataFromStorage ) ;
951+ // Load all storage data into cache silently (no subscriber notifications)
952+ cache . setAllKeys ( Object . keys ( allDataFromStorage ) ) ;
953+ cache . merge ( allDataFromStorage ) ;
954954
955- // Extract only the default key states from storage and merge with defaults
956- const defaultKeysFromStorage = Object . keys ( defaultKeyStates ) . reduce ( ( obj : Record < string , unknown > , key ) => {
957- if ( key in allDataFromStorage ) {
958- // eslint-disable-next-line no-param-reassign
959- obj [ key ] = allDataFromStorage [ key ] ;
960- }
961- return obj ;
962- } , { } ) ;
955+ // Extract only the default key states from storage and merge with defaults
956+ const defaultKeysFromStorage = Object . keys ( defaultKeyStates ) . reduce ( ( obj : Record < string , unknown > , key ) => {
957+ if ( key in allDataFromStorage ) {
958+ // eslint-disable-next-line no-param-reassign
959+ obj [ key ] = allDataFromStorage [ key ] ;
960+ }
961+ return obj ;
962+ } , { } ) ;
963963
964- const merged = utils . fastMerge ( defaultKeysFromStorage , defaultKeyStates , {
965- shouldRemoveNestedNulls : true ,
966- } ) . result ;
967- cache . merge ( merged ?? { } ) ;
964+ const merged = utils . fastMerge ( defaultKeysFromStorage , defaultKeyStates , {
965+ shouldRemoveNestedNulls : true ,
966+ } ) . result ;
967+ cache . merge ( merged ?? { } ) ;
968968
969- // Only notify subscribers for default key states — same as before.
970- // Other keys will be picked up by subscribers when they connect.
971- // FIXME: Maybe we dont need this, but some tests in E/App are failing if we remove it.
972- for ( const [ key , value ] of Object . entries ( merged ?? { } ) ) keyChanged ( key , value ) ;
973- } ) ;
969+ // Only notify subscribers for default key states — same as before.
970+ // Other keys will be picked up by subscribers when they connect.
971+ // FIXME: Maybe we dont need this, but some tests in E/App are failing if we remove it.
972+ for ( const [ key , value ] of Object . entries ( merged ?? { } ) ) keyChanged ( key , value ) ;
973+ } )
974+ . catch ( ( error ) => {
975+ Logger . logAlert ( `Failed to load data from storage during init. The app will boot with default key states only. Error: ${ error } ` ) ;
976+
977+ // Populate the key index so getAllKeys() returns correct results for default keys.
978+ // Without this, subscribers that check getAllKeys() would see an empty set even
979+ // though we have default values in cache.
980+ cache . setAllKeys ( Object . keys ( defaultKeyStates ) ) ;
981+
982+ // Boot with defaults so the app renders instead of deadlocking.
983+ // Users will get a fresh-install experience but the app won't be bricked.
984+ cache . merge ( defaultKeyStates ) ;
985+ } ) ;
974986}
975987
976988/**
0 commit comments