Styles not loaded and 502 errors in NextJS app after app resumes from automatic stop

Hi, when loading my NextJS app after the automatic start/stop has paused the app. The styles of my app do not show up on the initial page load:

and I’m getting the following 502 errors in the console and network tab:

The issue goes away and the styles load as expected after refreshing the page and in subsequent page loads, but issue comes back whenever the app is automatically paused and the page is first loaded again to bring the app out of the paused state.

Please let me know your thoughts on this issue. Thank you very much.

A guess, and a possible workaround. Since the problem clears up (at least temporarily), it might be that your server is taking too long after restart to begin processing requests.

A possible workaround, use Fly Launch configuration (fly.toml) · Fly Docs to avoid these requests making it to your server at all.

Thanks for the quick response.
If the missing styles are tailwind classes would the statics approach still work?

As long as they are persisted on disk (I know tailwind can do this, i haven’t checked how next.js handles tailwind), then… yes, absolutely.

Since all the js and css files that get built in NextJS are in the /static directory, I tried using the following statics configuration in my fly.toml file

[[statics]]
  guest_path = "/app/_next/static"
  url_prefix = "/static"

however I’m still getting the 502 errors:

I tested on a local docker image and page loads and styles show up without the errors.

Still getting 502 errors after updating the statics a few times

Is there something wrong with the paths I’m specifying in the statics?

My app directory looks like this:

And my docker file WORKDIR

Thanks.

If I’m reading your 502 errors correctly, it is _next, not .next in the URLs.

Still getting the same 502 errors after switching URLs to _next.

The issue can be reproduced by checking logs and network when visiting
https://vanish-crm-vq89a.fly.dev/

when the server is automatically paused (usually happens after 10 mins of no site activity)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.