{"action":"created","issue":{"url":"https://api.github.com/repos/Aaronius/penpal/issues/7","repository_url":"https://api.github.com/repos/Aaronius/penpal","labels_url":"https://api.github.com/repos/Aaronius/penpal/issues/7/labels{/name}","comments_url":"https://api.github.com/repos/Aaronius/penpal/issues/7/comments","events_url":"https://api.github.com/repos/Aaronius/penpal/issues/7/events","html_url":"https://github.com/Aaronius/penpal/issues/7","id":243802118,"number":7,"title":"Loading Penpal with System.js fails to connect","user":{"login":"gajewsk2","id":4039913,"avatar_url":"https://avatars1.githubusercontent.com/u/4039913?v=4","gravatar_id":"","url":"https://api.github.com/users/gajewsk2","html_url":"https://github.com/gajewsk2","followers_url":"https://api.github.com/users/gajewsk2/followers","following_url":"https://api.github.com/users/gajewsk2/following{/other_user}","gists_url":"https://api.github.com/users/gajewsk2/gists{/gist_id}","starred_url":"https://api.github.com/users/gajewsk2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gajewsk2/subscriptions","organizations_url":"https://api.github.com/users/gajewsk2/orgs","repos_url":"https://api.github.com/users/gajewsk2/repos","events_url":"https://api.github.com/users/gajewsk2/events{/privacy}","received_events_url":"https://api.github.com/users/gajewsk2/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-07-18T18:05:09Z","updated_at":"2017-07-18T19:25:46Z","closed_at":null,"body":"System.js loads assets asynchronously (in development) and this causes the iframe's 'load' event to fire pre-emptively, for the purposes of Penpal. The child's connectToParent function has not been called, so it cannot receieve the message from the parent that is sent after the iframe's load event fires.\r\n\r\nWe have yet to find a way to cause System.js to load synchronously, except with bundling, which is only used in production. Currently we have developed a work-around that involves exposing a version of the handleIframeLoaded function that only calls the child.postMessage  HANDSHAKE part of the function (which we have dubbed 'manualHandshake'). We then have the child send a message to the parent once System.js has done its work, to trigger a re-handshake. \r\n\r\nThe other solutions we tried, such as trying to re-fiore the Load event, didn't work because we are inside a situation where CORS is blocking us, which is what we wanted Penpal for in the first place.\r\n\r\nDo you have any opinions or advice on how to address this issue without a code change to the repository? Alternately, we could submit a pull request with our solution if the solution sounds reasonable and useful. (Current 'issue' with the pull request is that it would change the return interface of connectToChild to return this extra handshaking function as well.)"},"comment":{"url":"https://api.github.com/repos/Aaronius/penpal/issues/comments/316170944","html_url":"https://github.com/Aaronius/penpal/issues/7#issuecomment-316170944","issue_url":"https://api.github.com/repos/Aaronius/penpal/issues/7","id":316170944,"user":{"login":"Aaronius","id":210820,"avatar_url":"https://avatars1.githubusercontent.com/u/210820?v=4","gravatar_id":"","url":"https://api.github.com/users/Aaronius","html_url":"https://github.com/Aaronius","followers_url":"https://api.github.com/users/Aaronius/followers","following_url":"https://api.github.com/users/Aaronius/following{/other_user}","gists_url":"https://api.github.com/users/Aaronius/gists{/gist_id}","starred_url":"https://api.github.com/users/Aaronius/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Aaronius/subscriptions","organizations_url":"https://api.github.com/users/Aaronius/orgs","repos_url":"https://api.github.com/users/Aaronius/repos","events_url":"https://api.github.com/users/Aaronius/events{/privacy}","received_events_url":"https://api.github.com/users/Aaronius/received_events","type":"User","site_admin":false},"created_at":"2017-07-18T19:25:46Z","updated_at":"2017-07-18T19:25:46Z","body":"Interesting. A couple thoughts that come to mind:\r\n\r\n(1) What if, instead of starting the handshake from the parent, we started it from the child. It's actually similar to what you're doing in your code, but rather than the child saying \"hey parent, start the handshake\", the child would be starting the handshake itself and waiting for the parent to acknowledge it. Maybe there's an obvious reason I'm missing as to why this wouldn't work. I need to look through the code to see what ramifications this would have.\r\n\r\n(2) If option 1 doesn't work for some reason, we could instead retry the handshake on an interval until a response is received from the child.\r\n\r\nPros: It's resolved automatically. No need to send a message from the client, receive it from the parent, or call `manualHandshake`.\r\nCons: Waiting for an interval to end will probably take longer than the child telling the parent immediately when it's ready for the handshake. `postMessage` isn't too expensive though, so I think we could keep the intervals pretty short.\r\n\r\nI can take a shot at implementation sometime. I would greatly prefer option 1. Thanks for reporting this issue. I do think it's something we should resolve."}}
{"actor":{"display_login":"Aaronius"}}