ucsb-cs156-m23 / proj-happycows-m23-10am-4

https://ucsb-cs156-m23.github.io/proj-happycows-m23-10am-4/
0 stars 1 forks source link

FIX: Removed 404 Error Page on Navigation and Reload #61

Closed iain801 closed 1 year ago

iain801 commented 1 year ago

Overview

In this PR, we remove the issue of the 404 Error screen appearing briefly whenever a page is loaded or reloaded. We accomplish this by rendering a blank page until the correct one has been served to the client. This also has a secondary benefit of reducing page loading times, as it removes the initial React Router query (Which resulted in 404).

Screenshots (Optional)

Insert absence of 404 Error

Future Possibilities (Optional)

Some possible points could be:

Validation (Optional)

  1. Deploy this branch on dokku (localhost is too fast to replicate the issue).
  2. Navigate to a page other than root
  3. Reload the page repeatedly and make sure “404” never appears

Tests

Linked Issues

Closes #33

chriscerie commented 1 year ago

We accomplish this by rendering a blank page until the correct one has been served to the client.

The changes don't seem to do that. It tries to hide the issue by delaying loading by 200ms in hopes the currentuser query wins the introduced race condition, which will fail on high latency networks. Instead I suggest solving the root of the issue and use react-query's flags (e.g., isLoading) to determine when to fallback to blank page.

pconrad commented 1 year ago

We accomplish this by rendering a blank page until the correct one has been served to the client.

The changes don't seem to do that. It tries to hide the issue by delaying loading by 200ms in hopes the currentuser query wins the introduced race condition, which will fail on high latency networks. Instead I suggest solving the root of the issue and use react-query's flags (e.g., isLoading) to determine when to fallback to blank page.

I think I agree with @chriscerie here. This does "appear" to fix the problem, but only with a hack that is tailored to very specific network conditions. I think a better solution involves tackling this at the root of the problem, which is to say, at the react-query call, along the lines that @chriscerie suggests. That may mean that there is no "silver bullet" that solves this across the entire app (though some refactoring in https://github.com/ucsb-cs156-m23/proj-happycows-m23-10am-4/blob/main/frontend/src/main/utils/currentUser.js might go a long way towards resolving it.)

It's a great first step though, in terms of investigating and understanding the problem.

chriscerie commented 1 year ago

Just a hint, react-query used in the hook already gives you the necessary states for whether a resource is still fetching. If you use that to determine whether to display 404 or blank page it’ll be a fairly straightforward fix.

iain801 commented 1 year ago

That was something I originally thought, but I tested it on varying latency networks on my dev server with a production build deployment from 0 offset (around 10 ms ping latency) to 10 seconds and never saw the 404 page. I do know the race condition is between the client rendering the page and the currentUser being returned from the backend.

iain801 commented 1 year ago

idk how I never noticed the initialData flag in useCurrentUser

iain801 commented 1 year ago

just kidding, didnt work

iain801 commented 1 year ago

Also, currently we serve the 404 Error when the client doesn't have the correct permissions, however, the HTTP standard has 403 Forbidden for this purpose.

iain801 commented 1 year ago

@phtcon check it out now, thanks @chriscerie for the hint

iain801 commented 1 year ago

@phtcon are deleting all the comments the correct move here?

chriscerie commented 1 year ago

You don’t need a comment to tell you a variable called adminRoutes defines the admin routes. Favor meaningful comments that tell you why the code is there than what the code does.