`lazyRouteComponent` shares a pending import across requests on the server: on Cloudflare Workers one cancelled request breaks the route for the isolate

Abierto
#8,950 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@gentil93 ya está trabajando en esto.

Desde el 19/11/2026.

  • #8966 de @gentil93 — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
72/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
react, typescript

Línea de trabajo

Start with packages/react-router/src/lazyRouteComponent.tsx, especially the server and client paths around loadPromise; the issue includes a reproduction and a proposed server-side fix. Run the reproducer in the linked repository, then verify that cancelling an import request no longer makes later requests for the same route fail, while the existing client behavior remains intact.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Which project does this relate to?

Router

Describe the bug

On Cloudflare Workers a promise only settles in the request that created it (handle_cross_request_promise_resolution, default since 2024-10-14). On the server, lazyRouteComponent keeps loadPromise for later requests (by design, "SSR can reuse the import"):

https://github.com/TanStack/router/blob/6b9fe6d29552270836c511bc9b343d73541f4424/packages/react-router/src/lazyRouteComponent.tsx#L25-L50

If the request that started the import is cancelled before it settles, loadPromise never settles and is never cleared. Every later SSR of that route fails ("Something went wrong!", 500) until the isolate is recycled; other routes keep working.

Reproduction: in 20/20 runs, every later /about answers 500 while / stays 200; with the diff below, 0/20.

Suggested fix, server branch only (keep the component, not the promise):

   const load = () => {
+    if (isServer ?? typeof window === 'undefined') {
+      if (comp) {
+        return Promise.resolve()
+      }
+      error = undefined
+      return importer()
+        .then((res) => {
+          comp ??= res[exportName ?? 'default']
+        })
+        .catch((err) => {
+          error = err
+        })
+    }
     if (!loadPromise) {
Complete minimal reproducer

https://github.com/LlamaLtda/workers-lazy-import-cross-request-repro/tree/main/tanstack-router

Steps to Reproduce the Bug
  1. cd tanstack-router && npm install && npm run repro
  2. The script starts wrangler dev with the app (router SSR in a plain Worker, /about uses lazyRouteComponent) and a second Worker that calls it through a service binding.
  3. It requests /, then requests /about and aborts that call while the component import is pending (the importer waits 200 ms before import() to make the window deterministic). Aborting a service-binding call cancels the callee's request, as Cloudflare does when a visitor leaves.
  4. It requests /about and / five more times and prints the statuses. npm run repro -- --fixed applies the diff above.

Also reproduced inside a default TanStack Start app, where autoCodeSplitting wraps every route component in lazyRouteComponent on the server (tanstack-start/, --mode route-component): 20/20, and 0/20 with the diff above.

Expected behavior

Cancelling one request affects only that request: later /about requests answer 200. Instead they answer 500 with Error: This promise was created by a request that has since ended, so it can never settle. serialized in the page.

Platform
  • Router / Start Version: @tanstack/react-router 1.170.46 (latest), router-core 1.171.39; Start case: @tanstack/react-start 1.169.5
  • OS: Linux x64
  • Browser: n/a (server-side)
  • Bundler: wrangler 4.164.0 (esbuild) for the Router case; vite 8.3.8 + @cloudflare/vite-plugin 1.70.0 for the Start case
  • Runtime: workerd via wrangler dev, compatibility_date 2026-11-01
Additional context
  • router-core's loadRouteChunk keeps route._lazy the same way (load-client.ts L80-L105); not exercised here (.lazy() routes).
  • Start has the same pattern in getEntries and the manifest caches: TanStack/router#8951. Also h3 (h3js/h3#1661), Nitro (nitrojs/nitro#5153), and Astro (withastro/astro#18764, fixed).

AI disclosure: this report was written and filed by an AI agent (Claude Code) acting for the owner of this account, on the project where the bug was hit in production. The agent built and ran the reproduction; the raw outputs are in the repo's results/ folder.

Lenguaje dominante
TypeScript
Estrellas
15.3k
Forks
1.9k
Merge medio
1 d 5 h
PR fusionados (30 d)
46

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de TanStack/router

Todos los issues de TanStack/router

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.