Skip to content

fix:621 fixed gradient issues#653

Open
MANVENDRA-github wants to merge 2 commits into
AOSSIE-Org:mainfrom
MANVENDRA-github:electron-gradient-stability
Open

fix:621 fixed gradient issues#653
MANVENDRA-github wants to merge 2 commits into
AOSSIE-Org:mainfrom
MANVENDRA-github:electron-gradient-stability

Conversation

@MANVENDRA-github
Copy link
Copy Markdown

@MANVENDRA-github MANVENDRA-github commented Mar 31, 2026

This PR addresses rendering inconsistencies in the Electron application and improves the overall stability of the Output component.

The changes focus on fixing gradient text rendering issues and resolving multiple reliability concerns related to state handling, localStorage parsing, dropdown interactions, and Web Worker lifecycle management.

Related Issue

Closes: #621

Type of Change

Bug fix

Summary by CodeRabbit

  • New Features

    • Added gradient text styling for enhanced visual presentation.
  • Improvements

    • Improved rendering stability and performance in the desktop app.
    • Smoother PDF dropdown interactions with more reliable outside-click handling and state management.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 31, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6e330f81-eba2-42be-9101-beeb441f55a5

📥 Commits

Reviewing files that changed from the base of the PR and between ef16c38 and e34fda3.

📒 Files selected for processing (1)
  • eduaid_web/src/index.css
🚧 Files skipped from review as they are similar to previous changes (1)
  • eduaid_web/src/index.css

📝 Walkthrough

Walkthrough

Disabled Electron hardware acceleration, added CSS gradient text utilities, and refactored the Output PDF dropdown to use React state and a ref-based outside-click handler instead of imperative DOM manipulation.

Changes

Cohort / File(s) Summary
Electron Hardware Acceleration
eduaid_desktop/main.js
Called app.disableHardwareAcceleration() at startup to disable GPU acceleration.
Gradient Text CSS Utilities
eduaid_web/src/index.css
Added .gradient-text-base, .gradient-text, and .gradient-text-2 classes to enable background-clip gradient-filled text and two preset gradients. Minor whitespace cleanup in .border-gradient.
Output Component State Refactor
eduaid_web/src/pages/Output.jsx
Replaced imperative DOM toggling with showDropdown React state and dropdownRef; outside-click handling moved to a ref-based handler; hides dropdown after PDF generation via state update.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through code at morning's light,
Gradients gleam from left to right,
GPU sleeps, no flicker seen,
Dropdowns tidy—state is clean,
A little rabbit's dev delight. 🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (1 warning, 2 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR partially addresses issue #621 requirements: gradient CSS classes were added for consistent rendering, and PDF dropdown state management was improved. However, requirements for localStorage safety and Web Worker cleanup are not implemented. Implement safe localStorage JSON parsing with try-catch error handling and add proper Web Worker lifecycle cleanup to fully resolve issue #621 requirements.
Title check ❓ Inconclusive The title is vague and generic, using non-descriptive phrasing like 'fixed gradient issues' without specifying what gradient issues were fixed or clarifying the actual changes. Use a more specific title that clearly describes the main changes, such as 'fix: add gradient text CSS classes and improve Output component state handling' to better convey the scope.
Out of Scope Changes check ❓ Inconclusive The addition of hardware acceleration disabling in main.js and gradient text CSS classes are relevant to stability, but the hardware acceleration change lacks explicit mention in issue #621 and may represent scope expansion. Clarify whether hardware acceleration disabling is necessary for the gradient rendering fix or if it should be separated into a distinct issue and PR.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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
Copy Markdown

@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 (3)
eduaid_web/src/pages/Output.jsx (3)

94-96: ⚠️ Potential issue | 🟠 Major

Protect localStorage parse on Line 95 to avoid runtime crashes.

JSON.parse(localStorage.getItem("qaPairs")) will throw on malformed data, which breaks initial render instead of degrading gracefully.

