Skip to content
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

[FIX] Uncaught TypeError: Cannot read property 'focus' of null #270

Open
JohnAtFenestra opened this issue May 26, 2016 · 1 comment
Open

Comments

@JohnAtFenestra
Copy link

This is a suggested fix to an error which turned up for me on May 20, 2016. The error was originally documented as #1 Uncaught TypeError: Cannot read property 'focus' of null. I posted this suggested fix as a comment before I realized that the issue had been closed.

I looked over the code and it may be a race condition. The use case scenario would be one where handleFocus is called a second time before @returnFocus is set to null. The final scenario, which is highly unlikely, involves both threads passing the first guard and then thread one switching and setting @returnFocus to null before the second thread assigns to a temp variable. I added a final guard for that possibility as well.

Suggested change:

status-bar.coffee

Original

    handleFocus = =>
      if @returnFocus
        setTimeout =>
            @returnFocus.focus()
            @returnFocus = null
        , 100

Changed

    handleFocus = =>
      if @returnFocus
        setTimeout =>
          if @returnFocus
              tempFocus = @returnFocus
              @returnFocus = null
              tempFocus.focus() if tempFocus
        , 100
fusion809 added a commit to fusion809/terminal-fusion that referenced this issue Jun 14, 2016
@fusion809
Copy link

@JohnAtFenestra Hi, while it seems that Jeremyramin is unlikely to respond to this issue anytime soon as he hasn't been on GitHub for several months now, I have just implemented this fix at my repo. So if you want to use a terminal package with this fix please use it. You can install it by running:

apm install terminal-fusion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants