Skip to content

Conversation

@reekystive
Copy link

@reekystive reekystive commented Oct 23, 2025

Summary

This PR fixes an asymmetric compatibility issue in useMediaQuery where the addEventListener compatibility check was removed during subscription but still present during unsubscription, causing errors in older Safari versions.

The recent commit 4880540 removed the addEventListener / addListener fallback logic in createQueryEntry but kept it in queryUnsubscribe, creating an inconsistency. This causes issues in Safari versions that don't support addEventListener on MediaQueryList (Safari < 14).

Changes

  • Restored the addEventListener / addListener compatibility check in createQueryEntry to match the unsubscription logic in queryUnsubscribe
  • Ensures symmetric handling of event listeners for both subscription and unsubscription

Problem

In older Safari versions, MediaQueryList only supports the deprecated addListener / removeListener methods. The code was:

  • Using addEventListener unconditionally when subscribing (line 20)
  • Using conditional removeEventListener / removeListener when unsubscribing (lines 52-56)

This mismatch meant that in older Safari:

  1. Subscription would fail trying to call non-existent addEventListener
  2. Even if it didn't fail, the listener wouldn't be properly registered with addListener
  3. Unsubscription would try to call removeListener on a listener that was never added

@reekystive reekystive changed the title fix(useMediaQuery): restore addEventListener compatibility check for symmetry Fix compatibility issue for useMediaQuery Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant