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

don't recreate the player for video changes #397

Open
wants to merge 1 commit into
base: canary
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/react-youtube/src/YouTube.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ function filterResetOptions(opts: Options = {}) {
* those.
*/
function shouldResetPlayer(prevProps: YouTubeProps, props: YouTubeProps) {
return (
prevProps.videoId !== props.videoId || !isEqual(filterResetOptions(prevProps.opts), filterResetOptions(props.opts))
);
return !isEqual(filterResetOptions(prevProps.opts), filterResetOptions(props.opts));
}

/**
Expand Down
18 changes: 3 additions & 15 deletions packages/react-youtube/src/Youtube.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,13 @@ describe('YouTube', () => {
expect(playerMock.destroy).toHaveBeenCalled();
});

it('should create and bind a new YouTube player when props.videoId, playerVars.autoplay, playerVars.start, or playerVars.end change', async () => {
it('should not create and bind a new YouTube player when only props.videoId changes', async () => {
const { rerender } = render(
<YouTube
videoId="XxVg_s8xAms"
opts={{
width: '480px',
height: '360px',
playerVars: {
autoplay: 0,
start: 0,
end: 50,
},
}}
/>,
);
Expand All @@ -170,19 +165,12 @@ describe('YouTube', () => {
opts={{
width: '480px',
height: '360px',
playerVars: {
autoplay: 1, // changed, does not force destroy & rebind
start: 10, // changed, does not force destroy & rebind
end: 20, // changed, does not force destroy & rebind
},
}}
/>,
);

// player is destroyed & rebound, despite the changes
expect(playerMock.destroy).toHaveBeenCalled();
// and the video is updated
await waitFor(() => expect(playerMock.loadVideoById).toHaveBeenCalled());
// player is not destroyed & rebound, despite the change
expect(playerMock.destroy).not.toHaveBeenCalled();
});

it('should not create and bind a new YouTube player when only playerVars.autoplay, playerVars.start, or playerVars.end change', () => {
Expand Down