fix#540
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements safety checks for iframe availability in AppEmbed and LiveboardEmbed and updates the scroll event listener removal to use the capture phase. It also adds comprehensive unit tests for these scenarios. The review feedback suggests a performance optimization to check configuration flags before performing layout-triggering calculations, which helps avoid unnecessary browser reflows.
| if (!this.iFrame?.getBoundingClientRect) { | ||
| return; | ||
| } | ||
|
|
||
| const data = calculateVisibleElementData(this.iFrame); | ||
| // this should be fired only if the lazyLoadingForFullHeight and fullHeight are true | ||
| if(this.viewConfig.lazyLoadingForFullHeight && this.viewConfig.fullHeight){ | ||
| if (this.viewConfig.lazyLoadingForFullHeight && this.viewConfig.fullHeight) { | ||
| this.trigger(HostEvent.VisibleEmbedCoordinates, data); | ||
| } |
There was a problem hiding this comment.
The calculateVisibleElementData function is called and its result is computed even when the lazyLoadingForFullHeight and fullHeight conditions are not met. Since calculateVisibleElementData internally calls getBoundingClientRect, which can trigger a browser reflow/layout, it is more efficient to perform the configuration check first and only proceed with the calculation if the event is actually going to be triggered.
if (this.viewConfig.lazyLoadingForFullHeight && this.viewConfig.fullHeight) {
if (!this.iFrame?.getBoundingClientRect) {
return;
}
const data = calculateVisibleElementData(this.iFrame);
this.trigger(HostEvent.VisibleEmbedCoordinates, data);
}| if (!this.iFrame?.getBoundingClientRect) { | ||
| return; | ||
| } | ||
|
|
||
| const data = calculateVisibleElementData(this.iFrame); | ||
| // this should be fired only if the lazyLoadingForFullHeight and fullHeight are true | ||
| if(this.viewConfig.lazyLoadingForFullHeight && this.viewConfig.fullHeight){ | ||
| if (this.viewConfig.lazyLoadingForFullHeight && this.viewConfig.fullHeight) { | ||
| this.trigger(HostEvent.VisibleEmbedCoordinates, data); | ||
| } |
There was a problem hiding this comment.
The calculateVisibleElementData function is called and its result is computed even when the lazyLoadingForFullHeight and fullHeight conditions are not met. Since calculateVisibleElementData internally calls getBoundingClientRect, which can trigger a browser reflow/layout, it is more efficient to perform the configuration check first and only proceed with the calculation if the event is actually going to be triggered.
if (this.viewConfig.lazyLoadingForFullHeight && this.viewConfig.fullHeight) {
if (!this.iFrame?.getBoundingClientRect) {
return;
}
const data = calculateVisibleElementData(this.iFrame);
this.trigger(HostEvent.VisibleEmbedCoordinates, data);
}
No description provided.