AOSSIE-Org / AOSSIE-Org/EduAid

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

Ouverte
#599 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
bug
Langage dominant
JavaScript
Étoiles
171
Forks
425
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

### 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

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.