tutorbook icon indicating copy to clipboard operation
tutorbook copied to clipboard

Don't revalidate user data when editing

Open nicholaschiang opened this issue 4 years ago • 1 comments
trafficstars

To reproduce issue:

  1. First make sure you're an org admin (add your ID to the org members field in the local Firestore emulator).
  2. Open up http://localhost:3000/users/volunteer/edit.
  3. Make a change but don't click the "update user" button.
  4. Switch tabs or windows.
  5. Refocus the edit user tab and notice how your changes get reset.

If you open up developer tools, you should be able to see an HTTP request that is sent when you refocus the edit user tab. This is because the pages/[org]/users/[id]/edit.tsx page uses SWR which automatically revalidates data when a page regains focus.

Instead, you should disable SWR's automatic revalidation only if the user's data has been changed in the front-end but not yet updated in the back-end (i.e. if the user data has been changed but the "update user" button has yet to be clicked).

You can look for examples of how to implement this pattern in components/calendar/index.tsx which prevents revalidation while there are meetings that have been mutated.

nicholaschiang avatar May 11 '21 22:05 nicholaschiang

Because of #213, this issue will only affect people who try to update their profiles from the org signup page (/[org]/signup) instead of the profile page (/profile). Thus, this is still quite a high priority issue (related: nicholaschiang/hammock#27).

nicholaschiang avatar May 16 '21 03:05 nicholaschiang