From 17e8d52cd94469d8c1b8c5a3adbe6d417bc14ffc Mon Sep 17 00:00:00 2001 From: "Mykhailo (via MelvinBot)" Date: Fri, 20 Mar 2026 19:52:29 +0000 Subject: [PATCH 1/4] Skip background task registration in HybridApp mode The BGTaskScheduler is unavailable in HybridApp because the OldDot host app's Info.plist lacks the required BGTaskSchedulerPermittedIdentifiers configuration. Guard the defineTask call with CONFIG.IS_HYBRID_APP check and add .catch() to handle promise rejections gracefully. Co-authored-by: Mykhailo --- src/setup/backgroundTask/index.native.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/setup/backgroundTask/index.native.ts b/src/setup/backgroundTask/index.native.ts index e616dbb2dcb8..15db3b4b1d53 100644 --- a/src/setup/backgroundTask/index.native.ts +++ b/src/setup/backgroundTask/index.native.ts @@ -1,10 +1,15 @@ import TaskManager from '@expensify/react-native-background-task'; import Log from '@libs/Log'; import {flush} from '@libs/Network/SequentialQueue'; +import CONFIG from '@src/CONFIG'; const BACKGROUND_FETCH_TASK = 'FLUSH-SEQUENTIAL-QUEUE-BACKGROUND-FETCH'; -TaskManager.defineTask(BACKGROUND_FETCH_TASK, () => { - Log.info('BackgroundTask', true, `Executing ${BACKGROUND_FETCH_TASK} background task at ${new Date().toISOString()}`); - flush(); -}); +if (!CONFIG.IS_HYBRID_APP) { + TaskManager.defineTask(BACKGROUND_FETCH_TASK, () => { + Log.info('BackgroundTask', true, `Executing ${BACKGROUND_FETCH_TASK} background task at ${new Date().toISOString()}`); + flush(); + }).catch((error: unknown) => { + Log.warn('BackgroundTask', false, `Failed to define ${BACKGROUND_FETCH_TASK}: ${String(error)}`); + }); +} From ccf085c88e8e30e37c71e267fe08c24bc257969c Mon Sep 17 00:00:00 2001 From: "Mykhailo (via MelvinBot)" Date: Fri, 20 Mar 2026 20:01:31 +0000 Subject: [PATCH 2/4] Fix: correct Log.warn call signature to match 1-2 parameter API Co-authored-by: Mykhailo --- src/setup/backgroundTask/index.native.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/setup/backgroundTask/index.native.ts b/src/setup/backgroundTask/index.native.ts index 15db3b4b1d53..2d02efd9eeac 100644 --- a/src/setup/backgroundTask/index.native.ts +++ b/src/setup/backgroundTask/index.native.ts @@ -10,6 +10,6 @@ if (!CONFIG.IS_HYBRID_APP) { Log.info('BackgroundTask', true, `Executing ${BACKGROUND_FETCH_TASK} background task at ${new Date().toISOString()}`); flush(); }).catch((error: unknown) => { - Log.warn('BackgroundTask', false, `Failed to define ${BACKGROUND_FETCH_TASK}: ${String(error)}`); + Log.warn(`[BackgroundTask] Failed to define ${BACKGROUND_FETCH_TASK}: ${String(error)}`); }); } From 76cc72779e5ad3986111e45689ea6863da373d04 Mon Sep 17 00:00:00 2001 From: "Mykhailo (via MelvinBot)" Date: Fri, 20 Mar 2026 20:14:18 +0000 Subject: [PATCH 3/4] Fix: use optional chaining on defineTask to handle undefined return in test env Co-authored-by: Mykhailo --- src/setup/backgroundTask/index.native.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/setup/backgroundTask/index.native.ts b/src/setup/backgroundTask/index.native.ts index 2d02efd9eeac..bbee5e52972a 100644 --- a/src/setup/backgroundTask/index.native.ts +++ b/src/setup/backgroundTask/index.native.ts @@ -9,7 +9,7 @@ if (!CONFIG.IS_HYBRID_APP) { TaskManager.defineTask(BACKGROUND_FETCH_TASK, () => { Log.info('BackgroundTask', true, `Executing ${BACKGROUND_FETCH_TASK} background task at ${new Date().toISOString()}`); flush(); - }).catch((error: unknown) => { + })?.catch((error: unknown) => { Log.warn(`[BackgroundTask] Failed to define ${BACKGROUND_FETCH_TASK}: ${String(error)}`); }); } From 62052e067ee4dbe20beabc9834f43f78e9f6d905 Mon Sep 17 00:00:00 2001 From: "Mykhailo (via MelvinBot)" Date: Fri, 20 Mar 2026 20:16:29 +0000 Subject: [PATCH 4/4] Remove IS_HYBRID_APP guard, keep .catch() for graceful error handling The HybridApp does have BGTaskSchedulerPermittedIdentifiers configured, so the IS_HYBRID_APP guard was based on an incorrect premise. The error (BGTaskSchedulerErrorDomain error 1 = unavailable) can occur on iOS Simulator or when Background App Refresh is disabled. Adding .catch() handles these cases gracefully without suppressing background tasks in HybridApp mode. Co-authored-by: Mykhailo --- src/setup/backgroundTask/index.native.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/setup/backgroundTask/index.native.ts b/src/setup/backgroundTask/index.native.ts index bbee5e52972a..5c955c98e7b2 100644 --- a/src/setup/backgroundTask/index.native.ts +++ b/src/setup/backgroundTask/index.native.ts @@ -1,15 +1,12 @@ import TaskManager from '@expensify/react-native-background-task'; import Log from '@libs/Log'; import {flush} from '@libs/Network/SequentialQueue'; -import CONFIG from '@src/CONFIG'; const BACKGROUND_FETCH_TASK = 'FLUSH-SEQUENTIAL-QUEUE-BACKGROUND-FETCH'; -if (!CONFIG.IS_HYBRID_APP) { - TaskManager.defineTask(BACKGROUND_FETCH_TASK, () => { - Log.info('BackgroundTask', true, `Executing ${BACKGROUND_FETCH_TASK} background task at ${new Date().toISOString()}`); - flush(); - })?.catch((error: unknown) => { - Log.warn(`[BackgroundTask] Failed to define ${BACKGROUND_FETCH_TASK}: ${String(error)}`); - }); -} +TaskManager.defineTask(BACKGROUND_FETCH_TASK, () => { + Log.info('BackgroundTask', true, `Executing ${BACKGROUND_FETCH_TASK} background task at ${new Date().toISOString()}`); + flush(); +})?.catch((error: unknown) => { + Log.warn(`[BackgroundTask] Failed to define ${BACKGROUND_FETCH_TASK}: ${String(error)}`); +});