Skip to content

fix: harden state handling and stabilize gradient rendering in Electron#622

Open
ashi2004 wants to merge 3 commits intoAOSSIE-Org:mainfrom
ashi2004:feature/electron-gradient-output-stability
Open

fix: harden state handling and stabilize gradient rendering in Electron#622
ashi2004 wants to merge 3 commits intoAOSSIE-Org:mainfrom
ashi2004:feature/electron-gradient-output-stability

Conversation

@ashi2004
Copy link

@ashi2004 ashi2004 commented Mar 23, 2026

Addressed Issues:

Fixes #621

This PR tightens Output page behavior and fixes gradient text rendering inconsistencies seen in Electron.

What I changed

  • Reworked gradient text styling to a stable utility pattern used across headings
  • Replaced DOM-driven PDF dropdown toggling with controlled React state plus ref-based outside-click handlingg
  • Added safer state paths around Output data flow to reduce edge-case breakage
  • Improved PDF worker flow so dropdown state and worker cleanup are handled more predictably

Why

  • Electron fullscreen and Chromium-specific cases were rendering gradients inconsistently.
  • Dropdown behavior was bad due to direct DOM class manipulation.
  • Output flow had avoidable failure paths when state/data became inconsistent.

Additional Notes:

AI Usage Disclosure:

We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact. AI slop is strongly discouraged and may lead to banning and blocking. Do not spam our repos with AI slop.

Check one of the checkboxes below:

  • This PR does not contain AI-generated code at all.
  • This PR contains AI-generated code. I have read the AI Usage Policy and this PR complies with this policy. I have tested the code locally and I am responsible for it.

Checklist

  • My PR addresses a single issue, fixes a single bug or makes a single improvement.
  • My code follows the project's code style and conventions
  • If applicable, I have made corresponding changes or additions to the documentation
  • If applicable, I have made corresponding changes or additions to tests
  • My changes generate no new warnings or errors
  • I have joined the Discord server and I will share a link to this PR with the project maintainers there
  • I have read the Contribution Guidelines
  • Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.
  • I have filled this PR template completely and carefully, and I understand that my PR may be closed without review otherwise.

Summary by CodeRabbit

Release Notes

  • Style

    • Enhanced gradient text styling effects throughout the interface for improved visual presentation
    • Updated home page heading with new visual design and styling
    • Refined PDF dropdown menu interaction in the output page
  • Chores

    • Applied rendering optimization improvements to the desktop application

@coderabbitai
Copy link

coderabbitai bot commented Mar 23, 2026

📝 Walkthrough

Walkthrough

These changes address gradient rendering inconsistencies and component stability. The desktop app disables GPU hardware acceleration to resolve rendering issues. The web UI refactors gradient styling into dedicated CSS classes and converts the Output component's dropdown management from direct DOM manipulation to React state-based control.

Changes

Cohort / File(s) Summary
Hardware Acceleration
eduaid_desktop/main.js
Disabled GPU/hardware acceleration in Electron app initialization to improve gradient rendering consistency across environments.
Gradient Styling
eduaid_web/src/index.css
Added .gradient-text-base, .gradient-text, and .gradient-text-2 CSS classes for consistent gradient text rendering with proper background clipping and transforms.
Component Refactoring
eduaid_web/src/pages/Home.jsx, eduaid_web/src/pages/Output.jsx
Refactored heading markup from inline Tailwind styles to new gradient CSS classes; converted Output dropdown management from direct DOM manipulation to React state and useRef for improved stability.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰✨ Gradients dance without the GPU's gleam,
React state tames dropdowns, a steadier dream,
CSS classes bloom in vibrant array,
Rendering stable, both night and day!
No more flicker, just smooth delight—
EduAid shines with consistent light! 🌈

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: hardening state handling in the Output component and stabilizing gradient rendering across the codebase via new CSS utility classes and Electron GPU acceleration disabling.
Linked Issues check ✅ Passed The PR directly addresses all four coding objectives from issue #621: stabilized gradient rendering via CSS utilities [#621], replaced DOM-driven dropdown with state-controlled React patterns [#621], improved localStorage parsing safety [#621], and enhanced PDF worker cleanup [#621].
Out of Scope Changes check ✅ Passed All changes remain directly aligned with issue #621: gradient CSS classes, Home/Output heading refactors, state-driven dropdown control, and hardware acceleration disabling are all addressing the stability and rendering issues specified.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
eduaid_web/src/pages/Output.jsx (2)

