Skip to content

refactor: replace deprecated matchMedia listeners with addEventListener#3531

Merged
arkid15r merged 4 commits intoOWASP:mainfrom
ThetaLogN:refactor/modernize-use-is-mobile-hook
Jan 25, 2026
Merged

refactor: replace deprecated matchMedia listeners with addEventListener#3531
arkid15r merged 4 commits intoOWASP:mainfrom
ThetaLogN:refactor/modernize-use-is-mobile-hook

Conversation

@ThetaLogN
Copy link
Contributor

Resolves #3515

The useIsMobile hook currently uses addListener and removeListener, which are deprecated in modern browsers. This updates the hook to use the standard addEventListener('change', ...) API, improving code quality.

https://sonarcloud.io/project/issues?open=AZksw2CU_PPcrA-zHUTg&id=OWASP_Nest

Checklist

  • Required: I followed the contributing workflow
  • Required: I verified that my code works as intended and resolves the issue as described
  • Required: I ran make check-test locally: all warnings addressed, tests passed
  • I used AI for code, documentation, tests, or communication related to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 25, 2026

Summary by CodeRabbit

  • Refactor
    • Simplified mobile detection logic for more consistent event handling and reliable cleanup.
    • Removed legacy browser-specific fallback branches to reduce conditional complexity.
    • Preserved existing behavior tied to change events while improving maintainability and reducing potential edge-case differences across environments.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

Refactored the useIsMobile hook to always use MediaQueryList.addEventListener('change') and removeEventListener, removing the Safari <14 addListener/removeListener fallback while keeping the initial handleChange invocation. (48 words)

Changes

Cohort / File(s) Summary
Hook event listener modernization
frontend/src/hooks/useIsMobile.ts
Replaced deprecated MediaQueryList.addListener/removeListener branch with unconditional addEventListener('change', ...)/removeEventListener(...); removed Safari <14 compatibility branch; preserved initial handleChange call.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: replacing deprecated matchMedia listeners (addListener/removeListener) with the standard addEventListener API.
Description check ✅ Passed The description is directly related to the changeset, explaining the motivation for replacing deprecated APIs with addEventListener and referencing the resolved issue.
Linked Issues check ✅ Passed The PR successfully addresses issue #3515 by replacing deprecated addListener/removeListener with addEventListener('change', ...) in the useIsMobile hook.
Out of Scope Changes check ✅ Passed The changes are focused solely on refactoring the useIsMobile hook to use modern API patterns, with no unrelated modifications detected.
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 docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 25, 2026
coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 25, 2026
@arkid15r arkid15r enabled auto-merge January 25, 2026 21:16
@sonarqubecloud
Copy link

@codecov
Copy link

codecov bot commented Jan 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.48%. Comparing base (dfc96ef) to head (106ac1a).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3531   +/-   ##
=======================================
  Coverage   85.48%   85.48%           
=======================================
  Files         461      461           
  Lines       14240    14240           
  Branches     1896     1896           
=======================================
  Hits        12173    12173           
  Misses       1688     1688           
  Partials      379      379           
Flag Coverage Δ
backend 84.48% <ø> (ø)
frontend 88.26% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dfc96ef...106ac1a. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@arkid15r arkid15r added this pull request to the merge queue Jan 25, 2026
Merged via the queue into OWASP:main with commit c15981a Jan 25, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor: Replace deprecated MediaQueryList.addListener with addEventListener

2 participants

Comments