-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use timers instead of requestAnimationFrame
The issue with using requestAnimationFrame is that its meant to be used for visual effects. Therefore when a tab is hidden the browser might decide to not perform animation frame updates until the tab becomes visible, this is confirmed behaviour for Firefox. Due to this title updates would not be triggered while document titles are normally visible in the tabs title. For now we batch updates by setting/clearing timeouts with a 10ms interval Resolves: #313
- Loading branch information
Showing
5 changed files
with
86 additions
and
47 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// store an id to keep track of DOM updates | ||
let batchId = null | ||
|
||
export function triggerUpdate(vm, hookName) { | ||
if (vm.$root._vueMeta.initialized && !vm.$root._vueMeta.paused) { | ||
// batch potential DOM updates to prevent extraneous re-rendering | ||
batchUpdate(() => vm.$meta().refresh()) | ||
} | ||
} | ||
|
||
/** | ||
* Performs a batched update. | ||
* | ||
* @param {(null|Number)} id - the ID of this update | ||
* @param {Function} callback - the update to perform | ||
* @return {Number} id - a new ID | ||
*/ | ||
export function batchUpdate(callback, timeout = 10) { | ||
clearTimeout(batchId) | ||
|
||
batchId = setTimeout(() => { | ||
callback() | ||
}, timeout) | ||
|
||
return batchId | ||
} |
This file contains 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
This file contains 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