iframe-resizer-react icon indicating copy to clipboard operation
iframe-resizer-react copied to clipboard

Invalid typings for `onResized` `width`

Open duncanbeevers opened this issue 4 years ago • 1 comments

Issue

The typings for onResized indicate it receives numerical width.

2021-06-01 at 3 49 PM

However, when using it in the wild, the callback is invoked with a string value. In the implementation, width is never cast to a number.

https://github.com/davidjbradshaw/iframe-resizer/blob/master/src/iframeResizer.js#L162-L175

function processMsg() {
  var data = msg.substr(msgIdLen).split(':')
  var height = data[1] ? parseInt(data[1], 10) : 0
  var iframe = settings[data[0]] && settings[data[0]].iframe
  var compStyle = getComputedStyle(iframe)

  return {
    iframe: iframe,
    id: data[0],
    height: height + getPaddingEnds(compStyle) + getBorderEnds(compStyle),
    width: data[2], // ← width is still a string
    type: data[3]
  }
}

Recommended Fix

Ideally, this could be fixed in the upstream iframe-resizer library so that width actually comes through as a number instead of a string. However, I recognize the far larger impact of such a change.

Alternatively, this consuming library could expect a string width without breaking backwards compatibility.

duncanbeevers avatar Jun 01 '21 23:06 duncanbeevers

If you would like to fix the typings, I'd welcome the PR

davidjbradshaw avatar Jun 02 '21 11:06 davidjbradshaw