-
Notifications
You must be signed in to change notification settings - Fork 3.5k
#167410: _initCalled completed twice #9694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 6 commits
7a44a91
d061d6a
3ca9fc4
7781af6
a954909
6ef759f
e6adf2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,10 +49,9 @@ class GoogleSignInPlugin extends GoogleSignInPlatform { | |
@visibleForTesting GisSdkClient? debugOverrideGisSdkClient, | ||
@visibleForTesting | ||
StreamController<AuthenticationEvent>? debugAuthenticationController, | ||
}) : _gisSdkClient = debugOverrideGisSdkClient, | ||
_authenticationController = | ||
debugAuthenticationController ?? | ||
StreamController<AuthenticationEvent>.broadcast() { | ||
}) : _gisSdkClient = debugOverrideGisSdkClient, | ||
_authenticationController = debugAuthenticationController ?? | ||
StreamController<AuthenticationEvent>.broadcast() { | ||
autoDetectedClientId = web.document | ||
.querySelector(clientIdMetaSelector) | ||
?.getAttribute(clientIdAttributeName); | ||
|
@@ -68,8 +67,6 @@ class GoogleSignInPlugin extends GoogleSignInPlatform { | |
|
||
// A future that completes when the JS loader is done. | ||
late Future<void> _jsSdkLoadedFuture; | ||
// A future that completes when the `init` call is done. | ||
Completer<void>? _initCalled; | ||
|
||
// A StreamController to communicate status changes from the GisSdkClient. | ||
final StreamController<AuthenticationEvent> _authenticationController; | ||
|
@@ -89,28 +86,14 @@ class GoogleSignInPlugin extends GoogleSignInPlatform { | |
return _gisSdkClient!; | ||
} | ||
|
||
// This method throws if init or initWithParams hasn't been called at some | ||
// point in the past. It is used by the [initialized] getter to ensure that | ||
// users can't await on a Future that will never resolve. | ||
void _assertIsInitCalled() { | ||
if (_initCalled == null) { | ||
throw StateError( | ||
'GoogleSignInPlugin::init() or GoogleSignInPlugin::initWithParams() ' | ||
'must be called before any other method in this plugin.', | ||
); | ||
} | ||
} | ||
|
||
/// A future that resolves when the plugin is fully initialized. | ||
/// | ||
/// This ensures that the SDK has been loaded, and that the `init` method | ||
/// has finished running. | ||
@visibleForTesting | ||
Future<void> get initialized { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method should just be removed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will work on it and push the updated changes by today if possible There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing the function completely won't work cause the renderButton uses the initialized function as the future There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That code is wrong now though; If we want to keep There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Understood so how should I proceed?? |
||
_assertIsInitCalled(); | ||
return Future.wait<void>(<Future<void>>[ | ||
_jsSdkLoadedFuture, | ||
_initCalled!.future, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is the right fix. There's a chance There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As of |
||
]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can become: Future<void> get initialized {
_assertIsInitCalled();
return _initCalled!.future; // `init()` already awaits `_jsSdkLoadedFuture` so there's no need to wait for it here.
} |
||
} | ||
|
||
|
@@ -133,12 +116,8 @@ class GoogleSignInPlugin extends GoogleSignInPlatform { | |
' or pass clientId when initializing GoogleSignIn', | ||
); | ||
|
||
assert( | ||
params.serverClientId == null, | ||
'serverClientId is not supported on Web.', | ||
); | ||
|
||
_initCalled = Completer<void>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may work by putting the completer in a local variable: final initCalled = _initCalled = Completer<void>(); and later: initCalled.complete(); // Use the local completer, not `_initCalled` |
||
assert(params.serverClientId == null, | ||
'serverClientId is not supported on Web.'); | ||
|
||
await _jsSdkLoadedFuture; | ||
|
||
|
@@ -149,8 +128,6 @@ class GoogleSignInPlugin extends GoogleSignInPlatform { | |
authenticationController: _authenticationController, | ||
loggingEnabled: kDebugMode, | ||
); | ||
|
||
_initCalled!.complete(); // Signal that `init` is fully done. | ||
} | ||
|
||
@override | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds like there was a bug in the plugin that was fixed, which is not the case. This should say something like "Removes initialization checks, since initialization handling has moved to the app-facing package."