Repository navigation
Vite + React page not responding after reopening browser #19423
Replies: 1 comment
|
This sounds like it could be an issue with how authentication state is restored when the browser session is reopened, but I'd investigate the frontend before assuming Django is responsible. A few things I'd check:
Make sure the application waits for authentication state to be restored before rendering protected routes or making authenticated requests. For example, maintain an explicit loading state: const [user, setUser] = useState(null); Only render the protected application after authentication initialization has completed.
You mentioned checking whether the user is defined after three seconds. If you're using "setInterval" or "setTimeout" inside a React component, make sure timers are not being created repeatedly without cleanup. useEffect(() => { return () => clearTimeout(timer);
After reopening the browser, check for:
Also check the Network tab to see whether requests are being sent at all.
A page that becomes completely unresponsive may have a synchronous JavaScript loop or another operation blocking the main thread. This would explain why even frontend interactions stop working. A few questions that would help narrow it down:
I'd start by investigating the authentication initialization and timer logic. If you can share the relevant React authentication code, it will be much easier to identify the actual cause. |
Uh oh!
There was an error while loading. Please reload this page.
I've made my authentication in a way that when tge user isn't defined then it opens the login page and after 3 seconds it checjs if the user is still defined. Everything is working fine but the problem is when I'm logged in then i close my browser once i reopen it and restore the pages or even putin the url of my project server then it will open that last page i was on but it won't be responding which is leading to the whole browser not responding at all uo to the point that it closes itself.
I'm using django as my backend I've checked my server to see if there is any request coming and found out there is nothing going to the backend. Thought of something then changed the html texts then it changed on that frozen (not responsive) page...
In short editing the code of the page is being successful but the page won't send any requests to the backend after i reopen it when i closed the browser while logged in
Someone please help
All reactions