packages icon indicating copy to clipboard operation
packages copied to clipboard

#167410: _initCalled completed twice

Open srivats22 opened this issue 5 months ago • 20 comments

This PR Fixes: https://github.com/flutter/flutter/issues/167410, where _initCalled was being performed twice on the web

Based on the discussion comments I have removed the calles to _initCalled in the google_sign_in_web package

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.

srivats22 avatar Jul 29 '25 15:07 srivats22

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

flutter-dashboard[bot] avatar Jul 29 '25 15:07 flutter-dashboard[bot]

Hi,

any idea or pointers on how to fix this:

The following TestFailure was thrown running a test (but after
the test had completed):
Expected: throws <Instance of 'StateError'>
  Actual: <Closure: () => Future<Null> from: () => {
                            let t$goto = 0, t$completer =
async._makeAsyncAwaitCompleter(T.Null());
                            var t$36asyncBody =
async._wrapJsFunctionForAsync((t$errorCode, t$result) => {
                              if (t$errorCode === 1) return
async._asyncRethrow(t$result, t$completer);
                              while (true)
                                switch (t$goto) {
                                  case 0:
                                    // Function start
                                    t$goto = 2;
                                    return
async._asyncAwait(t$36$35plugin$35get().disconnect(C[8] ||
CT.C8), t$36asyncBody, t$completer);
                                  case 2:
                                    // returning from await.
                                    // implicit return
                                    return
async._asyncReturn(null, t$completer);
                                }
                            });
                            return
async._asyncStartSync(t$36asyncBody, t$completer);
                          }>
   Which: returned a Future that emitted <null>

When the exception was thrown, this was the stack:

its failing for the same reason in 3 of the tests and the repo check I know the issue which I will fix...

srivats22 avatar Jul 29 '25 21:07 srivats22

I'm not sure I understand the question. The expectations that check that calling a method without calling init throws a StateError are failing because you removed the code that throws the StateError if a method is called without calling init.

stuartmorgan-g avatar Jul 31 '25 12:07 stuartmorgan-g

Oh so the changes in the PR is incorrect? Or something else needs to change?

srivats22 avatar Jul 31 '25 12:07 srivats22

Tests that expect that the web implementation asserts init completion everywhere are no longer valid if the web implementation no longer asserts init completion. Intentional behavioral changes often require changing tests.

stuartmorgan-g avatar Jul 31 '25 14:07 stuartmorgan-g

Understood let me look at the code and see where the initCompleted is still be called in the test and remove those... Last I checked wasn't able to find any

srivats22 avatar Jul 31 '25 14:07 srivats22

From triage: Is this ready for review?

stuartmorgan-g avatar Aug 19 '25 18:08 stuartmorgan-g

Yes its ready for review looks like I might need to fix the conflicts which I will get to

srivats22 avatar Aug 19 '25 18:08 srivats22

I made the changes based on what was put in the issue... What I got from it was since the logic has been moved outside the package the code for init seems redundant... I might have miss understood let me take a look based on the comments and try and incorporate it

srivats22 avatar Aug 20 '25 22:08 srivats22

@stuartmorgan-g what do other platforms do in this case?

Nothing; in the new version of google_sign_in, clients explicitly call an initialize method (rather than it being an internal, implicit thing on most platforms, but semi-exposed on web, as was the case before), and the docs say they must do so exactly once. It's a programming error by the client to write the code you've shown there.

If we think clients need explicit Errors when doing the wrong thing, that should be added to the app-facing package, rather than handled in each implementation. This code is a legacy of the exposed-for-web nature of the previous init code.

(Also, clients should basically never call the platform interface methods directly. That's not how most federated plugins are designed.)

stuartmorgan-g avatar Aug 21 '25 12:08 stuartmorgan-g

Thank you, I will work on it with the directions provided and update the PR

srivats22 avatar Oct 27 '25 15:10 srivats22

Is it ok if I close this PR and open a new one?

srivats22 avatar Nov 05 '25 19:11 srivats22

@srivats22 What would the goal of doing that be? Making it harder to find all the review context makes continuing the review much harder.

stuartmorgan-g avatar Nov 06 '25 14:11 stuartmorgan-g

@srivats22 What would the goal of doing that be? Making it harder to find all the review context makes continuing the review much harder.

Oh ok no worries I will just push to this... Was just thinking the number of commits were increasing hence...

srivats22 avatar Nov 06 '25 14:11 srivats22

From triage: @srivats22 Are you still planning on updating this PR based on the review feedback?

stuartmorgan-g avatar Dec 02 '25 19:12 stuartmorgan-g

From triage: @srivats22 Are you still planning on updating this PR based on the review feedback?

Hi,

yes I am still working on it... I had posted a question: Quick question on this, should _isInitCalled be a local boolean? or how should I procceed on it? Once I get the answer I will try and finalize it by this week

srivats22 avatar Dec 02 '25 19:12 srivats22

I had posted a question: Quick question on this, should _isInitCalled be a local boolean?

I don't see anywhere in the discussion above where you asked that; the only comment since the last review was when you asked about creating a new PR.

You'll need to provide more context for the question, since I'm not sure what you mean. I don't see how a local variable would be relevant to the previous discussion.

stuartmorgan-g avatar Dec 03 '25 14:12 stuartmorgan-g

I had posted a question: Quick question on this, should _isInitCalled be a local boolean?

I don't see anywhere in the discussion above where you asked that; the only comment since the last review was when you asked about creating a new PR.

You'll need to provide more context for the question, since I'm not sure what you mean. I don't see how a local variable would be relevant to the previous discussion. Screenshot 2025-12-03 at 9 48 14 AM Sorry I had accidently put it as a review comment have attached a screenshot of the same

srivats22 avatar Dec 03 '25 14:12 srivats22

@srivats22 yes _isInitCalled should be private and serve a single purpose: detect when init() is called more than once.

mdebbar avatar Dec 03 '25 15:12 mdebbar

How do I fix the build failures?

srivats22 avatar Dec 05 '25 15:12 srivats22