Skip to content

Grayed out menu items, "Cannot read property 'toLowerCase' of undefined" #6313

Closed

Description

@cheshire137

Description

I opened the dev tools and saw a JavaScript error repeated several times:

image

Version

  • GitHub Desktop:

1.5.1-beta0

screen shot 2018-11-29 at 1 42 29 pm

screen shot 2018-11-29 at 1 43 27 pm

screen shot 2018-11-29 at 1 43 37 pm

screen shot 2018-11-29 at 1 43 50 pm

  • Operating system:

macOS High Sierra 10.13.6

Steps to Reproduce

I'm not sure. I have been using the app all day with no troubles. I pushed up a branch and hit Cmd-R in the app to open the 'new pull request' page for the branch in my browser, and noticed no such page opened. I tried it a few more times, no luck. That's when I went to the menu and saw the option was grayed out, along with many other options.

Expected Behavior

Menu options would work and not be grayed out.

Actual Behavior

Many menu options are grayed out, including "About GitHub Desktop" which seems like it should always work.

Activity

  1. iAmWillShepherd commented on Nov 29, 2018

    @iAmWillShepherd
    Contributor

    What happens if you restart the app? Is that state persisted?

  2. added
    investigation-needed
    on Nov 30, 2018
  3. cheshire137 commented on Nov 30, 2018

    @cheshire137
    ContributorAuthor

    Nope, exiting and reopening the app made it work normally again!

  4. shiftkey commented on Dec 17, 2018

    @shiftkey
    Member

    Looking at the stack trace, it seems like this is the problem code:

    function userWithLowerCase(user: IGitHubUser): IGitHubUser {
      return {
        ...user,
        email: user.email.toLowerCase(),
        login: user.login.toLowerCase(),
      }
    }
    

    The stack trace itself refers to line 518, which is the end of the function - but I think that's it's own confused way of saying the second case is undefined (based on my attempts to breakpoint here):

    Maybe we have some cached users which don't have a login defined that we then try to cache. @cheshire137 was this occurring with a GitHub repository?

  5. cheshire137 commented on Dec 17, 2018

    @cheshire137
    ContributorAuthor

    was this occurring with a GitHub repository?

    It was!

  6. cheshire137 commented on Feb 25, 2019

    @cheshire137
    ContributorAuthor

    This happens to me periodically. Exiting and relaunching the app fixes it. Here's some recent JS console output when it occurred (version 1.6.3-beta2):

    image

  7. added
    bug
    on Feb 25, 2019
  8. added
    priority-2
    and removed
    investigation-needed
    on Feb 25, 2019
  9. self-assigned this
    on Feb 25, 2019
  10. shiftkey commented on Feb 25, 2019

    @shiftkey
    Member

    Marking as priority-2 because of the impact (menus not working). The presence of undefined makes me think something at runtime is violating the type checks we have setup in this area.

  11. shiftkey commented on Feb 25, 2019

    @shiftkey
    Member

    Thanks to @cheshire137 who helped test the build from #6940 and uncovered the problem commit involved with this.

    I'll spare the person responsible who created the commit from being named, but this is the API response that GitHub returns to the app for this comment:

      ...
      "commit": {
        "author": {
          "name": "[redacted]",
          "email": "",
          "date": "2018-12-06T20:33:38Z"
        },
        "committer": {
          "name": "[redacted]",
          "email": "",
          "date": "2018-12-06T20:33:38Z"
        },
        ... 
      "author": {},
      "committer": {},
      ...
    

    Because author is an empty object here (rather than null) this code path is tripped an object with an undefined name and login, and an empty email is returned:

    if (apiCommit && apiCommit.author) {
    const avatarURL = getAvatarWithEnterpriseFallback(
    apiCommit.author.avatar_url,
    email,
    account.endpoint
    )
    return {
    email,
    avatarURL,
    login: apiCommit.author.login,
    endpoint: account.endpoint,
    name: apiCommit.author.name || apiCommit.author.login,
    }
    }

    We can relax the type declarations coming from the API to reflect this newly-discovered anarchy:

    diff --git a/app/src/lib/api.ts b/app/src/lib/api.ts
    index 1f055b9e7..aa4ca569c 100644
    --- a/app/src/lib/api.ts
    +++ b/app/src/lib/api.ts
    @@ -57,7 +57,7 @@ export interface IAPIRepository {
      */
     export interface IAPICommit {
       readonly sha: string
    -  readonly author: IAPIUser | null
    +  readonly author: IAPIUser | {} | null
     }
     
     /**

    And this highlights the code we need to update to properly handle this case.

  12. shiftkey commented on Feb 26, 2019

    @shiftkey
    Member

    After talking a bit more about this with @cheshire137 I wanted to clarify where my head is at:

    My next steps are to try and trigger this problem state myself

  13. added
    priority-3
    and removed
    priority-2
    on Feb 26, 2019
  14. shiftkey commented on Feb 26, 2019

    @shiftkey
    Member

    Dropping this down to priority-3 unless I can get an easy, consistent reproduction of the disabled menus state.

  15. shiftkey commented on Mar 6, 2019

    @shiftkey
    Member

    Alright, I've got what I believe is one reproduction of this issue:

    • run the app up in development mode (this will help later on)
    • have multiple repositories open in the app
    • for the first repository, trigger merge conflicts and see the dialog
    • dismiss the dialog, confirm the menus are working
    • switch to a different repository
    • restart the app
    • switch over to the Dev Tools, open the React tab, and wait

    You want to keep an eye on the currentPopup root state - initially this is null :

    A couple of minutes after launching this will change to an object:

    29 is the enum code for MergeConflicts, and those branches are the ones associated with the earlier merge.

    And despite there not being a popup you'll see some of the menu items are disabled:

    What happened? My guess:

    • background fetching kicked in
    • AppStore.withPushPullFetch runs on the conflicted repository
    • ... which calls AppStore._refreshRepository
    • ... which calls AppStore.loadStatus
    • ... which calls AppStore._triggerConflictsFlow
    • which sees the merge conflict and tries to AppStore.showMergeConflictsDialog despite not being the selected repository.
    • menu-update gets stuck in this code path and assumes all the menu items should be disabled

    if (state.currentPopup) {
    return getAllMenusDisabledBuilder().state
    }

  16. shiftkey commented on Apr 1, 2019

    @shiftkey
    Member

    We published 1.7.0-beta1 last week which I believe addresses these two identified issues, so for the moment I'm going to close this out as resolved pending it being available in production. If you spot something that you believe might be related to this, please open a fresh issue rather than add to the existing discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugpriority-3

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions