Fix failing assertion on start-up with Safari (#1736)

The initial media query that's used to watch for device pixel ratio
changes should match. Unfortunately it doesn't with Safari and the
corresponding assertion fails. This is because resolution is not a
supported support property for queries. As a workaround, this patch
extends the query to optionally match for the webkit specific DPR
property directly.

This fixes #1734
This commit is contained in:
Simon Hausmann 2020-10-10 06:31:51 +02:00 committed by GitHub
parent 676fb947f2
commit 5a78fe33e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -59,9 +59,9 @@ impl ScaleChangeDetectorInternal {
// We add 0.0001 to the lower and upper bounds such that it won't fail
// due to floating point precision limitations.
let media_query = format!(
"(min-resolution: {:.4}dppx) and (max-resolution: {:.4}dppx)",
current_scale - 0.0001,
current_scale + 0.0001,
"(min-resolution: {min_scale:.4}dppx) and (max-resolution: {max_scale:.4}dppx),
(-webkit-min-device-pixel-ratio: {min_scale:.4}) and (-webkit-max-device-pixel-ratio: {max_scale:.4})",
min_scale = current_scale - 0.0001, max_scale= current_scale + 0.0001,
);
let mql = MediaQueryListHandle::new(&media_query, closure);
if let Some(mql) = &mql {