AOSSIE-Org / AOSSIE-Org/EduAid

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

Offen
#599 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
bug
Vorherrschende Sprache
JavaScript
Sterne
171
Forks
425
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.