Skip to content

Add React 19.x to supported versions #286

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

Open
wants to merge 2 commits into
base: default
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
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
react-version: [17.x, 18.x]
react-version: [17.x, 18.x, 19.x]
include:
- node-version: 12.x
react-version: 16.0.0
Expand All @@ -53,10 +53,11 @@ jobs:
- name: Install dependencies
run: npm install
- name: Install React ${{matrix.react-version}}
if: matrix.react-version != '18.x'
if: matrix.react-version != '19.x'
run: |
npm install --save-dev \
react@${{matrix.react-version}} \
react-dom@${{matrix.react-version}}
react-dom@${{matrix.react-version}}\
@types/react@${{matrix.react-version}}
- name: Run tests
run: npm run tests-only
6 changes: 3 additions & 3 deletions example/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-env browser */
import React from 'react';
import ReactDOM from 'react-dom';
import ReactDOM from 'react-dom/client';
import YouTube from '@u-wave/react-youtube'; // eslint-disable-line import/no-unresolved

const {
Expand Down Expand Up @@ -128,5 +128,5 @@ function App() {
);
}

// eslint-disable-next-line react/no-deprecated
ReactDOM.render(<App />, document.getElementById('example'));
const root = ReactDOM.createRoot(document.getElementById('example'));
root.render(<App />);
4 changes: 2 additions & 2 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"dependencies": {
"@u-wave/react-youtube": "file:..",
"esbuild": "^0.14.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"serve": "^13.0.0"
}
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/u-wave/react-youtube/issues"
},
"dependencies": {
"@types/react": "^17.0.0",
"@types/react": "^17.0.0 || ^18.0.0 || ^19.0.0",
"@types/youtube": "0.0.50",
"load-script2": "^1.0.1",
"prop-types": "^15.7.2"
Expand All @@ -33,8 +33,8 @@
"mocha": "^10.0.0",
"prop-types-table": "^1.0.0",
"proxyquire": "^2.1.3",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"rollup": "^2.0.2",
"tsd": "^0.31.0"
},
Expand All @@ -51,7 +51,7 @@
"module": "dist/react-youtube.es.js",
"types": "index.d.ts",
"peerDependencies": {
"react": "^0.14.0 || ^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0"
"react": "^0.14.0 || ^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
},
"repository": {
"type": "git",
Expand Down
36 changes: 25 additions & 11 deletions test/util/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import React from 'react';
import ReactDOM from 'react-dom';
// Doing this after React is loaded makes React do a bit less DOM work
import 'min-react-env/install';
import env from 'min-react-env';
import createYouTube from './createYouTube';

Object.assign(global, env);
const reactMajor = parseInt((ReactDOM.version || '16').split('.')[0], 10);

const render = (initialProps) => {
async function render(initialProps) {
const { YouTube, sdkMock, playerMock } = createYouTube();

let component;
Expand All @@ -36,18 +35,33 @@ const render = (initialProps) => {
}
}

const div = env.document.createElement('div');
const container = new Promise((resolve) => {
// eslint-disable-next-line react/no-deprecated
ReactDOM.render(<Container {...initialProps} ref={resolve} />, div);
const div = document.createElement('div');
let root;
if (reactMajor >= 18) {
const { createRoot } = await import('react-dom/client');
root = createRoot(div);
} else {
root = {
render(element) {
// eslint-disable-next-line react/no-deprecated
ReactDOM.render(element, div);
},
unmount() {
// eslint-disable-next-line react/no-deprecated
ReactDOM.unmountComponentAtNode(div);
},
};
}
const container = await new Promise((resolve) => {
root.render(<Container {...initialProps} ref={resolve} />);
});

function rerender(newProps) {
return container.then((wrapper) => new Promise((resolve) => {
wrapper.setState({ props: newProps }, () => {
return new Promise((resolve) => {
container.setState({ props: newProps }, () => {
Promise.resolve().then(resolve);
});
}));
});
}

function unmount() {
Expand All @@ -62,6 +76,6 @@ const render = (initialProps) => {
rerender,
unmount,
}));
};
}

export default render;
Loading