diff --git a/.all-contributorsrc b/.all-contributorsrc index 95c5605e5..e9b11effc 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -84,7 +84,8 @@ "question", "bug", "code", - "content" + "content", + "review" ] }, { diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b56206ac6..958f4e90c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -60,7 +60,7 @@ For more information on `@all-contributors` see it's [usage docs](https://allcon ### Release process: - `npm test` -- `npm run release` +- `NPM_CONFIG_OTP= npm run release` Follow the prompts from [`lerna publish`](https://lernajs.io/#command-publish) diff --git a/README.md b/README.md index 664c6fd0a..2e10f38fb 100644 --- a/README.md +++ b/README.md @@ -466,7 +466,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d -| [Brian Mullan
Brian Mullan](https://twitter.com/bmullan91)
[💬](#question-bmullan91 "Answering Questions") [🐛](https://github.com/nearform/graphql-hooks/issues?q=author%3Abmullan91 "Bug reports") [💻](https://github.com/nearform/graphql-hooks/commits?author=bmullan91 "Code") [🖋](#content-bmullan91 "Content") [📖](https://github.com/nearform/graphql-hooks/commits?author=bmullan91 "Documentation") [💡](#example-bmullan91 "Examples") [🤔](#ideas-bmullan91 "Ideas, Planning, & Feedback") [🚧](#maintenance-bmullan91 "Maintenance") [👀](#review-bmullan91 "Reviewed Pull Requests") [⚠️](https://github.com/nearform/graphql-hooks/commits?author=bmullan91 "Tests") | [Jack Clark
Jack Clark](https://jackdc.com)
[💬](#question-jackdclark "Answering Questions") [🐛](https://github.com/nearform/graphql-hooks/issues?q=author%3Ajackdclark "Bug reports") [💻](https://github.com/nearform/graphql-hooks/commits?author=jackdclark "Code") [🖋](#content-jackdclark "Content") [📖](https://github.com/nearform/graphql-hooks/commits?author=jackdclark "Documentation") [💡](#example-jackdclark "Examples") [🤔](#ideas-jackdclark "Ideas, Planning, & Feedback") [🚧](#maintenance-jackdclark "Maintenance") [👀](#review-jackdclark "Reviewed Pull Requests") [⚠️](https://github.com/nearform/graphql-hooks/commits?author=jackdclark "Tests") | [Joe Warren
Joe Warren](http://twitter.com/joezo)
[💬](#question-Joezo "Answering Questions") [🐛](https://github.com/nearform/graphql-hooks/issues?q=author%3AJoezo "Bug reports") [💻](https://github.com/nearform/graphql-hooks/commits?author=Joezo "Code") [🖋](#content-Joezo "Content") [📖](https://github.com/nearform/graphql-hooks/commits?author=Joezo "Documentation") [💡](#example-Joezo "Examples") [🤔](#ideas-Joezo "Ideas, Planning, & Feedback") [🚧](#maintenance-Joezo "Maintenance") [👀](#review-Joezo "Reviewed Pull Requests") [⚠️](https://github.com/nearform/graphql-hooks/commits?author=Joezo "Tests") | [Simone Busoli
Simone Busoli](http://simoneb.github.io)
[💬](#question-simoneb "Answering Questions") [🐛](https://github.com/nearform/graphql-hooks/issues?q=author%3Asimoneb "Bug reports") [📖](https://github.com/nearform/graphql-hooks/commits?author=simoneb "Documentation") | [jhey tompkins
jhey tompkins](https://jheytompkins.com)
[⚠️](https://github.com/nearform/graphql-hooks/commits?author=jh3y "Tests") [💬](#question-jh3y "Answering Questions") [🐛](https://github.com/nearform/graphql-hooks/issues?q=author%3Ajh3y "Bug reports") [💻](https://github.com/nearform/graphql-hooks/commits?author=jh3y "Code") [🖋](#content-jh3y "Content") | [Haroen Viaene
Haroen Viaene](https://haroen.me)
[🐛](https://github.com/nearform/graphql-hooks/issues?q=author%3AHaroenv "Bug reports") | +| [Brian Mullan
Brian Mullan](https://twitter.com/bmullan91)
[💬](#question-bmullan91 "Answering Questions") [🐛](https://github.com/nearform/graphql-hooks/issues?q=author%3Abmullan91 "Bug reports") [💻](https://github.com/nearform/graphql-hooks/commits?author=bmullan91 "Code") [🖋](#content-bmullan91 "Content") [📖](https://github.com/nearform/graphql-hooks/commits?author=bmullan91 "Documentation") [💡](#example-bmullan91 "Examples") [🤔](#ideas-bmullan91 "Ideas, Planning, & Feedback") [🚧](#maintenance-bmullan91 "Maintenance") [👀](#review-bmullan91 "Reviewed Pull Requests") [⚠️](https://github.com/nearform/graphql-hooks/commits?author=bmullan91 "Tests") | [Jack Clark
Jack Clark](https://jackdc.com)
[💬](#question-jackdclark "Answering Questions") [🐛](https://github.com/nearform/graphql-hooks/issues?q=author%3Ajackdclark "Bug reports") [💻](https://github.com/nearform/graphql-hooks/commits?author=jackdclark "Code") [🖋](#content-jackdclark "Content") [📖](https://github.com/nearform/graphql-hooks/commits?author=jackdclark "Documentation") [💡](#example-jackdclark "Examples") [🤔](#ideas-jackdclark "Ideas, Planning, & Feedback") [🚧](#maintenance-jackdclark "Maintenance") [👀](#review-jackdclark "Reviewed Pull Requests") [⚠️](https://github.com/nearform/graphql-hooks/commits?author=jackdclark "Tests") | [Joe Warren
Joe Warren](http://twitter.com/joezo)
[💬](#question-Joezo "Answering Questions") [🐛](https://github.com/nearform/graphql-hooks/issues?q=author%3AJoezo "Bug reports") [💻](https://github.com/nearform/graphql-hooks/commits?author=Joezo "Code") [🖋](#content-Joezo "Content") [📖](https://github.com/nearform/graphql-hooks/commits?author=Joezo "Documentation") [💡](#example-Joezo "Examples") [🤔](#ideas-Joezo "Ideas, Planning, & Feedback") [🚧](#maintenance-Joezo "Maintenance") [👀](#review-Joezo "Reviewed Pull Requests") [⚠️](https://github.com/nearform/graphql-hooks/commits?author=Joezo "Tests") | [Simone Busoli
Simone Busoli](http://simoneb.github.io)
[💬](#question-simoneb "Answering Questions") [🐛](https://github.com/nearform/graphql-hooks/issues?q=author%3Asimoneb "Bug reports") [📖](https://github.com/nearform/graphql-hooks/commits?author=simoneb "Documentation") | [jhey tompkins
jhey tompkins](https://jheytompkins.com)
[⚠️](https://github.com/nearform/graphql-hooks/commits?author=jh3y "Tests") [💬](#question-jh3y "Answering Questions") [🐛](https://github.com/nearform/graphql-hooks/issues?q=author%3Ajh3y "Bug reports") [💻](https://github.com/nearform/graphql-hooks/commits?author=jh3y "Code") [🖋](#content-jh3y "Content") [👀](#review-jh3y "Reviewed Pull Requests") | [Haroen Viaene
Haroen Viaene](https://haroen.me)
[🐛](https://github.com/nearform/graphql-hooks/issues?q=author%3AHaroenv "Bug reports") | | :---: | :---: | :---: | :---: | :---: | :---: | diff --git a/lerna.json b/lerna.json index 7926728a6..60e971f40 100644 --- a/lerna.json +++ b/lerna.json @@ -1,4 +1,9 @@ { "packages": ["packages/*"], - "version": "independent" + "version": "independent", + "command": { + "bootstrap": { + "npmClientArgs": ["--no-package-lock"] + } + } } diff --git a/package.json b/package.json index cf6fe88c5..3daced6ab 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "eslint-plugin-prettier": "3.0.1", "eslint-plugin-react-hooks": "1.4.0", "eslint-plugin-react": "7.12.4", - "eslint": "5.15.0", + "eslint": "5.15.1", "husky": "1.3.1", "jest": "24.1.0", "lerna": "3.13.1", diff --git a/packages/graphql-hooks-memcache/package.json b/packages/graphql-hooks-memcache/package.json index 580dea521..641aee867 100644 --- a/packages/graphql-hooks-memcache/package.json +++ b/packages/graphql-hooks-memcache/package.json @@ -1,10 +1,12 @@ { "name": "graphql-hooks-memcache", - "version": "1.0.5", + "version": "1.0.7", "description": "In memory cache for graphql-hooks", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "prepublishOnly": "cp ../../LICENSE .", + "postpublish": "rm ./LICENSE" }, "keywords": [ "graphql", diff --git a/packages/graphql-hooks-ssr/package.json b/packages/graphql-hooks-ssr/package.json index e4e75a582..b0afcd620 100644 --- a/packages/graphql-hooks-ssr/package.json +++ b/packages/graphql-hooks-ssr/package.json @@ -1,10 +1,12 @@ { "name": "graphql-hooks-ssr", - "version": "1.0.1", + "version": "1.0.3", "description": "Server side rendering utils for graphql-hooks", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 0" + "test": "echo \"Error: no test specified\" && exit 0", + "prepublishOnly": "cp ../../LICENSE .", + "postpublish": "rm ./LICENSE" }, "keywords": [ "graphql", @@ -21,7 +23,6 @@ "react": "^16.8.1", "react-dom": "^16.8.1" }, - "dependencies": {}, "devDependencies": { "react": "16.8.3", "react-dom": "16.8.3" diff --git a/packages/graphql-hooks/package.json b/packages/graphql-hooks/package.json index 3102bb919..c61d15a06 100644 --- a/packages/graphql-hooks/package.json +++ b/packages/graphql-hooks/package.json @@ -1,13 +1,14 @@ { "name": "graphql-hooks", - "version": "3.2.2", + "version": "3.2.4", "description": "Graphql Hooks", "main": "lib/graphql-hooks.js", "module": "es/graphql-hooks.js", "unpkg": "dist/graphql-hooks.min.js", "scripts": { "build": "rollup -c", - "prepublishOnly": "npm run build" + "prepublishOnly": "npm run build && cp ../../README.md . && cp ../../LICENSE .", + "postpublish": "rm ./README.md && rm ./LICENSE" }, "files": [ "dist", diff --git a/packages/graphql-hooks/src/useClientRequest.js b/packages/graphql-hooks/src/useClientRequest.js index c866ece10..6970fc4e1 100644 --- a/packages/graphql-hooks/src/useClientRequest.js +++ b/packages/graphql-hooks/src/useClientRequest.js @@ -52,6 +52,7 @@ function reducer(state, action) { */ function useClientRequest(query, initialOpts = {}) { const client = React.useContext(ClientContext); + const isMounted = React.useRef(true); const operation = { query, variables: initialOpts.variables, @@ -73,10 +74,19 @@ function useClientRequest(query, initialOpts = {}) { // if so the state would be invalid, this effect ensures we reset it back const stringifiedCacheKey = JSON.stringify(cacheKey); React.useEffect(() => { - if (initialOpts.updateData) return; // if using updateData we can assume that the consumer cares about the previous data - dispatch({ type: actionTypes.RESET_STATE, initialState }); + if (!initialOpts.updateData) { + // if using updateData we can assume that the consumer cares about the previous data + dispatch({ type: actionTypes.RESET_STATE, initialState }); + } }, [stringifiedCacheKey]); // eslint-disable-line react-hooks/exhaustive-deps + React.useEffect(() => { + isMounted.current = true; + return () => { + isMounted.current = false; + }; + }, []); + // arguments to fetchData override the useClientRequest arguments function fetchData(newOpts) { const revisedOpts = { @@ -118,10 +128,12 @@ function useClientRequest(query, initialOpts = {}) { client.cache.set(revisedCacheKey, result); } - dispatch({ - type: actionTypes.REQUEST_RESULT, - result - }); + if (isMounted.current) { + dispatch({ + type: actionTypes.REQUEST_RESULT, + result + }); + } return result; }); diff --git a/packages/graphql-hooks/test/unit/useClientRequest.test.js b/packages/graphql-hooks/test/unit/useClientRequest.test.js index 4482213f1..b16054c77 100644 --- a/packages/graphql-hooks/test/unit/useClientRequest.test.js +++ b/packages/graphql-hooks/test/unit/useClientRequest.test.js @@ -205,6 +205,30 @@ describe('useClientRequest', () => { expect(state).toEqual({ cacheHit: false, loading: false, data: 'data' }); }); + it('calls request with options & doesnt update state if component unmounts whilst request is in flight', async () => { + let fetchData, state; + const { unmount } = renderHook( + () => + ([fetchData, state] = useClientRequest(TEST_QUERY, { + variables: { limit: 2 }, + operationName: 'test' + })), + { + wrapper: Wrapper + } + ); + + const fetchDataPromise = fetchData(); + unmount(); + await fetchDataPromise; + + expect(mockClient.request).toHaveBeenCalledWith( + { operationName: 'test', variables: { limit: 2 }, query: TEST_QUERY }, + { operationName: 'test', variables: { limit: 2 } } + ); + expect(state).toEqual({ cacheHit: false, loading: true }); + }); + it('calls request with revised options', async () => { let fetchData; renderHook(