Skip to content

Fix VoiceSearch TypeError in Firefox#1249

Open
Ayushi227 wants to merge 1 commit intocodeaashu:mainfrom
Ayushi227:fix-firefox-voicesearch
Open

Fix VoiceSearch TypeError in Firefox#1249
Ayushi227 wants to merge 1 commit intocodeaashu:mainfrom
Ayushi227:fix-firefox-voicesearch

Conversation

@Ayushi227
Copy link
Copy Markdown

@Ayushi227 Ayushi227 commented Apr 16, 2026

Description

Added a check for browser. As the speech recognition implemented does not function on firefox browser, the program throws an error -
Screenshot 2026-04-16 at 2 56 03 PM

Related Issues

[Bug]: Website not working on Firefox - #1234

Changes Proposed

The change I am proposing is to add a small display message to the user stating that speech recognition is not supported in firefox, and bypass the use of speech recognition on firefox. The rest of the page functions as is.
Uploading Screenshot 2026-04-16 at 2.58.20 PM.png…

Checklist

  • I have read and followed the Contribution Guidelines.
  • All new and existing tests passed.
  • I have updated the documentation to reflect the changes I've made.
  • My code follows the code style of this project.
  • The title of my pull request is a short description of the requested changes.

Screenshots

Note to reviewers

Summary by CodeRabbit

  • Bug Fixes
    • Added notification informing Firefox users about voice search availability in their browser.
    • Improved voice search stability and error handling to prevent crashes and provide better feedback on failures.
    • Enhanced cleanup procedures during component lifecycle for more consistent and reliable behavior.

@bolt-new-by-stackblitz
Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 16, 2026

Someone is attempting to deploy a commit to the icecream's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

🎉 Incredible work, @Ayushi227! 🚀

🔥 Welcome to DevDisplay — A space where developers and all the tech enthusiasts can connect, collaborate, code, create, and conquer in the tech ecosystem.

At DevDisplay, we don't just welcome contributors—we celebrate them! 🎊 Because here, your ideas matter. Your code matters. You matter. 🚀

💡 This isn't just about adding your profile. It's about making an impact, showcasing your skills, and standing out in the developer ecosystem.

Think of DevDisplay as your own project, not just another open-source contribution. We're not just a platform—we're a global movement redefining the tech space. Our vision is to be the go-to platform for developers and tech enthusiasts worldwide.

🚀 Innovation has no limits!
We encourage you to think beyond the ordinary. Got a revolutionary idea? Spot a gap in the tech world? DevDisplay can be the solution! We want contributors like you to dream big, build bold, and bring game-changing features to life.

🌍 DevDisplay is more than an open-source project. It's a global tech hub, a thriving community, and a platform where you can connect, collaborate, code, create, and conquer.

🔥 Keep pushing boundaries—we're just getting started!
If you put your 💯 into creating something exceptional, you could even join our Global Core Team and also you can lead DevDisplay as a Community Leader in your area, college, or university.


💡 Your issue is now in review!

  • Our maintainers will soon review your PR and provide feedback/suggestions. 🚀 Stay tuned, stay engaged, and get ready to bring your ideas to life! 💡

---

📢 Have ideas to improve DevDisplay? Let us know! We're always looking for innovative minds to shape the future of tech.

💬 Join the conversation. Grow with the community. You belong here. 🙌


📢 Join Our Global Developer Communities & Connect with Innovators:

📩 Need Help? Reach Out to the Team:

💻 Follow DevDisplay on Social Media & Stay Updated:

🔥 🌟 Thank You for Being Here!

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 16, 2026

📝 Walkthrough

Walkthrough

The VoiceSearch component was refactored to improve React lifecycle management by moving SpeechRecognition initialization from module scope into a useEffect hook using a ref. Firefox browser detection was added with conditional initialization and a user-facing notification for unsupported browsers, along with enhanced error handling.

Changes

Cohort / File(s) Summary
VoiceSearch Lifecycle & Browser Compatibility Refactor
src/components/Search/VoiceSearch.jsx
Migrated SpeechRecognition initialization from module scope to useEffect with proper cleanup. Added Firefox detection via navigator.userAgent to skip initialization and display a dismissible notification. Introduced useRef for recognition instance management and useState for notification state. Event handlers now set within effect, with separate effect handling start/stop logic wrapped in try/catch with error logging. Conditional rendering prevents listening UI display on Firefox.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Voice search gets a refresh, hooks take the stage,
Firefox finds mercy on this careful page,
Lifecycle flows clean, from mount to the end,
A ref and a state, on which we depend,
Listen or not—the choice is now true!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change—fixing a TypeError in VoiceSearch that occurs in Firefox, which matches the core issue being addressed.
Description check ✅ Passed The pull request description includes all required template sections: description of the issue, related issues link, detailed changes proposed, and a completed checklist.

✏️ 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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/components/Search/VoiceSearch.jsx`:
- Around line 73-78: The dismiss button in VoiceSearch.jsx uses an onClick that
calls setShowNotification(false) but lacks an explicit button type and
accessible name; update the <button> that calls setShowNotification to include
type="button" to prevent accidental form submits and add an accessible label
(e.g., aria-label="Dismiss notification" or a visually hidden text node) so
screen readers can announce its purpose, keeping the current onClick handler
unchanged.
- Around line 52-64: The useEffect early-return when recognitionRef.current is
falsy or isFirefox leaves isListening potentially stale; update the effect (the
one referencing recognitionRef, isListening, isFirefox) so that when recognition
is unavailable (recognitionRef.current is falsy) or isFirefox is true you
explicitly reset the isListening state (call the setter passed from props or
local setIsListening) to false before returning, ensuring component state
reflects the actual recognition availability instead of silently exiting; keep
the try/catch path for start/stop logic unchanged.
🪄 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: e86eea87-d34f-4369-a7b1-53b10f806463

📥 Commits

Reviewing files that changed from the base of the PR and between e5b46c1 and 098fb17.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • src/components/Search/VoiceSearch.jsx

Comment on lines +52 to +64
useEffect(() => {
if (!recognitionRef.current || isFirefox) return;

try {
if (isListening) {
recognitionRef.current.start();
} else {
recognitionRef.current.stop();
}
} catch (err) {
console.error('Failed to control recognition:', err);
}
}, [isListening, isFirefox]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Reset isListening when recognition is unavailable.

At Line 53, Firefox exits early without reconciling isListening. If parent code sets it to true, state can remain out-of-sync with actual recognition state.

Proposed fix
 useEffect(() => {
-  if (!recognitionRef.current || isFirefox) return;
+  if (isFirefox || !recognitionRef.current) {
+    if (isListening) {
+      setShowNotification(true);
+      setIsListening(false);
+    }
+    return;
+  }
 
   try {
     if (isListening) {
       recognitionRef.current.start();
     } else {
       recognitionRef.current.stop();
     }
   } catch (err) {
     console.error('Failed to control recognition:', err);
   }
-}, [isListening, isFirefox]);
+}, [isListening, isFirefox, setIsListening]);
📝 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
useEffect(() => {
if (!recognitionRef.current || isFirefox) return;
try {
if (isListening) {
recognitionRef.current.start();
} else {
recognitionRef.current.stop();
}
} catch (err) {
console.error('Failed to control recognition:', err);
}
}, [isListening, isFirefox]);
useEffect(() => {
if (isFirefox || !recognitionRef.current) {
if (isListening) {
setShowNotification(true);
setIsListening(false);
}
return;
}
try {
if (isListening) {
recognitionRef.current.start();
} else {
recognitionRef.current.stop();
}
} catch (err) {
console.error('Failed to control recognition:', err);
}
}, [isListening, isFirefox, setIsListening]);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/Search/VoiceSearch.jsx` around lines 52 - 64, The useEffect
early-return when recognitionRef.current is falsy or isFirefox leaves
isListening potentially stale; update the effect (the one referencing
recognitionRef, isListening, isFirefox) so that when recognition is unavailable
(recognitionRef.current is falsy) or isFirefox is true you explicitly reset the
isListening state (call the setter passed from props or local setIsListening) to
false before returning, ensuring component state reflects the actual recognition
availability instead of silently exiting; keep the try/catch path for start/stop
logic unchanged.

Comment on lines +73 to +78
<button
onClick={() => setShowNotification(false)}
className="text-yellow-800 hover:text-yellow-900 dark:text-yellow-200"
>
</button>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Make the dismiss button safe and accessible.

The new close button should explicitly use type="button" (to avoid accidental form submit) and include an accessible name.

Proposed fix
           <button
+            type="button"
+            aria-label="Dismiss speech recognition browser support notice"
             onClick={() => setShowNotification(false)}
             className="text-yellow-800 hover:text-yellow-900 dark:text-yellow-200"
           >
📝 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
<button
onClick={() => setShowNotification(false)}
className="text-yellow-800 hover:text-yellow-900 dark:text-yellow-200"
>
</button>
<button
type="button"
aria-label="Dismiss speech recognition browser support notice"
onClick={() => setShowNotification(false)}
className="text-yellow-800 hover:text-yellow-900 dark:text-yellow-200"
>
</button>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/Search/VoiceSearch.jsx` around lines 73 - 78, The dismiss
button in VoiceSearch.jsx uses an onClick that calls setShowNotification(false)
but lacks an explicit button type and accessible name; update the <button> that
calls setShowNotification to include type="button" to prevent accidental form
submits and add an accessible label (e.g., aria-label="Dismiss notification" or
a visually hidden text node) so screen readers can announce its purpose, keeping
the current onClick handler unchanged.

@github-actions
Copy link
Copy Markdown

Hi there! This issue is still open. We are looking forward to your response.
Assignees: None

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.

1 participant