Skip to content

dev: first request 503s with Vite environment "ssr" is unavailable on cold start #4295

Closed

Description

@glekner

On a fresh vite dev, the very first page load occasionally fails with a 503 before the SSR environment is ready:

HTTPError: Vite environment "ssr" is unavailable
  at httpError (.../nitro/dist/runtime/internal/vite/dev-worker.mjs:208)
  at ViteEnvRunner.fetch (.../dev-worker.mjs:77)

Reloading the page always fixes it.

Cause

ViteEnvRunner.fetch waits for the SSR entry import to resolve, but only retries 5 times with exponential backoff:

for (let i = 0; i < 5 && !(this.entry || this.entryError); i++) {
  await new Promise((r) => setTimeout(r, 100 * Math.pow(2, i)));
}
if (!this.entry) {
  throw httpError(503, `Vite environment "${this.name}" is unavailable`);
}

That caps the wait at 100+200+400+800+1600 = ~3.1s. On a larger app the first cold import of the SSR entry takes longer than that, so the initial request gives up and 503s. A reload succeeds because the import has finished by then, which makes it look intermittent.

Reproduction

  • nitro 3.0.260522-beta, Vite 8, TanStack Start (preset vercel)
  • Start the dev server and hit / immediately, before the SSR module graph finishes transforming.

Possible fix

Poll on a short fixed interval with a higher ceiling instead of bailing after ~3s. It still exits the moment the entry resolves, so the common (warm) case stays fast, but a slow cold start no longer 503s:

for (let i = 0; i < 600 && !(this.entry || this.entryError); i++) {
  await new Promise((r) => setTimeout(r, 50));
}

I've been running this patch locally and it reliably removes the first-load 503. Happy to open a PR if the approach looks right.

Activity

  1. added
    tanstack
    on Sep 2, 2026
  2. pi0x commented on Sep 7, 2026

    @pi0x
    Contributor

    Fixed on main. The dev server used to give up after about 3 seconds while the SSR entry was still doing its first import and return a 503; it now waits for that import to actually finish. Fixed in 7536de7 (#4541), released in v3.0.260903-beta.

    Posted by an AI triage agent on behalf of a maintainer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    tanstack

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions