-
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
Batch render DOM elements to avoid reflow #10530
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -507,7 +507,12 @@ export default class Marker extends Evented { | |
this._pos = this._pos.round(); | ||
} | ||
|
||
DOM.setTransform(this._element, `${anchorTranslate[this._anchor]} translate(${this._pos.x}px, ${this._pos.y}px) ${pitch} ${rotation}`); | ||
const el = this._element; | ||
const pos = this._pos; | ||
const anchor = this._anchor; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can get rid of aliases here too (and check for just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is embarrassing, I really thought I removed it! |
||
this._map._domRenderTaskQueue.add(() => { | ||
DOM.setTransform(el, `${anchorTranslate[anchor]} translate(${pos.x}px, ${pos.y}px) ${pitch} ${rotation}`); | ||
}); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -572,8 +572,12 @@ export default class Popup extends Evented { | |
} | ||
|
||
const offsetedPos = pos.add(offset[anchor]).round(); | ||
DOM.setTransform(this._container, `${anchorTranslate[anchor]} translate(${offsetedPos.x}px,${offsetedPos.y}px)`); | ||
applyAnchorClass(this._container, anchor, 'popup'); | ||
const container = this._container; | ||
const _anchor = anchor; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: given that the closure captures the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, I edited the comment here but the old version got posted somehow — so, now I see that the DOM elements are aliased so that it doesn't break in case a task is run after the object is removed from the map, but it's not obvious, so might need additional comments to avoid maintainers tripping up on this. Alternatively, we could look into whether this can be refactored to avoid the issue differently — e.g. perhaps marking a task as cancelled when a corresponding object is removed, or maybe adding some guards for the elements inside the closure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be honest, I got an error with It would be better however to see how it can be refactored. What about storing the task ID in the popup, as there should always be only one? Considering the total number of popup, it won't be a burden and then we could cancel the task in |
||
this._map._domRenderTaskQueue.add(() => { | ||
DOM.setTransform(container, `${anchorTranslate[_anchor]} translate(${offsetedPos.x}px,${offsetedPos.y}px)`); | ||
applyAnchorClass(container, _anchor, 'popup'); | ||
}); | ||
} | ||
|
||
_focusFirstElement() { | ||
|
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.
Nit: it's better to pass the smallest scope necessary for the function — in this case,
queue
instead of the wholemap
object. Makes refactoring easier later.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.
Thanks I totally missed this!