AOSSIE-Org / AOSSIE-Org/EduAid

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

Aperta
#599 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
bug
Lingua principale
JavaScript
Stelle
171
Fork
425
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.