forked from cybrespace/mastodon
Improve IntersectionObserverArticle perf (#5152)
This commit is contained in:
parent
83ffc4dc07
commit
ca0e8be20c
|
@ -58,26 +58,31 @@ export default class IntersectionObserverArticle extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
handleIntersection = (entry) => {
|
handleIntersection = (entry) => {
|
||||||
const { onHeightChange, saveHeightKey, id } = this.props;
|
this.entry = entry;
|
||||||
|
|
||||||
if (this.node && this.node.children.length !== 0) {
|
scheduleIdleTask(this.calculateHeight);
|
||||||
// save the height of the fully-rendered element
|
this.setState(this.updateStateAfterIntersection);
|
||||||
this.height = getRectFromEntry(entry).height;
|
}
|
||||||
|
|
||||||
if (onHeightChange && saveHeightKey) {
|
updateStateAfterIntersection = (prevState) => {
|
||||||
onHeightChange(saveHeightKey, id, this.height);
|
if (prevState.isIntersecting && !this.entry.isIntersecting) {
|
||||||
}
|
scheduleIdleTask(this.hideIfNotIntersecting);
|
||||||
}
|
}
|
||||||
|
return {
|
||||||
|
isIntersecting: this.entry.isIntersecting,
|
||||||
|
isHidden: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
this.setState((prevState) => {
|
calculateHeight = () => {
|
||||||
if (prevState.isIntersecting && !entry.isIntersecting) {
|
const { onHeightChange, saveHeightKey, id } = this.props;
|
||||||
scheduleIdleTask(this.hideIfNotIntersecting);
|
// save the height of the fully-rendered element (this is expensive
|
||||||
}
|
// on Chrome, where we need to fall back to getBoundingClientRect)
|
||||||
return {
|
this.height = getRectFromEntry(this.entry).height;
|
||||||
isIntersecting: entry.isIntersecting,
|
|
||||||
isHidden: false,
|
if (onHeightChange && saveHeightKey) {
|
||||||
};
|
onHeightChange(saveHeightKey, id, this.height);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hideIfNotIntersecting = () => {
|
hideIfNotIntersecting = () => {
|
||||||
|
|
Loading…
Reference in New Issue