fix: activate a plugin's hooks only after it has registered - #334
Closed
abelonogov-ld wants to merge 1 commit into
Closed
fix: activate a plugin's hooks only after it has registered#334abelonogov-ld wants to merge 1 commit into
abelonogov-ld wants to merge 1 commit into
Conversation
A plugin's hooks now go live once every plugin has registered, rather than before register is called. This keeps a plugin's own hooks from observing what its register does, and keeps one plugin's hooks from observing another plugin's register regardless of list order. Both the plugins configured on LDConfig and those passed to registerPlugin now go through safeRegisterPlugins, so the two paths cannot drift apart. Co-authored-by: Cursor <cursoragent@cursor.com>
kinyoklion
requested changes
Aug 25, 2026
kinyoklion
left a comment
Member
There was a problem hiding this comment.
The description of this PR specifically violates the design of hooks/plugins. Which is two phases to ensures that plugins can specifically observe evaluations of themselves and other plugins. Though if a specific plugin wishes to not do that, it could be possible.
https://github.com/launchdarkly/sdk-specs/tree/main/specs/PLUGIN-sdk-plugin-support#requirement-116
If nothing else spec changes need to come before code changes, and the spec isn't changed.
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
Follow-up to #278, aligning Flutter with the same change going into the iOS and Android client SDKs (launchdarkly/ios-client-sdk#525).
A plugin's hooks now go live only once every plugin has registered, rather than before
registeris called. That has two effects:registermakes.register, which previously depended on where each plugin sat inLDConfig.plugins.The plugins configured on
LDConfigand those passed toregisterPluginnow both go throughsafeRegisterPlugins, so the two paths cannot drift apart again.safeRegisterPluginstakes anaddHookcallback and activates the collected hooks as its last step;safeRegisterPluginis the single plugin case and simply delegates.A plugin that throws from either
hooksorregisternow contributes no hooks, where before a failingregisterleft its hooks in place.This does not change when hooks are ready relative to the first identify: registration still completes inside the constructor, well before
start()opens the initial identify series.Test plan
common_client: 24 tests pass, including new coverage that hooks are activated in plugin order and that a plugin failing to register contributes noneflutter_client_sdk: full suite passes (51 tests)dart analyze/flutter analyzeclean on both packagesadds hooks only after plugin register has returned(was asserting the old ordering) and addedplugin hooks do not observe another plugin registerNote
Overview
Plugin hooks are no longer wired in before
registerruns.safeRegisterPluginsnow registers every plugin first, collects hooks only from plugins that succeed, then callsaddHookfor all of them in one pass—so hooks never see another plugin’sregisterwork (including flag evaluations during registration).safeRegisterPluginis the single-plugin entry point that delegates to the same path.On
LDClient, construction passes onlyconfig.hooksinto the common client; plugin hooks are added afterward viasafeRegisterPlugins(..., addHook, ...).registerPluginusessafeRegisterPlugininstead of activating hooks beforeregister. A plugin that throws fromhooksorregistercontributes no hooks (previously a failedregistercould still leave hooks active).Config-time and runtime plugin registration share one code path, aligning Flutter with the iOS/Android SDK change. Hook readiness relative to the first identify is unchanged—registration still finishes in the constructor before
start().Reviewed by Cursor Bugbot for commit 9e2bf0f. Bugbot is set up for automated code reviews on this repo. Configure here.