Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: tjallingt/react-youtube
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 431debc810fcdc8278d440df70205cc14a1b7016
Choose a base ref
...
head repository: tjallingt/react-youtube
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 863ee323e3ec7f83abc92c0619091a3a210354f8
Choose a head ref

Commits on Mar 13, 2021

  1. chore(deps): bump elliptic from 6.5.3 to 6.5.4 (#286)

    Bumps [elliptic](https://github.com/indutny/elliptic) from 6.5.3 to 6.5.4.
    - [Release notes](https://github.com/indutny/elliptic/releases)
    - [Commits](indutny/elliptic@v6.5.3...v6.5.4)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Mar 13, 2021
    Copy the full SHA
    fa21478 View commit details
  2. fix: prevents reset when only dimensions change (#278)

    * Prevents reset when only dimensions change
    
    * fix: test doesn't need new player with size change
    dancancro authored Mar 13, 2021
    Copy the full SHA
    d5f7908 View commit details
  3. Copy the full SHA
    fc423ea View commit details
  4. Copy the full SHA
    36dc03b View commit details

Commits on Jul 15, 2021

  1. chore(deps): bump y18n from 3.2.1 to 3.2.2 (#289)

    Bumps [y18n](https://github.com/yargs/y18n) from 3.2.1 to 3.2.2.
    - [Release notes](https://github.com/yargs/y18n/releases)
    - [Changelog](https://github.com/yargs/y18n/blob/master/CHANGELOG.md)
    - [Commits](https://github.com/yargs/y18n/commits)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jul 15, 2021
    Copy the full SHA
    1bb2e95 View commit details
  2. chore(deps): bump ssri from 6.0.1 to 6.0.2 (#292)

    Bumps [ssri](https://github.com/npm/ssri) from 6.0.1 to 6.0.2.
    - [Release notes](https://github.com/npm/ssri/releases)
    - [Changelog](https://github.com/npm/ssri/blob/v6.0.2/CHANGELOG.md)
    - [Commits](npm/ssri@v6.0.1...v6.0.2)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jul 15, 2021
    Copy the full SHA
    7081546 View commit details
  3. chore(deps): bump handlebars from 4.7.6 to 4.7.7 (#293)

    Bumps [handlebars](https://github.com/wycats/handlebars.js) from 4.7.6 to 4.7.7.
    - [Release notes](https://github.com/wycats/handlebars.js/releases)
    - [Changelog](https://github.com/handlebars-lang/handlebars.js/blob/master/release-notes.md)
    - [Commits](handlebars-lang/handlebars.js@v4.7.6...v4.7.7)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jul 15, 2021
    Copy the full SHA
    9b0ec96 View commit details
  4. chore(deps): bump hosted-git-info from 2.8.8 to 2.8.9 (#294)

    Bumps [hosted-git-info](https://github.com/npm/hosted-git-info) from 2.8.8 to 2.8.9.
    - [Release notes](https://github.com/npm/hosted-git-info/releases)
    - [Changelog](https://github.com/npm/hosted-git-info/blob/v2.8.9/CHANGELOG.md)
    - [Commits](npm/hosted-git-info@v2.8.8...v2.8.9)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jul 15, 2021
    Copy the full SHA
    6eb4aab View commit details
  5. chore(deps): bump lodash from 4.17.20 to 4.17.21 (#295)

    Bumps [lodash](https://github.com/lodash/lodash) from 4.17.20 to 4.17.21.
    - [Release notes](https://github.com/lodash/lodash/releases)
    - [Commits](lodash/lodash@4.17.20...4.17.21)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jul 15, 2021
    Copy the full SHA
    a9c4ae6 View commit details
  6. chore(deps): bump browserslist from 4.14.0 to 4.16.6 (#299)

    Bumps [browserslist](https://github.com/browserslist/browserslist) from 4.14.0 to 4.16.6.
    - [Release notes](https://github.com/browserslist/browserslist/releases)
    - [Changelog](https://github.com/browserslist/browserslist/blob/main/CHANGELOG.md)
    - [Commits](browserslist/browserslist@4.14.0...4.16.6)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jul 15, 2021
    Copy the full SHA
    4a8a227 View commit details
  7. chore(deps): bump trim-newlines from 3.0.0 to 3.0.1 (#303)

    Bumps [trim-newlines](https://github.com/sindresorhus/trim-newlines) from 3.0.0 to 3.0.1.
    - [Release notes](https://github.com/sindresorhus/trim-newlines/releases)
    - [Commits](https://github.com/sindresorhus/trim-newlines/commits)
    
    ---
    updated-dependencies:
    - dependency-name: trim-newlines
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jul 15, 2021
    Copy the full SHA
    462f140 View commit details

Commits on Aug 19, 2021

  1. feat: lazy load (#308)

    * feat: lazy load
    
    Refs #234
    
    * feat: loading to be more specific
    Foo-x authored Aug 19, 2021
    Copy the full SHA
    32d55c7 View commit details
  2. chore(deps): bump tar from 4.4.13 to 4.4.15 (#306)

    Bumps [tar](https://github.com/npm/node-tar) from 4.4.13 to 4.4.15.
    - [Release notes](https://github.com/npm/node-tar/releases)
    - [Changelog](https://github.com/npm/node-tar/blob/main/CHANGELOG.md)
    - [Commits](isaacs/node-tar@v4.4.13...v4.4.15)
    
    ---
    updated-dependencies:
    - dependency-name: tar
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Aug 19, 2021
    Copy the full SHA
    000a172 View commit details
  3. chore(deps): bump path-parse from 1.0.6 to 1.0.7 (#307)

    Bumps [path-parse](https://github.com/jbgutierrez/path-parse) from 1.0.6 to 1.0.7.
    - [Release notes](https://github.com/jbgutierrez/path-parse/releases)
    - [Commits](https://github.com/jbgutierrez/path-parse/commits/v1.0.7)
    
    ---
    updated-dependencies:
    - dependency-name: path-parse
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Aug 19, 2021
    Copy the full SHA
    e9083af View commit details
  4. Copy the full SHA
    eef682a View commit details
  5. Copy the full SHA
    eaea63f View commit details

Commits on Jan 4, 2022

  1. Copy the full SHA
    e513c55 View commit details
  2. Copy the full SHA
    8f7b2dd View commit details
  3. Copy the full SHA
    edf564f View commit details
  4. Copy the full SHA
    e7bb635 View commit details
  5. Copy the full SHA
    d8124ff View commit details
  6. Copy the full SHA
    d551cc1 View commit details
  7. feat: allow setting a custom iframe title (#317)

    This allows for better accessibility especially for screen readers.
    
    See https://www.w3.org/TR/WCAG20-TECHS/H64.html.
    pcorpet authored Jan 4, 2022
    Copy the full SHA
    c563e8b View commit details
  8. Merge pull request #309 from tjallingt/canary

    chore: release
    tjallingt authored Jan 4, 2022
    Copy the full SHA
    863ee32 View commit details
Showing with 192 additions and 132 deletions.
  1. +5 −4 .github/workflows/deploy.yml
  2. +5 −4 .github/workflows/release.yml
  3. +4 −3 .github/workflows/tests.yml
  4. +1 −0 .nvmrc
  5. +1 −0 README.md
  6. +2 −0 index.d.ts
  7. +27 −4 src/YouTube.js
  8. +55 −0 src/Youtube.test.js
  9. +92 −117 yarn.lock
9 changes: 5 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -11,12 +11,13 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js 14
uses: actions/setup-node@v1
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 14.x
node-version-file: '.nvmrc'
cache: 'yarn'
- name: Install dependencies
uses: bahmutov/npm-install@v1
run: yarn install
- name: Build example
run: yarn example:build
- name: Deploy to GitHub pages
9 changes: 5 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -12,12 +12,13 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js 14
uses: actions/setup-node@v1
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 14.x
node-version-file: '.nvmrc'
cache: 'yarn'
- name: Install dependencies
uses: bahmutov/npm-install@v1
run: yarn install
- name: Run tests
run: yarn test
- name: Build
7 changes: 4 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -8,15 +8,16 @@ jobs:
name: Node.js ${{ matrix.node }}
strategy:
matrix:
node: ["10.x", "11.x", "12.x", "13.x", "14.x", "15.x"]
node: ['10.x', '11.x', '12.x', '13.x', '14.x', '15.x', '16.x', '17.x']
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node.js ${{ matrix.node }}
uses: actions/setup-node@v1
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
cache: 'yarn'
- name: Install dependencies
uses: bahmutov/npm-install@v1
run: yarn install
- name: Run tests
run: yarn test:ci
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16.13
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ $ npm install react-youtube
id={string} // defaults -> null
className={string} // defaults -> null
containerClassName={string} // defaults -> ''
title={string} // defaults -> null
opts={obj} // defaults -> {}
onReady={func} // defaults -> noop
onPlay={func} // defaults -> noop
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -37,6 +37,8 @@ export interface YouTubeProps {
id?: string;
className?: string;
containerClassName?: string;
title?: string;
loading?: 'lazy' | 'eager' | 'auto';
opts?: Options;
onReady?(event: { target: YouTubePlayer }): void;
onError?(event: { target: YouTubePlayer; data: number }): void;
31 changes: 27 additions & 4 deletions src/YouTube.js
Original file line number Diff line number Diff line change
@@ -33,11 +33,13 @@ function shouldUpdateVideo(prevProps, props) {
function filterResetOptions(opts) {
return {
...opts,
height: 0,
width: 0,
playerVars: {
...opts.playerVars,
autoplay: 0,
start: 0,
end: 0,
...opts.playerVars,
},
};
}
@@ -52,7 +54,9 @@ function filterResetOptions(opts) {
* @param {Object} props
*/
function shouldResetPlayer(prevProps, props) {
return !isEqual(filterResetOptions(prevProps.opts), filterResetOptions(props.opts));
return (
prevProps.videoId !== props.videoId || !isEqual(filterResetOptions(prevProps.opts), filterResetOptions(props.opts))
);
}

/**
@@ -62,7 +66,13 @@ function shouldResetPlayer(prevProps, props) {
* @param {Object} props
*/
function shouldUpdatePlayer(prevProps, props) {
return prevProps.id !== props.id || prevProps.className !== props.className;
return (
prevProps.id !== props.id ||
prevProps.className !== props.className ||
prevProps.opts.width !== props.opts.width ||
prevProps.opts.height !== props.opts.height ||
prevProps.title !== props.title
);
}

class YouTube extends React.Component {
@@ -213,6 +223,12 @@ class YouTube extends React.Component {
else iframe.removeAttribute('id');
if (this.props.className) iframe.setAttribute('class', this.props.className);
else iframe.removeAttribute('class');
if (this.props.opts && this.props.opts.width) iframe.setAttribute('width', this.props.opts.width);
else iframe.removeAttribute('width');
if (this.props.opts && this.props.opts.height) iframe.setAttribute('height', this.props.opts.height);
else iframe.removeAttribute('height');
if (typeof this.props.title === 'string') iframe.setAttribute('title', this.props.title);
else iframe.setAttribute('title', 'YouTube video player');
});
};

@@ -265,7 +281,7 @@ class YouTube extends React.Component {
render() {
return (
<div className={this.props.containerClassName}>
<div id={this.props.id} className={this.props.className} ref={this.refContainer} />
<div id={this.props.id} className={this.props.className} ref={this.refContainer} loading={this.props.loading} />
</div>
);
}
@@ -281,6 +297,11 @@ YouTube.propTypes = {
className: PropTypes.string,
// custom class name for player container element
containerClassName: PropTypes.string,
// custom title for the iFrame, see https://www.w3.org/TR/WCAG20-TECHS/H64.html
title: PropTypes.string,

// custom loading for player element
loading: PropTypes.oneOf(['lazy', 'eager', 'auto']),

// https://developers.google.com/youtube/iframe_api_reference#Loading_a_Video_Player
opts: PropTypes.objectOf(PropTypes.any),
@@ -300,6 +321,7 @@ YouTube.defaultProps = {
videoId: null,
id: null,
className: null,
loading: null,
opts: {},
containerClassName: '',
onReady: () => {},
@@ -310,6 +332,7 @@ YouTube.defaultProps = {
onStateChange: () => {},
onPlaybackRateChange: () => {},
onPlaybackQualityChange: () => {},
title: null,
};

export default YouTube;
55 changes: 55 additions & 0 deletions src/Youtube.test.js
Original file line number Diff line number Diff line change
@@ -44,6 +44,22 @@ describe('YouTube', () => {
expect(playerMock.getIframe).toHaveBeenCalled();
});

it('should update the title when modified', () => {
const { rerender } = render(<YouTube title="Video about a cat" videoId="XxVg_s8xAms" />);

rerender(<YouTube title="Video about a dancing cat" videoId="XxVg_s8xAms" />);

expect(playerMock.getIframe).toHaveBeenCalled();
});

it('should update the title when removed', () => {
const { rerender } = render(<YouTube title="Video about a cat" videoId="XxVg_s8xAms" />);

rerender(<YouTube videoId="XxVg_s8xAms" />);

expect(playerMock.getIframe).toHaveBeenCalled();
});

it('should not update id and className when no change in them', () => {
const className = 'custom-class';
const videoId = 'XxVg_s8xAms';
@@ -117,6 +133,8 @@ describe('YouTube', () => {
width: '480px',
height: '360px',
playerVars: {
height: 0, // changed, does not force destroy & rebind
width: 0, // changed, does not force destroy & rebind
autoplay: 1, // changed, does not force destroy & rebind
start: 10, // changed, does not force destroy & rebind
end: 20, // changed, does not force destroy & rebind
@@ -127,6 +145,43 @@ describe('YouTube', () => {

// player is destroyed & rebound, despite the changes
expect(playerMock.destroy).toHaveBeenCalled();
// and the video is updated
expect(playerMock.loadVideoById).toHaveBeenCalled();
});

it('should not create and bind a new YouTube player when only playerVars.autoplay, playerVars.start, or playerVars.end change', () => {
const { rerender } = render(
<YouTube
videoId="XxVg_s8xAms"
opts={{
width: '480px',
height: '360px',
playerVars: {
autoplay: 0,
start: 0,
end: 50,
},
}}
/>,
);

rerender(
<YouTube
videoId="XxVg_s8xAms"
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).not.toHaveBeenCalled();
// instead only the video is updated
expect(playerMock.loadVideoById).toHaveBeenCalled();
});
Loading