chore: call refreshHandler once and even if features are up to date#162
Merged
Conversation
vazarkevych
reviewed
May 21, 2026
vazarkevych
left a comment
Collaborator
There was a problem hiding this comment.
Hi @nekrich,
thanks for your contribution. The work looks good and the fix is more efficient. Please take a look at the comments - once addressed, I'll happily approve and merge. 🙌
| delegate?.featuresFetchedSuccessfully(features: features, isRemote: isRemote) | ||
| } else { | ||
| delegate?.featuresFetchFailed(error: .failedParsedEncryptedData, isRemote: isRemote) | ||
| let erorr = SDKError.failedParsedEncryptedData |
Collaborator
There was a problem hiding this comment.
erorr typo - also appears on lines 95 and 101.
| func featuresFetchFailed(error: SDKError, isRemote: Bool) {} | ||
|
|
||
| func featuresUpdateIsComplete(error: SDKError?, isRemote: Bool) { | ||
| if isRemote { |
Collaborator
There was a problem hiding this comment.
isRemote guard is not needed here. I believe we can remove this parameter.
| fetchCachedFeatures(logging: true) | ||
| if isCacheExpired(), let apiUrl = apiUrl { | ||
| guard let apiUrl else { | ||
| delegate?.featuresUpdateIsComplete(error: .invalidAPIURL, isRemote: false) |
Collaborator
There was a problem hiding this comment.
With isRemote: false it won't fire refreshHandler.
vazarkevych
approved these changes
May 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR makes
refreshHandlerbehave as a single completion signal. It is now called once for network success/failure handling and for the case where cached features are still fresh and no network request is needed.This allows us to determine the sate of the GrowthBookSDK and if the features are ready or not.
Problem
refreshCache()delegates toFeaturesViewModel.fetchFeatures, but the previous callback flow only notifiedrefreshHandlerfrom specific success or failure delegate paths and could call it several times. That meant a refresh could restore cached features and finish without notifying callers, so consumers could not reliably treatrefreshHandleras a "ready" signal.Remote evaluation also had two issues in the previous flow:
remoteEvalwas enabled and the cache was expired,fetchFeaturesstarted both the regular feature fetch and the remote-evaluation fetch.There was also a duplicate-notification risk because both
featuresFetchedSuccessfullyandsavedGroupsFetchedSuccessfullycould callrefreshHandlerduring the same response handling path.Solution
The change introduces a single delegate method,
featuresUpdateIsComplete(error:isRemote:), and routesrefreshHandlerthrough that method instead of calling it from individual feature and saved-group success/failure callbacks.FeaturesViewModel.fetchFeaturesnow:.invalidAPIURLwhen no API URL is available.GrowthBookSDKkeepsfeaturesFetchFailedandsavedGroupsFetchFailedas no-op delegate methods, if you want me to delete them just ask 😅.Tests
The patch adds regression coverage for:
refreshHandlerfiring whenrefreshCache()is called while features are already cached.featuresUpdateIsCompletebeing called once for remote-evaluation success and failure.featuresUpdateIsCompletebeing called when cached features are fresh.