From 8412e138308044e7e6db590b2f853c02071159c3 Mon Sep 17 00:00:00 2001 From: dianaKhortiuk-frontegg Date: Wed, 22 Jul 2026 13:55:15 +0300 Subject: [PATCH] fix(react-native): cancel prior iOS Combine sinks before re-subscribing (FR-25940) Each FronteggWrapper mount calls listener() -> FronteggRN.subscribe(), which added two Combine sinks to cancellables on every call and never cancelled them (stopObserving only flips a flag). N remounts meant N x duplicate native event work per state change, masked only by the 50 ms JS debounce. Cancel and clear cancellables at the start of subscribe(), mirroring Android which disposes the prior subscription before re-subscribing. --- ios/FronteggRN.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ios/FronteggRN.swift b/ios/FronteggRN.swift index a3c530f..c66995a 100644 --- a/ios/FronteggRN.swift +++ b/ios/FronteggRN.swift @@ -34,9 +34,16 @@ class FronteggRN: RCTEventEmitter { } @objc func subscribe() -> [AnyHashable : Any]! { - + + // FR-25940: cancel any prior subscriptions before re-subscribing. Each FronteggWrapper mount + // calls subscribe(), and without clearing, the two sinks below accumulated on `cancellables` + // on every call and were never cancelled (stopObserving only flips a flag) — so every state + // change fired N× duplicate native work. Mirrors Android, which disposes before re-subscribing. + cancellables.forEach { $0.cancel() } + cancellables.removeAll() + let auth = fronteggApp.auth - + var stateChange: AnyPublisher { return Publishers.Merge5 ( auth.$refreshingToken.map { _ in },