fix(useTheme): Safari ≤13 compatibility — fall back to addListener/removeListener#2916
Draft
fix(useTheme): Safari ≤13 compatibility — fall back to addListener/removeListener#2916
Conversation
|
|
…oveListener Agent-Logs-Url: https://github.com/alibaba/hooks/sessions/44b4f10a-2129-4b82-b52f-4ce18ef49dd2 Co-authored-by: crazylxr <16161407+crazylxr@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix useTheme compatibility issue with Safari 13.1.2
fix(useTheme): Safari ≤13 compatibility — fall back to addListener/removeListener
Mar 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Safari 13.1.2 and earlier don't implement
MediaQueryList.addEventListener, causing aTypeError: e.addEventListener is not a functioncrash inuseTheme.变更内容
useTheme/index.ts: InuseCurrentTheme, guardaddEventListener/removeEventListenercalls with existence checks and fall back to the deprecatedaddListener/removeListenerAPI supported by older Safari:useTheme/__tests__/index.spec.ts: Added test that mocksmatchMediawithoutaddEventListener/removeEventListenerand assertsaddListener/removeListenerare invoked instead.[English Template / 英文模板]
🤔 这个变动的性质是?
🔗 相关 Issue
Safari 13.1.2 下
useTheme报错:TypeError: e.addEventListener is not a function(MediaQueryList不支持addEventListener)。💡 需求背景和解决方案
问题:Safari ≤13 的
MediaQueryList未实现标准的addEventListener/removeEventListener,只支持已废弃的addListener/removeListener,直接调用导致运行时崩溃。方案:在订阅/取消订阅系统主题变化时,优先使用标准 API,检测不存在时降级为旧版 API,无需引入任何额外依赖。
📝 更新日志
useTheme: Fixed crash on Safari ≤13 by falling back to deprecatedaddListener/removeListenerwhenaddEventListeneris unavailable onMediaQueryList.useTheme:修复在 Safari ≤13 中因MediaQueryList不支持addEventListener导致的运行时报错,降级使用addListener/removeListener。☑️ 请求合并前的自查清单
📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.