fix: Prevent TypeError from deprecated addListener API#3992
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3992 +/- ##
==========================================
- Coverage 98.73% 98.67% -0.06%
==========================================
Files 827 828 +1
Lines 15133 15142 +9
Branches 4357 4367 +10
==========================================
Hits 14942 14942
- Misses 184 191 +7
- Partials 7 9 +2
Continue to review full report in Codecov by Harness.
|
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## main #3992 +/- ##
==========================================
- Coverage 98.73% 98.67% -0.06%
==========================================
Files 827 828 +1
Lines 15133 15142 +9
Branches 4357 4367 +10
==========================================
Hits 14942 14942
- Misses 184 191 +7
- Partials 7 9 +2
Continue to review full report in Codecov by Sentry.
|
Codecov ReportAttention: Patch coverage is
✅ All tests successful. No failed tests found.
@@ Coverage Diff @@
## main #3992 +/- ##
==========================================
- Coverage 98.73% 98.67% -0.06%
==========================================
Files 827 828 +1
Lines 15133 15142 +9
Branches 4357 4367 +10
==========================================
Hits 14942 14942
- Misses 184 191 +7
- Partials 7 9 +2
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## main #3992 +/- ##
==========================================
- Coverage 98.73% 98.67% -0.06%
==========================================
Files 827 828 +1
Lines 15133 15142 +9
Branches 4357 4367 +10
==========================================
Hits 14942 14942
- Misses 184 191 +7
- Partials 7 9 +2
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
Description
This PR addresses GAZEBO-17Z7, a
TypeError: Cannot read properties of undefined (reading 'addListener')occurring on commit detail pages.Root Cause:
The
react-hot-toastlibrary (v2.4.1) internally uses the deprecatedMediaQueryList.prototype.addListenermethod to detect dark mode preferences. In certain browser environments (e.g., Edge 150), this deprecated method isundefined, leading to aTypeErrorwhenreact-hot-toastattempts to call it without a null-check.Solution:
src/polyfills/mediaQueryList.ts: This new file provides a polyfill forMediaQueryList.prototype.addListenerandMediaQueryList.prototype.removeListener. If these deprecated methods are found to beundefined, the polyfill shims them to delegate to their modern counterparts,addEventListener('change', ...)andremoveEventListener('change', ...), respectively.src/index.tsx: The polyfill is imported as the very first statement insrc/index.tsx. This ensures that the polyfill is active and theaddListenermethod is available beforereact-hot-toast(or any other library) initializes and attempts to use it.Code Example
Notable Changes
src/polyfills/mediaQueryList.tsto provide a polyfill forMediaQueryList.prototype.addListenerandMediaQueryList.prototype.removeListener.src/index.tsxas the very first statement to ensure it's active globally before other libraries initialize.Screenshots
Link to Sample Entry
Legal Boilerplate
Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.
Fixes GAZEBO-17Z7