mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
use Promise to update head (#574)
This commit is contained in:
parent
1fbf324883
commit
f7ee50323d
|
@ -10,14 +10,14 @@ const DOMAttributeNames = {
|
|||
|
||||
export default class HeadManager {
|
||||
constructor () {
|
||||
this.requestId = null
|
||||
this.updatePromise = null
|
||||
}
|
||||
|
||||
updateHead (head) {
|
||||
// perform batch update
|
||||
window.cancelAnimationFrame(this.requestId)
|
||||
this.requestId = window.requestAnimationFrame(() => {
|
||||
this.requestId = null
|
||||
const promise = this.updatePromise = Promise.resolve().then(() => {
|
||||
if (promise !== this.updatePromise) return
|
||||
|
||||
this.updatePromise = null
|
||||
this.doUpdateHead(head)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue