Skip to content

Commit

Permalink
fix(widget): add a threshold for the widget height
Browse files Browse the repository at this point in the history
  • Loading branch information
shoom3301 committed Nov 10, 2023
1 parent c202eb0 commit 3e72764
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion libs/widget-lib/src/cowSwapWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ const COW_SWAP_WIDGET_EVENT_KEY = 'cowSwapWidget'
const DEFAULT_HEIGHT = '640px'
const DEFAULT_WIDTH = '450px'

/**
* Reference: IframeResizer (apps/cowswap-frontend/src/modules/injectedWidget/updaters/IframeResizer.ts)
* Sometimes MutationObserver doesn't trigger when the height of the widget changes and the widget displays with a scrollbar.
* To avoid this we add a threshold to the height.
* 20px
*/
const HEIGHT_THRESHOLD = 20

/**
* Callback function signature for updating the CoW Swap Widget.
*/
Expand Down Expand Up @@ -126,6 +134,6 @@ function applyDynamicHeight(iframe: HTMLIFrameElement, defaultHeight = DEFAULT_H
return
}

iframe.style.height = event.data.height ? `${event.data.height}px` : defaultHeight
iframe.style.height = event.data.height ? `${event.data.height + HEIGHT_THRESHOLD}px` : defaultHeight
})
}

0 comments on commit 3e72764

Please sign in to comment.