davidjbradshaw / iframe-resizer

Keep iFrames sized to their content.
https://iframe-resizer.com
Other
6.63k stars 978 forks source link

Callback from IframeResizer does not get the latest state object #1230

Closed avaya1 closed 2 months ago

avaya1 commented 3 months ago

Describe the bug I have a react component which house the IframeResizer and this component has state based on the event from IframeResizer. The state supposed to manipulate the latest state with the event but when callback is called I am getting the initial state instead of the latest state which was updated part of last callback.

To Reproduce Steps to reproduce the behavior:

  1. Download the sample project associated with this Or refer Updated code at
  2. Modify app.jsx
    const onMessage = data => { setMessageData({...messageData,...data}) ref.current.sendMessage('Hello back from parent page') }
  3. Modify message-data.jsx change renderer return data ? ( Frame ID: {data.iframe.id}   Height: {data.height}   Width: {data.width}   Event type: {data.type}   Message: {data.message}

    ) : null

  4. Observe the message that is rendered on the bottom. You will have hight and width value.

Frame ID: iFrameResizer0 Height: 546 Width: 751 Event type: init Message:

  1. Now Click on Send message and observe the message that is rendered, empty Height and width

Frame ID: iFrameResizer0 Height: Width: Event type: Message: Hello from the iFrame

Expected behavior As previous event had those attributes and already saved to the state we should have those values rendered as we are merging new event with the old state.

updated Sample code Updated code at

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Smartphone (please complete the following information):

davidjbradshaw commented 3 months ago

Could you please try the test release of V5 of iframe resized and let me know if it still has the same issue?

https://iframe-resizer.github.io/docs/

davidjbradshaw commented 2 months ago

Closed due to no response