Configuring Remix server to fallback to previous build on manifest failure
0 reputation · 04 Aug 2021, 10:49 UTC
0 reputation · 04 Aug 2021, 10:49 UTC
The goal is to allow a Remix @remix-run/node server to automatically serve the last known good build when a newly deployed build fails to produce a valid remix-manifest.json. Currently the server starts with whatever manifest is present; if the manifest is missing or malformed it throws an error and the application stops responding unless the process is restarted with a good build. Some hosting platforms provide atomic rollback by keeping immutable builds, but this behavior is not guaranteed across all deployment targets.
Constraints include the absence of built‑in health‑check or auto‑rollback logic in Remix, the risk of serving mixed assets if a partially written build is used, and the reliance on external tooling to preserve old build folders. It is unclear whether a configurable fallbackToPreviousBuild flag should be added, what manifest validation steps are required before triggering a fallback, and how the server should log or report the fallback event to operators.
34775 reputation · 04 Aug 2021, 21:32 UTC
Remix does not provide a built-in fallbackToPreviousBuild option. The standard @remix-run/node server adapters read build/remix-manifest.json at startup and throw if it is missing or malformed. To serve the last known good build automatically, you must use a custom server entry that wraps manifest loading, validates the result, and falls back to an archived build directory before the server starts listening.
Confirmed: There is no configuration flag, environment variable, or adapter setting in Remix that triggers an automatic rollback to a previous build. The server runtime expects a valid manifest at boot time.
Assumed: Your deployment pipeline can preserve the prior build output (for example, by copying build/ to build-previous/ before replacing it). Without an archived target, a fallback is impossible. Also assumed is that you are using a custom server with createRequestHandler rather than a managed platform adapter that abstracts the server entry.
Preserve the previous build. In your deploy script, copy the current build/ directory to a stable path such as build-previous/ before the new build is written. This is external to Remix.
Validate the manifest before listening. In your custom server, attempt to read and parse build/remix-manifest.json. Perform minimal structural validation: confirm it is valid JSON and contains expected top-level keys such as entry, routes, and assets. Do not validate against an exact internal schema version, because the manifest shape is not a stable public API and can change between Remix majors.
Fall back on failure. If parsing or structural validation fails, load the manifest and build assets from build-previous/ instead. Instantiate the request handler from that directory.
Bind the port only after the handler is ready. If the process binds to a port before the manifest is validated, a platform health check may route traffic to a broken instance. Validate first, then call listen.
Emit a structured log line when a fallback occurs, including the active build identifier (for example, a commit SHA or timestamp embedded in the build) and the reason (for example, manifest_parse_error or missing_keys). Keep HTTP error bodies generic; do not return filesystem paths, internal directory names, or stack traces to clients. Pair the log with a metric or alert so that stale serving is visible to operators rather than silent.
build/remix-manifest.json in a staging environment and confirm the server starts from build-previous/ instead of crashing.Does your deployment target replace the build directory atomically, or does it copy files in place? If it is not atomic, a partially written build can produce a manifest that parses but references missing assets, so the validation step should also spot-check that referenced files exist before accepting the new build.
Because Remix internals can evolve, re-verify the validation keys and fallback behavior against your specific Remix version before relying on this in production.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 04 Aug 2021, 20:02 UTC
While implementing a fallback for a malformed remix-manifest.json prevents a total server crash, it introduces a critical risk of asset mismatch. In Remix, the manifest maps specific route IDs to hashed JS and CSS filenames. If the server falls back to a previous manifest but the public build directory has already been updated with new assets, the server will attempt to serve hashes that no longer exist on disk, resulting in widespread 404s for client-side bundles.
To avoid this, a fallback mechanism must be coupled with a directory-level rollback. For those using @remix-run/node, consider these verification steps:
/current symlink only after the manifest is validated.JSON.parse() check combined with a verification that the routes object is not empty is generally sufficient to detect a corrupted build before the server initializes./public/build folder.