93-96: ⚠️ Potential issue | 🟡 Minor

localStorage parsing can still throw on malformed data.

The PR objective mentions "preventing crashes from unsafe localStorage parsing," but JSON.parse() will still throw a SyntaxError if localStorage contains malformed JSON. Consider wrapping in try-catch.

🛡️ Proposed fix for safer parsing
   useEffect(() => {
-    const qaPairsFromStorage =
-      JSON.parse(localStorage.getItem("qaPairs")) || {};
-    if (qaPairsFromStorage) {
+    let qaPairsFromStorage = {};
+    try {
+      qaPairsFromStorage = JSON.parse(localStorage.getItem("qaPairs")) || {};
+    } catch (e) {
+      console.error("Failed to parse qaPairs from localStorage:", e);
+    }
+    if (Object.keys(qaPairsFromStorage).length > 0) {
       const combinedQaPairs = [];
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@eduaid_web/src/pages/Output.jsx` around lines 93 - 96, The JSON.parse call
inside the useEffect that reads localStorage.getItem("qaPairs") can throw on
malformed data; update the useEffect to wrap parsing in a try-catch around
JSON.parse(localStorage.getItem("qaPairs")) (used to set qaPairsFromStorage),
fall back to an empty object on error, and optionally handle/log the error or
remove the invalid "qaPairs" entry so the app doesn't crash when malformed data
is present.

123-133: ⚠️ Potential issue | 🟠 Major

Potential TypeError if qaPairsFromStorage["output"] is undefined.

The condition on line 123 checks for output_mcq or questionType === "get_mcq", but line 124 accesses qaPairsFromStorage["output"] without verifying it exists. This can throw if the output key is missing.

🐛 Proposed fix to guard against undefined
-      if (qaPairsFromStorage["output_mcq"] || questionType === "get_mcq") {
+      if ((qaPairsFromStorage["output_mcq"] || questionType === "get_mcq") && qaPairsFromStorage["output"]) {
         qaPairsFromStorage["output"].forEach((qaPair) => {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@eduaid_web/src/pages/Output.jsx` around lines 123 - 133, The current block
that handles MCQ merging reads qaPairsFromStorage["output"] without ensuring it
exists, which can throw a TypeError; update the conditional around
qaPairsFromStorage["output_mcq"] / questionType === "get_mcq" to also guard that
qaPairsFromStorage["output"] is an array (e.g., check
Array.isArray(qaPairsFromStorage["output"]) or qaPairsFromStorage["output"] !=
null) before calling forEach, and only call combinedQaPairs.push(...) inside
that guarded branch so functions/values like qaPairsFromStorage,
combinedQaPairs, and the forEach callback on qaPair are safe.
🧹 Nitpick comments (3)
eduaid_desktop/main.js (1)

2-3: Make hardware acceleration disable configurable instead of unconditional.

This disables GPU globally for all users and environments. While it may stabilize specific rendering glitches, Electron's official documentation recommends using disableHardwareAcceleration() only when experiencing GPU-related issues—not by default for normal windows, as it can degrade performance and visual quality (especially on a gradient-heavy UI like this). Use the existing config system to gate it behind a flag (environment or config option) so it applies only where needed.

Suggested refactor
 // Fix Electron rendering glitch (safe and stable)
-app.disableHardwareAcceleration();
+if (config.disableGpuAcceleration === true) {
+  app.disableHardwareAcceleration();
+}

Then add disableGpuAcceleration: false to the appropriate environment block in config.js.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@eduaid_desktop/main.js` around lines 2 - 3, Replace the unconditional call to
app.disableHardwareAcceleration() with a configuration-gated call: add a boolean
config flag (e.g., disableGpuAcceleration) to your existing config system
(config.js) and read that flag at startup; only call
app.disableHardwareAcceleration() when that flag is true. Locate the startup
boot code where app.disableHardwareAcceleration() is invoked and wrap it with a
conditional check against your config (e.g., config.disableGpuAcceleration) so
the behavior is environment/config driven rather than unconditional.
eduaid_web/src/pages/Output.jsx (2)

202-205: Dropdown not closed on worker error.

The success path (line 198) closes the dropdown via setShowDropdown(false), but the error handler doesn't. Consider closing the dropdown on error for consistent UX.

♻️ Proposed fix
     worker.onerror = (err) => {
       console.error("PDF generation failed in worker:", err);
+      setShowDropdown(false);
       worker.terminate();
     };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@eduaid_web/src/pages/Output.jsx` around lines 202 - 205, The error handler
for PDF worker (worker.onerror) currently logs and terminates the worker but
doesn't close the UI dropdown; update the worker.onerror callback to call
setShowDropdown(false) before or after worker.terminate() so the dropdown is
closed on errors just like the success path (see the success handler usage of
setShowDropdown(false)), keeping the existing console.error and
worker.terminate() behavior.

382-392: Clean state-driven dropdown implementation.

Good use of ref for outside-click detection and functional state update for toggle. Note: the id="pdfDropdown" attribute (line 391) appears to be a leftover from the previous DOM-based approach and can be removed.

🧹 Optional cleanup
               <div
-                id="pdfDropdown"
                 className={`${showDropdown ? 'block' : 'hidden'} absolute bottom-full mb-1 left-0 sm:left-auto right-0 sm:right-auto bg-[`#02000F`] shadow-md text-white rounded-lg shadow-lg z-50 w-full sm:w-48`}
               >
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@eduaid_web/src/pages/Output.jsx` around lines 382 - 392, The id="pdfDropdown"
is a leftover DOM-based hook and should be removed to avoid confusion; locate
the dropdown container element that uses dropdownRef and controlled by
showDropdown (the div with className using `${showDropdown ? 'block' :
'hidden'}`) and delete the id="pdfDropdown" attribute, keeping the
ref={dropdownRef} and the state toggle via setShowDropdown intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@eduaid_web/src/pages/Home.jsx`:
- Around line 50-51: Replace the two separate <h1> elements in the Home
component with a single <h1> containing two <span> children (one for "Edu" and
one for "Aid") to preserve visual styles while fixing semantic accessibility;
keep the existing class names (gradient-text-base plus gradient-text for the
first span and gradient-text-base plus gradient-text-2 for the second) and
mirror the pattern used in Output.jsx (the single <h1> with spans) so screen
readers and SEO see one primary heading.

---

Outside diff comments:
In `@eduaid_web/src/pages/Output.jsx`:
- Around line 93-96: The JSON.parse call inside the useEffect that reads
localStorage.getItem("qaPairs") can throw on malformed data; update the
useEffect to wrap parsing in a try-catch around
JSON.parse(localStorage.getItem("qaPairs")) (used to set qaPairsFromStorage),
fall back to an empty object on error, and optionally handle/log the error or
remove the invalid "qaPairs" entry so the app doesn't crash when malformed data
is present.
- Around line 123-133: The current block that handles MCQ merging reads
qaPairsFromStorage["output"] without ensuring it exists, which can throw a
TypeError; update the conditional around qaPairsFromStorage["output_mcq"] /
questionType === "get_mcq" to also guard that qaPairsFromStorage["output"] is an
array (e.g., check Array.isArray(qaPairsFromStorage["output"]) or
qaPairsFromStorage["output"] != null) before calling forEach, and only call
combinedQaPairs.push(...) inside that guarded branch so functions/values like
qaPairsFromStorage, combinedQaPairs, and the forEach callback on qaPair are
safe.

---

Nitpick comments:
In `@eduaid_desktop/main.js`:
- Around line 2-3: Replace the unconditional call to
app.disableHardwareAcceleration() with a configuration-gated call: add a boolean
config flag (e.g., disableGpuAcceleration) to your existing config system
(config.js) and read that flag at startup; only call
app.disableHardwareAcceleration() when that flag is true. Locate the startup
boot code where app.disableHardwareAcceleration() is invoked and wrap it with a
conditional check against your config (e.g., config.disableGpuAcceleration) so
the behavior is environment/config driven rather than unconditional.

In `@eduaid_web/src/pages/Output.jsx`:
- Around line 202-205: The error handler for PDF worker (worker.onerror)
currently logs and terminates the worker but doesn't close the UI dropdown;
update the worker.onerror callback to call setShowDropdown(false) before or
after worker.terminate() so the dropdown is closed on errors just like the
success path (see the success handler usage of setShowDropdown(false)), keeping
the existing console.error and worker.terminate() behavior.
- Around line 382-392: The id="pdfDropdown" is a leftover DOM-based hook and
should be removed to avoid confusion; locate the dropdown container element that
uses dropdownRef and controlled by showDropdown (the div with className using
`${showDropdown ? 'block' : 'hidden'}`) and delete the id="pdfDropdown"
attribute, keeping the ref={dropdownRef} and the state toggle via
setShowDropdown intact.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a3154c01-0cc1-4ff1-a675-94df61a08973

📥 Commits

Reviewing files that changed from the base of the PR and between 2038116 and 06a90b4.

📒 Files selected for processing (4)
  • eduaid_desktop/main.js
  • eduaid_web/src/index.css
  • eduaid_web/src/pages/Home.jsx
  • eduaid_web/src/pages/Output.jsx

Comment on lines +50 to +51
<h1 className="gradient-text-base gradient-text">Edu</h1>
<h1 className="gradient-text-base gradient-text-2">Aid</h1>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Semantic issue: Two <h1> elements for a single heading.

Using two separate <h1> elements for "Edu" and "Aid" is semantically incorrect—screen readers and search engines will interpret these as two distinct primary headings. This differs from the approach in Output.jsx (lines 220-223) which correctly uses a single <h1> with two <span> children.

🛠️ Proposed fix to use a single h1 with spans
-                <h1 className="gradient-text-base gradient-text">Edu</h1>
-                <h1 className="gradient-text-base gradient-text-2">Aid</h1>
+                <h1 className="text-4xl sm:text-6xl font-extrabold flex gap-1 justify-center">
+                  <span className="gradient-text-base gradient-text">Edu</span>
+                  <span className="gradient-text-base gradient-text-2">Aid</span>
+                </h1>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<h1 className="gradient-text-base gradient-text">Edu</h1>
<h1 className="gradient-text-base gradient-text-2">Aid</h1>
<h1 className="text-4xl sm:text-6xl font-extrabold flex gap-1 justify-center">
<span className="gradient-text-base gradient-text">Edu</span>
<span className="gradient-text-base gradient-text-2">Aid</span>
</h1>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@eduaid_web/src/pages/Home.jsx` around lines 50 - 51, Replace the two separate
<h1> elements in the Home component with a single <h1> containing two <span>
children (one for "Edu" and one for "Aid") to preserve visual styles while
fixing semantic accessibility; keep the existing class names (gradient-text-base
plus gradient-text for the first span and gradient-text-base plus
gradient-text-2 for the second) and mirror the pattern used in Output.jsx (the
single <h1> with spans) so screen readers and SEO see one primary heading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Inconsistent gradient rendering in Electron and unstable output component behavior

1 participant