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

Bug: don't invoke this.focusInput in mousetrap callback #1157

Merged
merged 3 commits into from
May 1, 2022

Conversation

DAlperin
Copy link
Contributor

When calling this.focusInput() in the moustrap callback it is possible for this.commandPaletteInput.input (as used in this.focusInput()) to be null since this.commandPaletteInput is set during the render which is not guaranteed to happen first. This creates a race condition that can lead to an error being logged on the console in some cases.

this.focusInput() is still called by afterOpenModal and thus the desired effect is preserved.

I have published a package published that just bumps to react 18 and fixes this bug if you want to test out the changes really quickly. https://www.npmjs.com/package/react18-react-command-palette

Thank you for the awesome package. It saved me a ton of time and allowed me to put together a what would otherwise be complicated feature with extreme ease!

When calling this.focusInput() in the moustrap callback it is possible for this.commandPaletteInput.input to be null since this.commandPaletteInput is set during the render which is not guaranteed to happen first. This creates a race condition that can lead to an error being logged on the console in some cases.

this.focusInput() is still called by afterOpenModal and thus the desired effect is acheived.
@asabaylus asabaylus self-assigned this Apr 23, 2022
@asabaylus asabaylus added the bug label Apr 23, 2022
@asabaylus asabaylus added this to In progress in Roadmap v1.0 via automation Apr 23, 2022
@asabaylus asabaylus added the minor Increment the minor version when merged label May 1, 2022
@asabaylus asabaylus changed the title Don't invoke this.focusInput in moustrap callback Bug: don't invoke this.focusInput in mousetrap callback May 1, 2022
@codecov
Copy link

codecov bot commented May 1, 2022

Codecov Report

Merging #1157 (a886842) into main (928c917) will not change coverage.
The diff coverage is n/a.

@@            Coverage Diff            @@
##              main     #1157   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            7         7           
  Lines          219       218    -1     
  Branches        35        35           
=========================================
- Hits           219       218    -1     
Impacted Files Coverage Δ
src/command-palette.js 100.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 928c917...a886842. Read the comment docs.

@asabaylus
Copy link
Owner

@DAlperin thanks so much!

@asabaylus asabaylus merged commit 8509d11 into asabaylus:main May 1, 2022
Roadmap v1.0 automation moved this from In progress to Done May 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug minor Increment the minor version when merged
Projects
Roadmap v1.0
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants