Skip to content

Commit 92a4093

Browse files
committed
feat: deprecate react 15 support, support react 16 features
- use UNSAFE_ for one componentWillUpdateProps - refact for another componentWillUpdateProps - deprecate peer resolution for react 15 - dev dependencies bumped to react 16 - react-test-renderer and enzyme bumped to react 16 Created-By: @ryan-m-walker, @acao BREAKING CHANGE: Deprecate support for React 15. Please use React 16.8 or greater for hooks support.
1 parent de4005b commit 92a4093

File tree

6 files changed

+95
-157
lines changed

6 files changed

+95
-157
lines changed

examples/graphiql-webpack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"express-graphql": "^0.9.0",
1414
"graphiql": "file:../../packages/graphiql",
1515
"graphql": "14.5.8",
16-
"react": "16.10.2"
16+
"react": "16.12.0"
1717
},
1818
"devDependencies": {
1919
"@babel/plugin-proposal-class-properties": "7.7.4",

packages/graphiql/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@
5151
"peerDependencies": {
5252
"graphql": "^0.12.0 || ^0.13.0 || ^14.0.0",
5353
"prop-types": ">=15.5.0",
54-
"react": "^15.6.0 || ^16.0.0",
55-
"react-dom": "^15.6.0 || ^16.0.0"
54+
"react": "^16.8.0",
55+
"react-dom": "^16.8.0"
5656
},
5757
"devDependencies": {
5858
"cross-env": "^6.0.3",
5959
"css-loader": "3.3.2",
6060
"cssnano": "^4.1.10",
61-
"enzyme": "^3.9.0",
62-
"enzyme-adapter-react-15": "^1.4.0",
61+
"enzyme": "^3.10.0",
62+
"enzyme-adapter-react-16": "^1.15.1",
6363
"express": "5.0.0-alpha.5",
6464
"express-graphql": "0.9.0",
6565
"graphql": "14.5.8",
@@ -72,10 +72,10 @@
7272
"postcss-loader": "^3.0.0",
7373
"postcss-preset-env": "^6.7.0",
7474
"prop-types": "15.7.2",
75-
"react": "15.6.2",
76-
"react-dom": "15.6.2",
75+
"react": "^16.12.0",
76+
"react-dom": "^16.12.0",
7777
"react-hot-loader": "^4.12.18",
78-
"react-test-renderer": "15.6.2",
78+
"react-test-renderer": "^16.12.0",
7979
"rimraf": "^3.0.0",
8080
"serve": "^11.2.0",
8181
"start-server-and-test": "^1.10.6",

packages/graphiql/src/components/GraphiQL.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ import {
3939

4040
const DEFAULT_DOC_EXPLORER_WIDTH = 350;
4141

42+
// eslint-disable-next-line no-console
43+
const logger = console.log;
44+
45+
if (!React.version || !React.version.indexOf('16') < 0) {
46+
logger.warn(
47+
[
48+
'GraphiQL 0.18.0 and after is not compatible with React 15 or below.',
49+
'If you are using a CDN source (jsdelivr, unpkg, etc), follow this example:',
50+
'https://github.com/graphql/graphiql/blob/master/examples/graphiql-cdn/index.html#L49',
51+
].join('\n'),
52+
);
53+
}
54+
4255
/**
4356
* The top-level React component for GraphiQL, intended to encompass the entire
4457
* browser viewport.
@@ -171,8 +184,9 @@ export class GraphiQL extends React.Component {
171184

172185
global.g = this;
173186
}
174-
175-
componentWillReceiveProps(nextProps) {
187+
// todo: these values should be updated in a reducer imo
188+
// eslint-disable-next-line camelcase
189+
UNSAFE_componentWillReceiveProps(nextProps) {
176190
let nextSchema = this.state.schema;
177191
let nextQuery = this.state.query;
178192
let nextVariables = this.state.variables;

packages/graphiql/src/components/QueryHistory.js

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,26 @@ import HistoryQuery from './HistoryQuery';
1414
const MAX_QUERY_SIZE = 100000;
1515
const MAX_HISTORY_LENGTH = 20;
1616

17-
const shouldSaveQuery = (nextProps, current, lastQuerySaved) => {
18-
if (nextProps.queryID === current.queryID) {
19-
return false;
20-
}
17+
const shouldSaveQuery = (query, variables, lastQuerySaved) => {
2118
try {
22-
parse(nextProps.query);
19+
parse(query);
2320
} catch (e) {
2421
return false;
2522
}
2623
// Don't try to save giant queries
27-
if (nextProps.query.length > MAX_QUERY_SIZE) {
24+
if (query.length > MAX_QUERY_SIZE) {
2825
return false;
2926
}
3027
if (!lastQuerySaved) {
3128
return true;
3229
}
33-
if (
34-
JSON.stringify(nextProps.query) === JSON.stringify(lastQuerySaved.query)
35-
) {
30+
if (JSON.stringify(query) === JSON.stringify(lastQuerySaved.query)) {
3631
if (
37-
JSON.stringify(nextProps.variables) ===
38-
JSON.stringify(lastQuerySaved.variables)
32+
JSON.stringify(variables) === JSON.stringify(lastQuerySaved.variables)
3933
) {
4034
return false;
4135
}
42-
if (!nextProps.variables && !lastQuerySaved.variables) {
36+
if (variables && !lastQuerySaved.variables) {
4337
return false;
4438
}
4539
}
@@ -71,25 +65,6 @@ export class QueryHistory extends React.Component {
7165
this.state = { queries };
7266
}
7367

74-
componentWillReceiveProps(nextProps) {
75-
if (
76-
shouldSaveQuery(nextProps, this.props, this.historyStore.fetchRecent())
77-
) {
78-
const item = {
79-
query: nextProps.query,
80-
variables: nextProps.variables,
81-
operationName: nextProps.operationName,
82-
};
83-
this.historyStore.push(item);
84-
const historyQueries = this.historyStore.items;
85-
const favoriteQueries = this.favoriteStore.items;
86-
const queries = historyQueries.concat(favoriteQueries);
87-
this.setState({
88-
queries,
89-
});
90-
}
91-
}
92-
9368
render() {
9469
const queries = this.state.queries.slice().reverse();
9570
const queryNodes = queries.map((query, i) => {
@@ -114,6 +89,22 @@ export class QueryHistory extends React.Component {
11489
);
11590
}
11691

92+
updateHistory = (query, variables, operationName) => {
93+
if (shouldSaveQuery(query, variables, this.historyStore.fetchRecent())) {
94+
this.historyStore.push({
95+
query,
96+
variables,
97+
operationName,
98+
});
99+
const historyQueries = this.historyStore.items;
100+
const favoriteQueries = this.favoriteStore.items;
101+
const queries = historyQueries.concat(favoriteQueries);
102+
this.setState({
103+
queries,
104+
});
105+
}
106+
};
107+
117108
toggleFavorite = (query, variables, operationName, label, favorite) => {
118109
const item = {
119110
query,

resources/enzyme.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require('@babel/polyfill', {
1212

1313
// if (process.env.ENZYME) {
1414
const { configure } = require('enzyme');
15-
const Adapter = require('enzyme-adapter-react-15');
15+
const Adapter = require('enzyme-adapter-react-16');
1616
configure({ adapter: new Adapter() });
1717
// }
1818

0 commit comments

Comments
 (0)