Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

resource.reload() while params is in error switches the resource to 'idle' instead of retrying

Abierto Apto para principiantes
#71,585 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
angular, typescript
Área
api, backend

Línea de trabajo

Empieza en packages/core/src/resource/resource.ts, especialmente en ResourceImpl.reload() y el cálculo del estado alrededor de las líneas citadas en el issue. Lee las pruebas existentes de resource y añade un caso de regresión para un error de params seguido de reload(). Se considerará terminado cuando reload no indique éxito sin ejecutar el loader y el resource conserve un estado de error coherente.

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

Descripción

area: core
Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

No

Description

When a resource's params function throws (for example a thrown validation error, or mirroring an
upstream resource's error), the resource correctly reports status() === 'error'. Calling reload()
in that state breaks the resource:

  • reload() returns true, but the loader never runs,
  • status() switches from 'error' to 'idle',
  • error() still returns the old error while the status claims 'idle',
  • every subsequent reload() returns false (the 'idle' guard), so a "Retry" button is
    permanently dead.

The cause is in ResourceImpl.reload() (packages/core/src/resource/resource.ts:407):

this.extRequest.update(({request, reload}) => ({request, reload: reload + 1}));

extRequest is a union: after a params error its value is {error, reload}, with no request
field. Destructuring request yields undefined and the rebuilt object drops error, so the state
computation maps request === undefined to 'idle' (resource.ts:320) while reusing the previous —
error — stream (resource.ts:321), which is why error() keeps reporting the stale error.

Expected behavior: reload() should return false and leave the error state untouched when the
error came from params (only a params change can recover it), or alternatively preserve the error
state instead of fabricating 'idle'. Returning true without loading, and reporting 'idle'
while error() is set, are both incoherent.

Minimal reproduction (TestBed spec)

import {ApplicationRef, Injector, resource, signal} from '@angular/core';
import {TestBed} from '@angular/core/testing';

it('reload() while params is in error', async () => {
  const s = signal<string | Error>(new Error('params failed'));
  let loads = 0;
  const res = resource({
    params: () => {
      const v = s();
      if (v instanceof Error) throw v;
      return v;
    },
    loader: async ({params}) => {
      loads++;
      return params;
    },
    injector: TestBed.inject(Injector),
  });
  await TestBed.inject(ApplicationRef).whenStable();

  expect(res.status()).toBe('error'); // ✓

  const result = res.reload();
  await TestBed.inject(ApplicationRef).whenStable();

  console.log(result);        // true  — claims a reload happened
  console.log(res.status());  // 'idle' — was 'error'
  console.log(res.error());   // Error: params failed — still set while 'idle'
  console.log(loads);         // 0     — loader never ran
  console.log(res.reload());  // false — retry permanently dead
});

Observed on main (c27695f278, 22.3.0-next.2); the relevant code is unchanged in 22.x stable.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

Please provide the environment you discovered this bug in (run ng version)

Anything else?

No response

Lenguaje dominante
TypeScript
Estrellas
101k
Forks
30.3k
Merge medio
2 d 5 h
PR fusionados (30 d)
378

Preparar el entorno

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 angular/angular

Todos los issues de angular/angular

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.