-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TextField] Bad behavior when user edits box before hydration with SSR #34174
Comments
I think the solution to this is to lean toward CSS I plan to try this out for Joy UI and wait to see the feedbacks first. |
Doing the placeholder with CSS sounds like it would help the styling issue. But what about the part where hydration blows away the user's edits? Would it be possible to fire an |
My gut feeling is that React should handle this properly. What's the behavior of using pure React HTML input? |
Using a raw I'm a bit confused why nobody else seems to have problems with this issue. It seems like edits during hydration delays should affect any mutable DOM element. Do people just minimize their hydration delays and live with this? I guess the fundamental assumption of hydration is that the pre-hydration DOM exactly matches the server-rendered DOM. The docs have the following line:
|
Maybe @eps1lon could shed some light on this. |
Friendly ping @eps1lon, still hoping to make progress on this. |
I think this is a problem with React inputs in general. I'm re-opening facebook/react#12955 since that's the same underlying issue. |
Actually, I would recommend providing a minimal repro with just using React 18 first. React 18+ can yield during hydration. Typing into de-hydrated inputs might actually defer hydration of said input fields. Or they put heuristics into place that fixes these issues. But it warrants an investigation first. |
Okay, I tried it with React 18 and got the same result I had with React 17. I now have two branches of the original repro I posted: https://github.com/thomasjm/razzle/tree/textfield-ssr-rawinput-react17/examples/with-material-ui FWIW, I got the following suggested solution from StackOverflow. If the issue can't be fixed on a React-wide basis, maybe this solution could be used in |
The repro returns a 404. But I would recommend not using MUI at all to demonstrate the issue with React itself. |
Whoops, forgot to push the React 17 branch. Pushed now. These repros don't use MUI, as you can see here. But you can easily comment the raw |
It's really important that these repros have as little context as possible. Try to reproduce the code to a bare minimum. There shouldn't even be a mention of MUI. |
All right, repros are pretty minimal now. EDIT: oh, I just noticed an interesting warning on React 18. Let me deal with this first...
EDIT 2: okay, now the React 18 branch is using the new |
@eps1lon just checking in, is the above sufficient to reopen the React issue? |
Ideally this is a Codesandbox where the tester can control when hydration happens. Remember, make it as simple as possible for somebody without your context, to understand what the issue is. |
I just played with CodeSandbox a bit and had trouble finding a way to make SSR work, let alone having hydration occur on command. I'd rather not spend forever working through the nuances of CodeSandbox. But I moved the repros into a repo of their own, with clear instructions. It's very easy to try. What do you think? |
Same issue here! Looks like if you start typing inside text inputs before hydration finishes, the value doesn't change till you refocus. Note that you'll still get a change event every time you press a key, and right after it, another event comes with an empty value, which indicates that something is constantly clearing the input onchange. |
I have a similar issue. I think it's reasonable because html is different between client side and server side. |
This issue contains a reduced test case against React 18: facebook/react#26974 |
Duplicates
Latest version
Current behavior 馃槸
I'm using MUI's
TextField
to make a simple SSR login page with a username and password.The problem is when the user is working over a slow network connection, so it takes some time for the Javascript to download and hydrate the page. As a result, they can edit the text box before hydration occurs.
In the picture below, the user has typed "bob" for the username prior to hydration. The helper text remains in place and it looks bad:
There is also a second problem: once hydration does complete, the
TextField
reverts to blank, losing the user's edits, which is not good UX.Expected behavior 馃
The
TextField
should behave in a reasonable way prior to hydration. Reasonable could mean either a) don't allow edits, or b) handle the edits gracefully, with good styling and without losing them upon hydration.Steps to reproduce 馃暪
I am doing my SSR setup with Razzle.js. I made a fork here to showcase this.
localhost:3000
in Chrome. Open the Chrome DevTools, go to the Network tab, and set the speed to "Slow 3G".Context 馃敠
SSR is a popular technique for achieving fast page loads, and
TextField
should work gracefully with it.Your environment 馃寧
npx @mui/envinfo
The text was updated successfully, but these errors were encountered: