AOSSIE-Org / AOSSIE-Org/EduAid

[BUG]: Fix potential crashes and improve state handling in Output component

Abierto
#599 0 comentarios 0 reacciones 0 asignados Ver en GitHub
bug
Lenguaje dominante
JavaScript
Estrellas
171
Forks
425
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

### Bug Description

### 📌 Problem
The Output component had multiple issues related to stability, state handling, and React best practices, which could lead to crashes or inconsistent behavior.

### ⚠️ Issues Identified

1. **Potential Crash (High Priority)**
- Accessing `qaPairsFromStorage["output"]` without checking existence could cause runtime crashes

2. **Incorrect Default State**
- `questionType` could be `null` if not found in localStorage, leading to unexpected behavior

3. **Memory Leak Risk**
- Web Worker was not safely cleaned up in all scenarios

4. **Direct DOM Manipulation**
- Dropdown was handled using direct DOM methods instead of React state

5. **Unsafe localStorage Parsing**
- Default structure from localStorage could lead to type mismatch issues

---

### ✅ Fix Implemented

- Added safety checks before accessing `qaPairsFromStorage["output"]`
- Provided fallback value for `questionType`
- Ensured proper cleanup of Web Worker
- Refactored dropdown logic using `useState` and `useRef`
- Improved handling of parsed localStorage data

---

### 💡 Benefits
- Prevents runtime crashes
- Improves application stability
- Aligns with React best practices
- Safer and more predictable state handling
- Cleaner and more maintainable code

---

### 📍 Affected File
- `eduaid_web/src/pages/Output.jsx`

### Steps to Reproduce

_No response_

### Logs and Screenshots

_No response_

### Environment Details

_No response_

### Impact

Critical - Application is unusable

### Code of Conduct

- [x] I have joined the [Discord server](https://discord.gg/hjUhu33uAn) and will post updates there
- [x] I have searched existing issues to avoid duplicates

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.