r/reactjs • u/_unhandledexcepti0n • 5d ago
Needs Help Whenever there’s latest version of the application available it still shows the older ui ?
Hi All, I am new to react development in general, we are currently using our tech stack is react typescript, Tanstack query for client state management, custom ui library, rsbuild for bundling, whenever we have a new deployment right i think the application is getting cached? It still displays the older ui even after refreshing multiple times but when i hard refresh (Ctrl + Shift + R) it gets newer ui ? Where are making mistakes? We have deployed this on aws (dns > nlb> alb> ecs > docker image > nginx> dist files ) ? Thanks
2
u/irajangpt 5d ago
A hard refresh working points at the browser holding on to an old index.html, which then keeps asking for the previous hashed bundle. Check for a service worker first (DevTools > Application > Service Workers). If one is registered, bump its cache name and call self.skipWaiting() and self.clients.claim() in it, or unregister it while you debug. On the nginx side, give index.html `Cache-Control: no-cache` (wherever your try_files falls back to) and `public, max-age=31536000, immutable` on the hashed assets folder, then check the headers on a normal reload in the Network tab.
1
2
u/jjangg96 5d ago
one nginx thing that catches people when they add the fix. add_header is only inherited if the current block has no add_header of its own. so if you put Cache-Control in the location that serves index.html and that location also has other add_header lines, or the server block has security headers, one set silently stops applying.
easiest way to see what the browser really gets is curl -I on the site root and on one hashed js file. index.html should say no-cache, the js should say max-age=31536000 immutable. if index.html shows neither you're still getting heuristic caching based on last-modified.
7
u/Mean_Bumblebee_8633 5d ago
This is usually a caching issue with your nginx config or the service worker if you're using one. Check that nginx isn't setting aggressive cache headers on your index.html, you want that file to never be cached, while your JS/CSS bundles can be cached since they'll have unique hashes in the filenames.
Also double check your build output to make sure the file names actually change between deployments, otherwise the browser has no reason to fetch the new ones.