Skip to content

fix#540

Open
ruchI9897 wants to merge 1 commit into
mainfrom
getBoundingClientRect-err
Open

fix#540
ruchI9897 wants to merge 1 commit into
mainfrom
getBoundingClientRect-err

Conversation

@ruchI9897
Copy link
Copy Markdown
Contributor

No description provided.

@ruchI9897 ruchI9897 requested a review from a team as a code owner May 25, 2026 11:52
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/embed/app.ts
Comment on lines +1133 to 1141
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);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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);
        }

Comment thread src/embed/liveboard.ts
Comment on lines +828 to 836
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);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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);
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant