You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do you want to request a feature or report a bug?
Feature
What is the current behavior?
When serving controlled inputs serverside from ReactDOM, the user might have entered data already before the clientside React has executed. In this case, the data the user has entered gets overwritten by the initial value.
What is the expected behavior?
What mechanisms are available (or should be available) to capture this input? One natural solution I can imagine is some way to capture the user's entered text in getInitialState (or componentWillMount). We could hack this together by manually plucking the content from the DOM, but I'm interested to know if there is a more React-y solution if possible. The default of discarding the user's input is unlikely to be what is desired, for both the developer and the user.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
I have not observed this working in previous versions of React. I see this in Chrome on Mac OS X with React 15.
Could the solution be for the server to provide an initial state for the client side JavaScript to use for its initial render?
This is a common pattern for server/client react applications where you want the client to "pick up" from the state the server knows about.
For example, you could load the user value into an object in a script tag on the server, then load it into your component via props to set the initial state.
The problem here is not with the initial state - it's with picking up user input that the user has entered between the HTML being downloaded and between React initializing on the clientside. If we initialize a textbox to be empty, but then the user types something into the textbox before React initializes clientside, then their input will be wiped.
Activity
jackmarchant commentedon Oct 20, 2016
Could the solution be for the server to provide an initial state for the client side JavaScript to use for its initial render?
This is a common pattern for server/client react applications where you want the client to "pick up" from the state the server knows about.
For example, you could load the user value into an object in a script tag on the server, then load it into your component via props to set the initial state.
pfhayes commentedon Oct 20, 2016
The problem here is not with the initial state - it's with picking up user input that the user has entered between the HTML being downloaded and between React initializing on the clientside. If we initialize a textbox to be empty, but then the user types something into the textbox before React initializes clientside, then their input will be wiped.
alexeybondarenko commentedon Jan 18, 2017
@pfhayes I also think about this behavior. Do you have some solution for now for this case?
gaearon commentedon Oct 4, 2017
It seems like more or less the same issue as #4293. Let’s keep the discussion there.