BUG: onSuccess in useMutationFeedback triggers repeated executions / infinite re-render loop

Abierto Apto para principiantes
#1,729 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 10 días

Nadie ha tomado este issue todavía.

Evaluación

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

Línea de trabajo

Lee frontend/src/hooks/useMutationFeedback.tsx y el uso de useFolderOperations.tsx en la ubicación indicada para entender el comportamiento del callback y del efecto. Comprueba cómo el hook gestiona las notificaciones de error y cómo sus pruebas cubren las transiciones de éxito. La tarea estará terminada cuando el callback de éxito se ejecute y el diálogo se muestre una sola vez por cada transición de éxito, incluso si hay nuevos renderizados o cambia la referencia del callback.

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

Descripción

bug possible-duplicate
Is there an existing issue for this?
  • I have searched the existing issues
What happened?

In frontend/src/hooks/useMutationFeedback.tsx, the success state handler is implemented as:

// Handle success state
useEffect(() => {
  if (isSuccess && showSuccess) {
    dispatch(
      showInfoDialog({
        title: successTitle,
        message: successMessage,
        variant: 'info',
      }),
    );

    if (onSuccess) {
      onSuccess();
    }
  }
}, [
  isSuccess,
  showSuccess,
  successTitle,
  successMessage,
  dispatch,
  onSuccess,
]);
The Problem & Root Cause:
  1. onSuccess is included in the useEffect dependency array.
  2. In typical consumer usage (such as in useFolderOperations.tsx), options containing onSuccess are passed as an inline object:
    useMutationFeedback(
      { ...foldersQuery },
      {
        loadingMessage: 'Loading folders',
        showSuccess: false,
        onSuccess: () => {
          const folders = foldersQuery.data?.data?.folders as FolderDetails[];
          dispatch(setFolders(folders));
        },
      },
    );
    
  3. On every re-render of the component or custom hook, a new inline function reference is created for onSuccess.
  4. TanStack Query retains isSuccess: true for the duration of the query/mutation cache.
  5. Because onSuccess changes reference on every render while isSuccess is still true, useEffect re-executes on every single render:
    • If showSuccess is enabled, dispatch(showInfoDialog(...)) will be dispatched again on every re-render.
    • onSuccess() will be invoked again, which typically dispatches an update to the Redux store or sets local state.
    • That state update triggers another component re-render, creating a new onSuccess function reference, which retriggers useEffect — resulting in an infinite render/dispatch loop or redundant Redux state updates.

Unlike the error handler which uses lastShownErrorMsg to prevent spam, the success handler has no execution guard.

Expected Behavior:
  • onSuccess and showInfoDialog should execute exactly once per success transition (when isSuccess transitions from false to true).
  • Re-renders or reference changes to inline onSuccess functions while isSuccess remains true should not re-trigger onSuccess or re-open the success dialog.
Steps to Reproduce:
  1. Call useMutationFeedback with an inline onSuccess callback that updates state or dispatches to Redux (as seen in useFolderOperations).
  2. Trigger the query or mutation until it succeeds (isSuccess = true).
  3. Observe onSuccess executing repeatedly on every re-render while isSuccess remains true.

Record
  • I agree to follow this project's Code of Conduct
Lenguaje dominante
Python
Estrellas
320
Forks
771
Merge medio
9 d 5 h
PR fusionados (30 d)
15

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 AOSSIE-Org/PictoPy

Todos los issues de AOSSIE-Org/PictoPy

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.