Skip to content

Commit d5f7908

Browse files
authoredMar 13, 2021
fix: prevents reset when only dimensions change (#278)
* Prevents reset when only dimensions change * fix: test doesn't need new player with size change
1 parent fa21478 commit d5f7908

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed
 

‎src/YouTube.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ function shouldUpdateVideo(prevProps, props) {
3333
function filterResetOptions(opts) {
3434
return {
3535
...opts,
36+
height: 0,
37+
width: 0,
3638
playerVars: {
39+
...opts.playerVars,
3740
autoplay: 0,
3841
start: 0,
3942
end: 0,
40-
...opts.playerVars,
4143
},
4244
};
4345
}
@@ -62,7 +64,8 @@ function shouldResetPlayer(prevProps, props) {
6264
* @param {Object} props
6365
*/
6466
function shouldUpdatePlayer(prevProps, props) {
65-
return prevProps.id !== props.id || prevProps.className !== props.className;
67+
return prevProps.id !== props.id || prevProps.className !== props.className
68+
|| prevProps.opts.width !== props.opts.width || prevProps.opts.height !== props.opts.height;
6669
}
6770

6871
class YouTube extends React.Component {
@@ -213,6 +216,10 @@ class YouTube extends React.Component {
213216
else iframe.removeAttribute('id');
214217
if (this.props.className) iframe.setAttribute('class', this.props.className);
215218
else iframe.removeAttribute('class');
219+
if (this.props.opts && this.props.opts.width) iframe.setAttribute('width', this.props.opts.width);
220+
else iframe.removeAttribute('width');
221+
if (this.props.opts && this.props.opts.height) iframe.setAttribute('height', this.props.opts.height);
222+
else iframe.removeAttribute('height');
216223
});
217224
};
218225

‎src/Youtube.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ describe('YouTube', () => {
117117
width: '480px',
118118
height: '360px',
119119
playerVars: {
120+
height: 0, // changed, does not force destroy & rebind
121+
width: 0, // changed, does not force destroy & rebind
120122
autoplay: 1, // changed, does not force destroy & rebind
121123
start: 10, // changed, does not force destroy & rebind
122124
end: 20, // changed, does not force destroy & rebind

0 commit comments

Comments
 (0)
Please sign in to comment.