Proposed fix
-  const qaPairsFromStorage =
-    JSON.parse(localStorage.getItem("qaPairs")) || {};
+  let qaPairsFromStorage = {};
+  try {
+    const raw = localStorage.getItem("qaPairs");
+    qaPairsFromStorage = raw ? JSON.parse(raw) : {};
+  } catch (error) {
+    console.error("Invalid qaPairs in localStorage:", error);
+    qaPairsFromStorage = {};
+  }
🤖 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 94 - 96, Wrap the
JSON.parse(localStorage.getItem("qaPairs")) call in a safe parse so a malformed
value doesn't throw during initial render: catch errors from parsing the result
of localStorage.getItem("qaPairs") (or check it's valid JSON) and fallback to an
empty object; update the qaPairsFromStorage initialization in Output.jsx (the
const qaPairsFromStorage and the subsequent if (qaPairsFromStorage) check) to
use the safe result so the component degrades gracefully instead of crashing.

123-132: ⚠️ Potential issue | 🟠 Major

Guard output before iterating and dedupe merged MCQ datasets.

Line 124 assumes qaPairsFromStorage["output"] is always an array; when absent/corrupt it will throw. Also, appending both MCQ sources without dedupe can render duplicates.

Proposed fix
-      if (qaPairsFromStorage["output_mcq"] || questionType === "get_mcq") {
-        qaPairsFromStorage["output"].forEach((qaPair) => {
-          combinedQaPairs.push({
-            question: qaPair.question_statement,
-            question_type: "MCQ",
-            options: qaPair.options,
-            answer: qaPair.answer,
-            context: qaPair.context,
-          });
-        });
-      }
+      const mcqSeen = new Set();
+      const pushMcq = (qaPair) => {
+        const mapped = {
+          question: qaPair.question_statement,
+          question_type: "MCQ",
+          options: qaPair.options,
+          answer: qaPair.answer,
+          context: qaPair.context,
+        };
+        const key = `${mapped.question}::${mapped.answer}`;
+        if (!mcqSeen.has(key)) {
+          mcqSeen.add(key);
+          combinedQaPairs.push(mapped);
+        }
+      };
+
+      if (qaPairsFromStorage["output_mcq"]?.questions?.length) {
+        qaPairsFromStorage["output_mcq"].questions.forEach(pushMcq);
+      }
+      if (questionType === "get_mcq" && Array.isArray(qaPairsFromStorage["output"])) {
+        qaPairsFromStorage["output"].forEach(pushMcq);
+      }

Based on learnings: In eduaid_web/src/pages/Output.jsx, output_mcq and output (get_mcq) should be merged as separate MCQ sources without duplicates or order inconsistencies.

🤖 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 - 132, Guard access to
qaPairsFromStorage["output"] and dedupe when merging MCQ sources: before
iterating in Output.jsx ensure qaPairsFromStorage["output"] is an array (e.g.,
default to [] when falsy or not Array.isArray) and only push MCQ entries to
combinedQaPairs after normalizing them (use question_statement as the primary
unique key, optionally combined with serialized options) to filter out
duplicates when merging from qaPairsFromStorage["output_mcq"] and
qaPairsFromStorage["output"] (or when questionType === "get_mcq"); keep
insertion order by checking a Set of seen keys before pushing to
combinedQaPairs.

183-206: ⚠️ Potential issue | 🟠 Major

Prevent overlapping PDF workers and add unmount-safe cleanup.

Current flow can spawn concurrent workers if users click export options repeatedly; worker lifetime is not tracked across unmount/navigation, which can leak work and trigger stale updates.

Proposed fix
+  const pdfWorkerRef = useRef(null);
+  const [isGeneratingPdf, setIsGeneratingPdf] = useState(false);
+
+  useEffect(() => {
+    return () => {
+      if (pdfWorkerRef.current) {
+        pdfWorkerRef.current.terminate();
+        pdfWorkerRef.current = null;
+      }
+    };
+  }, []);
+
-    const generatePDF = async (mode) => {
+    const generatePDF = async (mode) => {
+    if (isGeneratingPdf) return;
+    setIsGeneratingPdf(true);
+    setShowDropdown(false);
     const logoBytes = await loadLogoAsBytes();
+    if (pdfWorkerRef.current) {
+      pdfWorkerRef.current.terminate();
+    }
     const worker = new Worker(new URL("../workers/pdfWorker.js", import.meta.url), { type: "module" });
+    pdfWorkerRef.current = worker;
@@
-      setShowDropdown(false);
       worker.terminate();
+      pdfWorkerRef.current = null;
+      setIsGeneratingPdf(false);
     };
@@
     worker.onerror = (err) => {
       console.error("PDF generation failed in worker:", err);
+      setShowDropdown(false);
       worker.terminate();
+      pdfWorkerRef.current = null;
+      setIsGeneratingPdf(false);
     };
   };

Also applies to: 389-413

🤖 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 183 - 206, The generatePDF
function can spawn overlapping Web Workers and leaks them across unmounts; fix
by tracking the active worker in a ref (e.g., currentWorkerRef) instead of a
local variable, guard generatePDF to return early if currentWorkerRef.current
exists, attach onmessage/onerror that clear currentWorkerRef.current and only
call setShowDropdown if the component is still mounted, and add a useEffect
cleanup to terminate any currentWorkerRef.current and remove handlers on
unmount; update references to worker in generatePDF and any other export
handlers (also where similar code appears around the other block) to use this
ref-based lifecycle.
🧹 Nitpick comments (1)
eduaid_desktop/main.js (1)

2-2: Move hardware-acceleration disablement to configuration, not unconditional startup.

Line 2 applies a global workaround that degrades performance on machines with stable rendering. The codebase already has a config.js module handling environment-specific settings—extend it to make this conditional (e.g., config.disableHardwareAcceleration flag toggled per environment or via environment variable). This avoids unnecessary performance loss on systems where GPU acceleration works reliably.

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

In `@eduaid_desktop/main.js` at line 2, The unconditional call to
app.disableHardwareAcceleration() should be made conditional via the existing
configuration: add a boolean flag (e.g., disableHardwareAcceleration) to the
config.js module and read it where the Electron app is initialized; replace the
direct call to app.disableHardwareAcceleration() with a guarded call that only
executes when config.disableHardwareAcceleration is true (or when the
corresponding env var enables it). Ensure config.js exports the new flag
(derived from env or environment-specific settings) and update the startup code
that currently calls app.disableHardwareAcceleration() to use that flag before
invoking the method.
🤖 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/index.css`:
- Around line 27-33: The .gradient-text-base rule is missing the standard color
property needed for Firefox compatibility; update the CSS for the
.gradient-text-base class to add color: transparent alongside
-webkit-text-fill-color: transparent so background-clip: text renders the
gradient correctly across browsers.

---

Outside diff comments:
In `@eduaid_web/src/pages/Output.jsx`:
- Around line 94-96: Wrap the JSON.parse(localStorage.getItem("qaPairs")) call
in a safe parse so a malformed value doesn't throw during initial render: catch
errors from parsing the result of localStorage.getItem("qaPairs") (or check it's
valid JSON) and fallback to an empty object; update the qaPairsFromStorage
initialization in Output.jsx (the const qaPairsFromStorage and the subsequent if
(qaPairsFromStorage) check) to use the safe result so the component degrades
gracefully instead of crashing.
- Around line 123-132: Guard access to qaPairsFromStorage["output"] and dedupe
when merging MCQ sources: before iterating in Output.jsx ensure
qaPairsFromStorage["output"] is an array (e.g., default to [] when falsy or not
Array.isArray) and only push MCQ entries to combinedQaPairs after normalizing
them (use question_statement as the primary unique key, optionally combined with
serialized options) to filter out duplicates when merging from
qaPairsFromStorage["output_mcq"] and qaPairsFromStorage["output"] (or when
questionType === "get_mcq"); keep insertion order by checking a Set of seen keys
before pushing to combinedQaPairs.
- Around line 183-206: The generatePDF function can spawn overlapping Web
Workers and leaks them across unmounts; fix by tracking the active worker in a
ref (e.g., currentWorkerRef) instead of a local variable, guard generatePDF to
return early if currentWorkerRef.current exists, attach onmessage/onerror that
clear currentWorkerRef.current and only call setShowDropdown if the component is
still mounted, and add a useEffect cleanup to terminate any
currentWorkerRef.current and remove handlers on unmount; update references to
worker in generatePDF and any other export handlers (also where similar code
appears around the other block) to use this ref-based lifecycle.

---

Nitpick comments:
In `@eduaid_desktop/main.js`:
- Line 2: The unconditional call to app.disableHardwareAcceleration() should be
made conditional via the existing configuration: add a boolean flag (e.g.,
disableHardwareAcceleration) to the config.js module and read it where the
Electron app is initialized; replace the direct call to
app.disableHardwareAcceleration() with a guarded call that only executes when
config.disableHardwareAcceleration is true (or when the corresponding env var
enables it). Ensure config.js exports the new flag (derived from env or
environment-specific settings) and update the startup code that currently calls
app.disableHardwareAcceleration() to use that flag before invoking the method.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 87949d97-a157-4c07-8daa-af5be63481f7

📥 Commits

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

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

Comment thread eduaid_web/src/index.css Outdated
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