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

Bugfix/prevent loss of reference #254

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

MtthsB
Copy link

@MtthsB MtthsB commented Mar 31, 2021

This merge request is intended to fix an insidious bug caused by a loss of reference to the input DOM element under certain circumstances.
In concreto, when the input loses focus, i.e. on blur, in response to an action which causes a re-render of the component, the input (momentarily) loses its reference: the re-render causes the ref function invoked by React.createElement to re-initialise, passing a null object on first render. At the moment, this causes both the inputRef and the forwardedRef to be set to null.

In between the first render and the second invocation of the React.createElement ref function, onBlur (and the useValue function) is called on a null inputRef, causing a crash.

A simple fix is checking for the existence of the reference returned by the ref callback.

ianchanning pushed a commit to mona-health/react-input-mask that referenced this pull request Feb 22, 2023
See sanniassin#254 - I just
didn't like the coding style
@ianchanning
Copy link

@MtthsB good catch - I've added this to my fork.

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

Successfully merging this pull request may close these issues.

2 participants