Skip to content

Receiving user-entered input  #7745

Closed
Closed

Description

@pfhayes

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.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem
https://jsfiddle.net/k61pvqhk/

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.

Activity

  1. jackmarchant commented on Oct 20, 2016

    @jackmarchant
    Contributor

    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.

  2. pfhayes commented on Oct 20, 2016

    @pfhayes
    Author

    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.

  3. alexeybondarenko commented on Jan 18, 2017

    @alexeybondarenko

    @pfhayes I also think about this behavior. Do you have some solution for now for this case?

  4. gaearon commented on Oct 4, 2017

    @gaearon
    Collaborator

    It seems like more or less the same issue as #4293. Let’s keep the discussion there.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions