-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Throttle calls to "window.history.replaceState" to fix Mobile Safari error message #5613
Conversation
…error message fixes #5612
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder, why is it called so often in the first place? _updateHash
is called on moveend
. If moveend
has been called 100 times in 30 seconds, and given that moveend
itself is debounced (called only once in case of many quick successive movements of the map), there might be a bug lurking there of which this is only a symptom.
Also, I'd prefer bringing back the little util.throttle
we had before but removed at some point than including a part of lodash for the first time in the GL JS build.
The provided test harness demonstrates a realistic use case that would trigger the error message even if we revamp the panning
I experienced a bug in our I will put more time into debugging |
I must confess I'm disappointed by the size of |
44f6aa6
to
3ac5097
Compare
The problem is that |
src/util/throttle.js
Outdated
unthrottledFunction(); | ||
} else if (!pending) { | ||
pending = true; | ||
// eslint-disable-next-line no-use-before-define |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ESLint docs on the rule state that:
In ES6, block-level bindings (let and const) introduce a “temporal dead zone” where a ReferenceError will be thrown with any attempt to access the variable before its declaration.
So if this code weren't transpiled (which may happen in future) it would throw an error in theory. So perhaps let's rewrite to either use function
declaration instead of arrows, or declare one of the vars at the top with let
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoa! I've been out in the woods too long. Fixed in 20f3fe0.
c93e2c2
to
6eb096b
Compare
As of iOS 9.3, Mobile Safari throws an error if
window.history.replaceState
is called more than 100 times per 30 seconds. This PR throttles all calls towindow.history.replaceState
to avoid triggering this error message.Benchmark scores: https://bl.ocks.org/anonymous/raw/9a02ed1c37970d9d6c697f667b56527a/
fixes #5612
Next Steps
util.throttle
& write tests forutil.throttle
) or find acceptablethrottle
implementationmoveend
deboucingTest Harness