AOSSIE-Org / AOSSIE-Org/EduAid

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

Open
#599 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
171
Forks
425
PR merge metrics
No merged PRs in 30d

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.