Profile settings form stays stale after user data loads #2477
Replies: 2 comments
|
The root cause is in const form = useForm<FormData>({
resolver: zodResolver(formSchema),
defaultValues: {
full_name: currentUser?.full_name ?? "",
email: currentUser?.email ?? "",
},
})
Two fixes, both fine with the versions this repo pins ( A. Reset when the user changes (what you proposed): useEffect(() => {
form.reset({
full_name: currentUser?.full_name ?? "",
email: currentUser?.email ?? "",
})
}, [currentUser, form])B. Let the form track the value with const form = useForm<FormData>({
resolver: zodResolver(formSchema),
defaultValues: { full_name: "", email: "" },
values: {
full_name: currentUser?.full_name ?? "",
email: currentUser?.email ?? "",
},
})The difference worth deciding on: Worth noting for the PR: this repository asks that PRs only be opened when a maintainer requests one (see |
|
Thanks for the detailed explanation, @artur282. That makes the root cause much clearer. I agree that Option A ( I also appreciate the clarification about the repository’s contribution policy and the maintainer-request requirement. I’ll keep that in mind rather than opening another PR unless a maintainer asks for one. Thanks again for taking the time to explain both the issue and the trade-offs between the approaches. |
Uh oh!
There was an error while loading. Please reload this page.
Profile form does not synchronize after the current user loads
Description
The settings profile form initializes its default values from
currentUser. The user query loads asynchronously, so the form can remain empty after the user data arrives. After a profile update, the form can also continue displaying stale values until the page is reloaded.Reproduction
Expected behavior
The profile form should populate when the current user data becomes available and reset to the saved values after a successful update.
Proposed fix
Reset the form when
currentUserchanges, for example with a React effect that callsform.reset()using the current user's name and email. I prepared this change in my fork, but I will wait for maintainer guidance before opening another pull request.Related closed PR: #2476
All reactions