Skip to content

fix(launch): skip script concatenation for projects with esm scripts#2145

Closed
kpal81xd wants to merge 1 commit into
mainfrom
fix-concatenate-scripts-mjs
Closed

fix(launch): skip script concatenation for projects with esm scripts#2145
kpal81xd wants to merge 1 commit into
mainfrom
fix-concatenate-scripts-mjs

Conversation

@kpal81xd

@kpal81xd kpal81xd commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Problem

Launching with Concatenate Scripts (Classic) enabled (concatenateScripts=true) hangs the launcher — it never finishes loading — for any project that contains ESM (.mjs) scripts.

Script concatenation is a classic-scripts-only backend feature. When the project also has ESM scripts, the /api/projects/:id/concatenated-scripts/scripts.js endpoint times out:

Failed to load resource: the server responded with a status of 504 ()
Script: .../concatenated-scripts/scripts.js?branchId=... failed to load

Every preloaded classic script points at that URL, so the engine's preload blocks on the failing request and the loading screen stalls until the gateway times out.

Fix

Guard concatenateScripts=true at its single source (launchApp in viewport-launch.ts): don't request concatenation when the project contains any ESM script. Evaluated fresh on each launch, so it tracks scripts added/removed mid-session, and the && short-circuits so the asset scan only runs when the option is checked.

Notes / trade-offs

  • Mixed classic+ESM projects lose classic-script concatenation entirely — forced by the backend, which 504s on the whole bundle when any ESM script is present.
  • A hand-typed ?concatenateScripts=true URL still bypasses this; the launcher can't reliably detect ESM before it routes assets. The real cure there is the backend not 504-ing.

Testing

  • eslint clean on the changed file; typecheck introduces no new errors (pre-existing baseline unchanged).
  • Not exercised end-to-end (requires a project with ESM scripts against the live launch backend).

Concatenation is a classic-scripts-only backend feature. Enabling it for a
project that contains esm (.mjs) scripts makes the concatenated-scripts
endpoint time out (504), so the engine preload blocks on the request and the
launcher never finishes loading.

Guard concatenateScripts=true at its only source so it is not requested when
the project has any esm script.
@vercel

vercel Bot commented Jul 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
editor Ready Ready Preview, Comment Jul 9, 2026 1:25pm

Request Review

@kpal81xd

kpal81xd commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Closing: investigation of the backend (monorepo) shows the concatenation service already excludes ESM (.mjs) and concatenates classic .js scripts only — this has been the deployed behavior since #2537 (2024-10-01). So disabling concatenation client-side for any project containing ESM scripts is over-broad: it removes a working optimization for the classic scripts in mixed projects, and doesn't address the actual cause of the 504 (the launch concatenated-scripts/scripts.js endpoint blocks the HTTP request on an on-demand generation job with no timeout, so a cold-cache miss can trip the gateway timeout). Fixing this properly on the backend instead.

@kpal81xd kpal81xd closed this Jul 9, 2026
@kpal81xd kpal81xd deleted the fix-concatenate-scripts-mjs branch July 9, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant