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: form data is lost upon hydration #26974

Closed
OliverJAsh opened this issue Jun 19, 2023 · 7 comments
Closed

Bug: form data is lost upon hydration #26974

OliverJAsh opened this issue Jun 19, 2023 · 7 comments
Labels
Resolution: Stale Automatically closed due to inactivity Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@OliverJAsh
Copy link

Related:

React version: 18.2.0

Steps To Reproduce

Link to code example: https://github.com/OliverJAsh/react-controlled-form-hydration-issue

Given this component which is used during SSR and then hydrated on the client-side:

import * as React from 'react';

export const App = () => {
  const [value, setValue] = React.useState('');

  const [, setCount] = React.useState(0);

  React.useEffect(() => {
    console.log('mount');

    setCount(1);
  }, []);

  return (
    <form>
      <div>Value: {value}</div>
      <input
        type="text"
        value={value}
        onChange={(e) => setValue(e.currentTarget.value)}
      />
    </form>
  );
};
  1. Before hydration, enter text into the input.

The current behavior

After hydration, the input's value is set back to the initial state. The text entered by the user prior to hydration is lost.

Screen.Recording.2023-06-19.at.12.33.28.mov

The expected behavior

The text entered by the user prior to hydration should be preserved.

@OliverJAsh OliverJAsh added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Jun 19, 2023
@nusr
Copy link

nusr commented Jun 26, 2023

After the page is loaded, enter the text after 3 seconds, and the content will not be lost.
Or remove the setTimeout, and the content directly entered will not be lost.
image

@EnshaednHiker
Copy link

Is the setTimeout just to demonstrate the issue? Another way to test this issue is to throttle CPU and network speed in devtools, and then that setTimoueout is most likely not necessary. Fast 3G and 4x CPU slowdown might be something to try to start. The location of these tools recently changed in chrome, so for others following along, here's where they are today:
image

@OliverJAsh
Copy link
Author

Yeah the timeout is to simulate delayed hydration e.g. due to slow JS.

Copy link

github-actions bot commented Apr 9, 2024

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

@github-actions github-actions bot added the Resolution: Stale Automatically closed due to inactivity label Apr 9, 2024
@OliverJAsh
Copy link
Author

Bump

@github-actions github-actions bot removed the Resolution: Stale Automatically closed due to inactivity label Apr 10, 2024
Copy link

github-actions bot commented Jul 9, 2024

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

@github-actions github-actions bot added the Resolution: Stale Automatically closed due to inactivity label Jul 9, 2024
Copy link

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Stale Automatically closed due to inactivity Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

3 participants