Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read properties of undefined (reading 'sendHeight') #197

Closed
das41236 opened this issue Jan 5, 2022 · 2 comments
Closed

Cannot read properties of undefined (reading 'sendHeight') #197

das41236 opened this issue Jan 5, 2022 · 2 comments

Comments

@das41236
Copy link

das41236 commented Jan 5, 2022

When we run the code:(parent)

<div id="foo"></div>
<script>
var pymParent = new pym.Parent('foo', 'child.html', {});
</script>

(child)
function render(width) { pymChild.sendHeight(); } var pymChild = new pym.Child({ renderCallback: render })

The page loads only the top 150px of the content (blank for the rest all the way to the bottom). The parent div shows a height of 154px, the iframe shows height of 150px, and the html inside the iframe renders 1500px which includes the top 150px that does get loaded. The console shows an error:

Uncaught TypeError: Cannot read properties of undefined (reading 'sendHeight') at Object.render [as renderCallback] (child.html?initialWidth=1664&childId=foo&parentTitle=Test PYM.js&parentUrl=file%3A%2F%2F%2FUsers%2Fwaltemik%2FDesktop%2Fppv-elearning%2Findex.html:2551) at new a.Child (pym.v1.min.js:3) at child.html?initialWidth=1664&childId=foo&parentTitle=Test PYM.js&parentUrl=file%3A%2F%2F%2FUsers%2Fwaltemik%2FDesktop%2Fppv-elearning%2Findex.html:2556

@thomaswilburn
Copy link

The renderCallback is immediately invoked when a Pym guest instance is constructed, which means that technically pymChild hasn't been assigned yet when it is run. You may want to add a guard to your code, something like if (pymChild) pymChild.sendHeight();, to handle this case. Alternately, switch to the polling option, which is much easier to manage than manually sending the height after each render.

@das41236
Copy link
Author

@thomaswilburn Thank you, your instructions helped resolve the issues we were having.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants