Aaronius / penpal

A promise-based library for securely communicating with iframes via postMessage.
MIT License
389 stars 56 forks source link

Parent methods called multiple times after child reload #18

Closed ski629 closed 6 years ago

ski629 commented 6 years ago

Thank you for writing this great library! It has been very easy to work with outside of this one issue.

After a child is reloaded, any methods that it calls on the parent are executed on the parent side multiple times. The child only receives one response, but the parent executes the method an additional time for every time the child is reloaded.

For example, if the child is reloaded three times, and then calls a parent method once, the parent will execute that method 4 times, and return only the first result to the child.

This is easy to reproduce by placing a console.log statement inside the 'add' method in the usage example, and right clicking inside the child pane and clicking 'reload frame'.

This is a fairly significant problem if the parent method has any side effects. I have not had a chance to look into the cause yet.

Aaronius commented 6 years ago

Thanks for reporting this. Yeah, sounds like a bug. I'll take a look as soon as I can. If you figure it out before then, a PR would be excellent.

Aaronius commented 6 years ago

Fixed in 3.0.2.

ski629 commented 6 years ago

Thank you Aaron!