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

react 16 doesn't support version property #1435

Merged
merged 2 commits into from
Mar 10, 2022
Merged
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ Please follow the recommendations outlined at [keepachangelog.com](http://keepac
Changes since last non-beta release.

*Please add entries here for your pull requests that are not yet released.*
### [13.0.2] - 2022-03-09
#### Fixed
- React 16 doesn't support version property, causing problems loading React on Rails. [PR 1435](https://github.com/shakacode/react_on_rails/pull/1435) by [justin808](https://github.com/justin808).

### [13.0.1] - 2022-02-09
#### Improved
- Updated the default generator [PR 1431](https://github.com/shakacode/react_on_rails/pull/1431) by [justin808](https://github.com/justin808).
- Updated the default generator. [PR 1431](https://github.com/shakacode/react_on_rails/pull/1431) by [justin808](https://github.com/justin808).

### [13.0.0] - 2022-02-08
#### Breaking
Expand Down
4 changes: 0 additions & 4 deletions node_package/src/supportsReactCreateRoot.js

This file was deleted.

8 changes: 8 additions & 0 deletions node_package/src/supportsReactCreateRoot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import ReactDOM from 'react-dom';

export const isVersionGreaterThanOrEqualTo18 = (): boolean => (
ReactDOM.version && parseInt(ReactDOM.version.split('.')[0], 10) >= 18 ||
false
)

export default isVersionGreaterThanOrEqualTo18();
44 changes: 44 additions & 0 deletions node_package/tests/supportsReactCreateRoot.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import ReactDOM from 'react-dom';
import { isVersionGreaterThanOrEqualTo18 } from '../src/supportsReactCreateRoot';

describe('supportsReactCreateRoot', () => {
it('returns false for ReactDOM v16, no version', () => {
expect.assertions(1);
const originalValue = ReactDOM.version;
delete ReactDOM.version;
expect(isVersionGreaterThanOrEqualTo18()).toBe(false);
ReactDOM.version = originalValue;
});

it('returns false for ReactDOM v17', () => {
const originalValue = ReactDOM.version;
ReactDOM.version = '17.0.0';
expect.assertions(1);
expect(isVersionGreaterThanOrEqualTo18()).toBe(false);
ReactDOM.version = originalValue;
});

it('returns true for ReactDOM v18', () => {
expect.assertions(1);
const originalValue = ReactDOM.version;
ReactDOM.version = '18.0.0';
expect(isVersionGreaterThanOrEqualTo18()).toBe(true);
ReactDOM.version = originalValue;
});

it('returns true for ReactDOM v19', () => {
expect.assertions(1);
const originalValue = ReactDOM.version;
ReactDOM.version = '19.0.0';
expect(isVersionGreaterThanOrEqualTo18()).toBe(true);
ReactDOM.version = originalValue;
});

it('returns true for ReactDOM v18 beta', () => {
expect.assertions(1);
const originalValue = ReactDOM.version;
ReactDOM.version = '18.0.0-rc.2';
expect(isVersionGreaterThanOrEqualTo18()).toBe(true);
ReactDOM.version = originalValue;
});
});