Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dark mode detection causes crashes in Safari #245

Closed
MaxDesiatov opened this issue Aug 3, 2020 · 1 comment · Fixed by #249
Closed

Dark mode detection causes crashes in Safari #245

MaxDesiatov opened this issue Aug 3, 2020 · 1 comment · Fixed by #249
Labels
bug Something isn't working

Comments

@MaxDesiatov
Copy link
Collaborator

I currently see this as soon as the page loads:

[Error] Fatal error: Unexpectedly found nil while unwrapping an Optional value: 
file Sources/TokamakDOM/App/ColorSchemeObserver.swift, line 30

Not reproducible in other browsers in my testing

@MaxDesiatov MaxDesiatov added the bug Something isn't working label Aug 3, 2020
@j-f1
Copy link
Member

j-f1 commented Aug 4, 2020

I haven’t been able to reproduce this on my side but this change should help debug:

diff --git a/Sources/TokamakDOM/App/ColorSchemeObserver.swift b/Sources/TokamakDOM/App/ColorSchemeObserver.swift
index 262acba..2bfebfa 100644
--- a/Sources/TokamakDOM/App/ColorSchemeObserver.swift
+++ b/Sources/TokamakDOM/App/ColorSchemeObserver.swift
@@ -25,7 +25,12 @@ enum ColorSchemeObserver {
 
   static func observe(_ rootElement: JSObjectRef) {
     let closure = JSClosure {
-      publisher.value = .init(matchMediaDarkScheme: $0[0].object!)
+      if let matchMediaDarkScheme = $0[0].object {
+        publisher.value = .init(matchMediaDarkScheme: matchMediaDarkScheme)
+      } else {
+        print($0)
+        _ = JSObjectRef.global.console.object!.log!($0[0])
+      }
       return .undefined
     }
     _ = matchMediaDarkScheme.addEventListener!("change", closure)

MaxDesiatov added a commit that referenced this issue Aug 5, 2020
Resolve #245. Turns out `matchMediaDarkScheme` object doesn't have `addEventListener`, but only `addListener` in Safari 13.1.2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

2 participants