-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Tweak types #1640
Tweak types #1640
Conversation
Author: YixuanXu <[email protected]> Date: Tue Nov 16 19:57:15 2021 +0800
Author: YixuanXu <[email protected]> Date: Tue Nov 16 19:58:38 2021 +0800
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 33dd46a:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make useSWR<{ id: number }>('/api/', (key) => ({ id: 123 })) still works as before
Which issue is this item trying to resolve? Could you elabrate?
What's the purpose of exporting OriginFetcher
and when will user use it?
Because the limitation of typescript. It could not support partial type argument inference // These two will works
useSWR<{ id: number }>('/api/', (key) => ({ id: 123 }))
useSWR<{ id: number }, any, string>('/api/', (key) => ({ id: 123 }))
useSWR<{ id: number }>('/api/', (key) => ({ id: 123 }))
// this would make fetcher's type fallback to
// ((args_0: string) => FetcherResponse<boolean>) | ((args_0: any, ...args_1: unknown[]) => FetcherResponse<boolean>) | ((args_0: Record<any, any>) => FetcherResponse<...>) | ((args_0: string | ... 2 more ... | Record<...>) => FetcherResponse<...>) | null'
// it would cause type error related issue #1518 (comment) I am trying to help user to avoid this limitation and make sure their code still works. So they could gradually adapt to the new type system
useSWRInfinite also uses this type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks like a great workaround! Can you add a test for the Data
inference case you mentioned?
Also regarding OriginFetcher
I think that BareFetcher
might be a better name.
❤️ |
Nice work! Thanks |
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [swr](https://swr.vercel.app) ([source](https://togithub.com/vercel/swr)) | [`1.0.1` -> `1.3.0`](https://renovatebot.com/diffs/npm/swr/1.0.1/1.3.0) | [![age](https://badges.renovateapi.com/packages/npm/swr/1.3.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/swr/1.3.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/swr/1.3.0/compatibility-slim/1.0.1)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/swr/1.3.0/confidence-slim/1.0.1)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>vercel/swr</summary> ### [`v1.3.0`](https://togithub.com/vercel/swr/releases/tag/1.3.0) [Compare Source](https://togithub.com/vercel/swr/compare/1.2.2...1.3.0) #### What's Changed - type: fix type error on SWRConfig by [@​Himself65](https://togithub.com/Himself65) in [#​1913](https://togithub.com/vercel/swr/issues/1913) - chore: update React 18 dependencies by [@​shuding](https://togithub.com/shuding) in [#​1824](https://togithub.com/vercel/swr/issues/1824) - test: fix an act warning by [@​koba04](https://togithub.com/koba04) in [#​1888](https://togithub.com/vercel/swr/issues/1888) - feat: support functional optimisticData by [@​huozhi](https://togithub.com/huozhi) in [#​1861](https://togithub.com/vercel/swr/issues/1861) - bugfix: make suspense and revalidateIfStale work together by [@​simowe](https://togithub.com/simowe) in [#​1851](https://togithub.com/vercel/swr/issues/1851) **Full Changelog**: vercel/swr@1.2.2...1.3.0 ### [`v1.2.2`](https://togithub.com/vercel/swr/releases/tag/1.2.2) [Compare Source](https://togithub.com/vercel/swr/compare/1.2.1...1.2.2) #### Highlights of This Release ##### `populateCache` Option Now Supports Function We added better Optimistic UI support in [v1.2.0](https://togithub.com/vercel/swr/releases/tag/1.2.0). However, what if your API is only returning a subset of the data (such as the mutated part), that can be populated into the cache? Usually, an extra revalidation after that mutation is needed. But now you can also use a function as `populateCache` to transform the mutate result into the full data: ```js await mutate(addTodo(newTodo), { optimisticData: [...data, newTodo], rollbackOnError: true, populateCache: (addedTodo, currentData) => { // `addedTodo` is what the API returns. It's not // returning a list of all current todos but only // the new added one. // In this case, we can transform the mutate result // together with current data, into the new data // that can be updated. return [...currentData, addedTodo]; }, // Since the API already gives us the updated information, // we don't need to revalidate here. revalidate: false, }); ``` The new definition: ```ts populateCache?: boolean | ((mutationResult: any, currentData: Data) => Data) ``` Here is a demo for it: https://codesandbox.io/s/swr-basic-forked-hi9svh ##### Bug Fixes #### What's Changed - refactor: revalidateIfStale has an effect on updates, not only mounting by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1837](https://togithub.com/vercel/swr/pull/1837) - fix: reset stale unmountedRef in suspense by [@​promer94](https://togithub.com/promer94) in [https://github.com/vercel/swr/pull/1843](https://togithub.com/vercel/swr/pull/1843) - test: add a test for the behavior of revalidateOnMount when the key has been changed by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1847](https://togithub.com/vercel/swr/pull/1847) - feat: Support `populateCache` as a function by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1818](https://togithub.com/vercel/swr/pull/1818) **Full Changelog**: vercel/swr@1.2.1...1.2.2 ### [`v1.2.1`](https://togithub.com/vercel/swr/releases/tag/1.2.1) [Compare Source](https://togithub.com/vercel/swr/compare/1.2.0...1.2.1) #### Highlights of This Release ##### `shouldRetryOnError` accepts a function Previously [`shouldRetryOnError`](https://swr.vercel.app/docs/error-handling#error-retry) is either true or false. Now it accepts a function that conditionally determines if SWR should retry. Here's a simple example: ```js const fetcher = url => fetch(url).then(res => { // Fetcher throws if the response code is not 2xx. if (!res.ok) throw res return res.json() }) useSWR(key, fetcher, { shouldRetryOnError: (error) => { // We skip retrying if the API is returning 404: if (error.status === 404) return false return true } }) ``` Thanks to [@​sairajchouhan](https://togithub.com/sairajchouhan) for contributing! #### What's Changed - `shouldRetryOnError` accepts a function that can be used to conditionally stop retrying by [@​sairajchouhan](https://togithub.com/sairajchouhan) in [https://github.com/vercel/swr/pull/1816](https://togithub.com/vercel/swr/pull/1816) - build(deps-dev): bump next from 12.0.8 to 12.0.9 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/vercel/swr/pull/1821](https://togithub.com/vercel/swr/pull/1821) - fix: useSWRInfinite revalidates with revalidateOnMount by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1830](https://togithub.com/vercel/swr/pull/1830) #### New Contributors - [@​sairajchouhan](https://togithub.com/sairajchouhan) made their first contribution in [https://github.com/vercel/swr/pull/1816](https://togithub.com/vercel/swr/pull/1816) **Full Changelog**: vercel/swr@1.2.0...1.2.1 ### [`v1.2.0`](https://togithub.com/vercel/swr/releases/tag/1.2.0) [Compare Source](https://togithub.com/vercel/swr/compare/1.1.2...1.2.0) #### Highlights of This Release ##### Optimistic Updates with Auto Error Rollback There are now some new options in `mutate`: ```js mutate(patchUser(user), { optimisticData: user, populateCache: true, rollbackOnError: true, revalidate: true, }) ``` Here the cache will be immediately updated to `user`, the “optimistic value”. And then a request (remote mutation) is started via `patchUser(user)` and the response will be written to the cache. If that request fails, the original result will be rolled back safely so the optimistic value will be gone. And after all those finish, a revalidation will start to fetch the latest value. This is extremely helpful for building the optimistic UI pattern. You can do the same for the global `mutate`, just remember to pass the key. Also, the current `mutate` APIs stay unchanged so `mutate(data, false)` works the same. Here's an example: https://codesandbox.io/s/swr-basic-forked-k5hps. https://user-images.githubusercontent.com/3676859/151381238-f3aba769-91b6-4bfc-9285-df1b9ef51773.mp4 ##### `.mjs` Support SWR now has `.mjs` exported for bundlers that prefer this format. This doesn’t break environments that don’t support `.mjs`. An alternative `.esm.js` and CJS bundle are also published. You can read more about ES modules [here](https://2ality.com/2017/05/es-module-specifiers.html). #### What's Changed - feat: Optimistic mutation with error rollback by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1745](https://togithub.com/vercel/swr/pull/1745) - fix: Required return type when mutating by [@​RKatarine](https://togithub.com/RKatarine) in [https://github.com/vercel/swr/pull/1772](https://togithub.com/vercel/swr/pull/1772) - fix: use the latest reference of fetcher with suspense mode by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1803](https://togithub.com/vercel/swr/pull/1803) - test: add delay for flaky focus test by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1762](https://togithub.com/vercel/swr/pull/1762) - test: remove flaky focus test case by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1793](https://togithub.com/vercel/swr/pull/1793) - test: use [@​swc/jest](https://togithub.com/swc/jest) by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1790](https://togithub.com/vercel/swr/pull/1790) - chore: Ignore coverage report by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1744](https://togithub.com/vercel/swr/pull/1744) - chore: Merge mutation states by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1748](https://togithub.com/vercel/swr/pull/1748) - chore: Rename CONCURRENT_REQUESTS to FETCH by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1749](https://togithub.com/vercel/swr/pull/1749) - chore: Merge extra request states in cache by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1752](https://togithub.com/vercel/swr/pull/1752) - chore: support mjs exports by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1760](https://togithub.com/vercel/swr/pull/1760) - chore: remove useless react-native field by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1761](https://togithub.com/vercel/swr/pull/1761) - chore: comment helper by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1757](https://togithub.com/vercel/swr/pull/1757) - chore: display name in devtool by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1779](https://togithub.com/vercel/swr/pull/1779) - chore: simplify example development by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1787](https://togithub.com/vercel/swr/pull/1787) - chore: build: improve watch commands by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1788](https://togithub.com/vercel/swr/pull/1788) - chore: Update examples and dependencies by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1789](https://togithub.com/vercel/swr/pull/1789) - chore: zeit -> vercel by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1791](https://togithub.com/vercel/swr/pull/1791) - chore: Clean up configurations by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1792](https://togithub.com/vercel/swr/pull/1792) - chore: move community health files to .github dir by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1794](https://togithub.com/vercel/swr/pull/1794) - chore: Add link to security email directly by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1795](https://togithub.com/vercel/swr/pull/1795) #### New Contributors - [@​RKatarine](https://togithub.com/RKatarine) made their first contribution in [https://github.com/vercel/swr/pull/1772](https://togithub.com/vercel/swr/pull/1772) **Full Changelog**: vercel/swr@1.1.2...1.2.0 ### [`v1.1.2`](https://togithub.com/vercel/swr/releases/tag/1.1.2) [Compare Source](https://togithub.com/vercel/swr/compare/1.1.1...1.1.2) #### Highlights of This Release ##### Use the Latest Fetcher Function SWR will now use the latest fetcher function passed to the hook, when sending the request. Previously it uses the initial snapshotted fetcher. ##### Avoid Unnecessary Auto Revalidations When refocusing on the window with state changes (like clicking a button that changes the SWR key immediately), SWR now avoids revalidations if they're not necessary. Details can be found in [#​1720](https://togithub.com/vercel/swr/issues/1720). ##### New Types for `useSWRInfinite` Two types for `useSWRInfinite` are added: `SWRInfinteHook` and `SWRInfinteKeyLoader`. You can use them to type the hook and the `getKey` function. ##### New `populateCache` option for `mutate` A new option to control if the mutation data should be written to the cache. You can find the details in [#​1729](https://togithub.com/vercel/swr/issues/1729). #### What's Changed - Make polyfill for `requestAnimationFrame` more robust by [@​thomaspaulmann](https://togithub.com/thomaspaulmann) in [https://github.com/vercel/swr/pull/1707](https://togithub.com/vercel/swr/pull/1707) - type(infinite): export SWRInfinteHook and SWRInfiniteKeyLoader from infinite, rename InfiniteFetcher to SWRInfiniteFetcher by [@​houkanshan](https://togithub.com/houkanshan) in [https://github.com/vercel/swr/pull/1714](https://togithub.com/vercel/swr/pull/1714) - feat: Ensure auto revalidations are executed after state updates by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1720](https://togithub.com/vercel/swr/pull/1720) - Add moduleNameMapper to jest by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1724](https://togithub.com/vercel/swr/pull/1724) - Improve test by [@​promer94](https://togithub.com/promer94) in [https://github.com/vercel/swr/pull/1725](https://togithub.com/vercel/swr/pull/1725) - feat: Use the latest reference of fetcher by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1727](https://togithub.com/vercel/swr/pull/1727) - fix: Re-export InfiniteFetcher by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1728](https://togithub.com/vercel/swr/pull/1728) - feat: Add `populateCache` option to `mutate` by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1729](https://togithub.com/vercel/swr/pull/1729) - Fix local state sharing example deps by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1737](https://togithub.com/vercel/swr/pull/1737) - Merge states for concurrent requests by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1741](https://togithub.com/vercel/swr/pull/1741) - Skip error retrying when document is not active and improve tests by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1742](https://togithub.com/vercel/swr/pull/1742) #### New Contributors - [@​thomaspaulmann](https://togithub.com/thomaspaulmann) made their first contribution in [https://github.com/vercel/swr/pull/1707](https://togithub.com/vercel/swr/pull/1707) - [@​houkanshan](https://togithub.com/houkanshan) made their first contribution in [https://github.com/vercel/swr/pull/1714](https://togithub.com/vercel/swr/pull/1714) **Full Changelog**: vercel/swr@1.1.1...1.1.2 ### [`v1.1.1`](https://togithub.com/vercel/swr/releases/tag/1.1.1) [Compare Source](https://togithub.com/vercel/swr/compare/1.1.0...1.1.1) #### Highlights of This Release ##### Dynamic `refreshInterval` You can now pass a function as `refreshInterval`, to dynamically return the interval (in millisecond) til the next request, based on the current data: ```typescript useSWR('key', fetcher, { refreshInterval: function (data: Data | undefined) { if (!data) return 3000 // Initial request return data.next_update } }) ``` If return `0`, polling will be stopped. #### What's Changed - feat: refreshInterval as a function by [@​Andrewnt219](https://togithub.com/Andrewnt219) in [https://github.com/vercel/swr/pull/1690](https://togithub.com/vercel/swr/pull/1690) - test: add refreshInterval function returns 0 by [@​Andrewnt219](https://togithub.com/Andrewnt219) in [https://github.com/vercel/swr/pull/1691](https://togithub.com/vercel/swr/pull/1691) - fix: If `newData` is deeply to the latest state, broadcast the latest state by [@​icyJoseph](https://togithub.com/icyJoseph) in [https://github.com/vercel/swr/pull/1697](https://togithub.com/vercel/swr/pull/1697) - fix: Return `undefined` data if key's falsy under suspense mode by [@​icyJoseph](https://togithub.com/icyJoseph) in [https://github.com/vercel/swr/pull/1698](https://togithub.com/vercel/swr/pull/1698) #### New Contributors - [@​Andrewnt219](https://togithub.com/Andrewnt219) made their first contribution in [https://github.com/vercel/swr/pull/1690](https://togithub.com/vercel/swr/pull/1690) - [@​icyJoseph](https://togithub.com/icyJoseph) made their first contribution in [https://github.com/vercel/swr/pull/1697](https://togithub.com/vercel/swr/pull/1697) **Full Changelog**: vercel/swr@1.1.0...1.1.1 ### [`v1.1.0`](https://togithub.com/vercel/swr/releases/tag/1.1.0) [Compare Source](https://togithub.com/vercel/swr/compare/1.0.1...1.1.0) #### Highlights for This Release ##### 1. Built-in & stable serialization for SWR keys ```js useSWR({ query: graphql`...`, variables }, fetcher) useSWR({ query: graphql`...`, variables }, fetcher) useSWR({ variables, query: graphql`...` }, fetcher) // ^all recognized as the same resource ``` For array keys too, it's safe to do the following: ```js useSWR([ `...`, { variables } ], fetcher) ``` ##### 2. `revalidateFirstPage` for `useSWRInfinite` This is a new added option for `useSWRInfinite` (defaults to `true`), you can use it to control if the first page should be revalidated when changing the size or doing a mutation. ##### 3. Better TypeScript support - Key / arguments - Conditional / dependent - Constant keys - Returned data ![image](https://user-images.githubusercontent.com/3676859/144089090-f46f109a-e2bc-465f-8a75-f4932bc2d7dd.png) #### What's Changed - Feature: make return state(data, error and isValidating) readonly by [@​anirudh1713](https://togithub.com/anirudh1713) in [https://github.com/vercel/swr/pull/1431](https://togithub.com/vercel/swr/pull/1431) - Stable hash by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1429](https://togithub.com/vercel/swr/pull/1429) - test: add render utilities and remove TestSWRConfig by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1435](https://togithub.com/vercel/swr/pull/1435) - Revert "Feature: make return state(data, error and isValidating) readonly" by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1443](https://togithub.com/vercel/swr/pull/1443) - Fix initial isValidating when isPaused() returns true by [@​anothertempore](https://togithub.com/anothertempore) in [https://github.com/vercel/swr/pull/1440](https://togithub.com/vercel/swr/pull/1440) - build: no emit on error by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1446](https://togithub.com/vercel/swr/pull/1446) - chore: remove unused typings by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1448](https://togithub.com/vercel/swr/pull/1448) - enhance: provider release handlers by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1449](https://togithub.com/vercel/swr/pull/1449) - test: refactor use-swr-cache-test by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1442](https://togithub.com/vercel/swr/pull/1442) - Chore: refactor code related to unsubscribing global listeners by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1451](https://togithub.com/vercel/swr/pull/1451) - Chore: code refactoring for swr/infinite by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1452](https://togithub.com/vercel/swr/pull/1452) - test: refactor concurrent rendering tests by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1457](https://togithub.com/vercel/swr/pull/1457) - test: refactor config tests by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1458](https://togithub.com/vercel/swr/pull/1458) - Revert "feat: add a warning for invalid arguments with suspense mode … by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1460](https://togithub.com/vercel/swr/pull/1460) - test: refactor mutation tests by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1459](https://togithub.com/vercel/swr/pull/1459) - fix: Support IE11 by [@​amannn](https://togithub.com/amannn) in [https://github.com/vercel/swr/pull/1463](https://togithub.com/vercel/swr/pull/1463) - test: refactor immutable and infinite hook tests by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1466](https://togithub.com/vercel/swr/pull/1466) - chore: Add React 18 to peerDependencies by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1467](https://togithub.com/vercel/swr/pull/1467) - test: refactor integration and loading tests by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1473](https://togithub.com/vercel/swr/pull/1473) - test: refactor key, middlewares, and suspense tests by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1474](https://togithub.com/vercel/swr/pull/1474) - test: refactor offline and refresh tests by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1483](https://togithub.com/vercel/swr/pull/1483) - build(deps): bump tmpl from 1.0.4 to 1.0.5 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/vercel/swr/pull/1484](https://togithub.com/vercel/swr/pull/1484) - Upgrade typescript to 4.4.3 by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1486](https://togithub.com/vercel/swr/pull/1486) - chore: Code refactoring by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1482](https://togithub.com/vercel/swr/pull/1482) - ci: multiple dir type checking by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1492](https://togithub.com/vercel/swr/pull/1492) - Type useSWR fetcher by [@​promer94](https://togithub.com/promer94) in [https://github.com/vercel/swr/pull/1477](https://togithub.com/vercel/swr/pull/1477) - chore: Improve project file structure by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1497](https://togithub.com/vercel/swr/pull/1497) - chore: Refine type interfaces by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1496](https://togithub.com/vercel/swr/pull/1496) - chore: Upgrade eslint and add local cache by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1499](https://togithub.com/vercel/swr/pull/1499) - fix: Invalidate the key when mutating without revalidating by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1498](https://togithub.com/vercel/swr/pull/1498) - example: add ref checking condition by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1504](https://togithub.com/vercel/swr/pull/1504) - fix: Refactor core revalidate function and fix isValidating state bug by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1493](https://togithub.com/vercel/swr/pull/1493) - chore: remove duplicate configs by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1507](https://togithub.com/vercel/swr/pull/1507) - typing: fix-type-generation by [@​promer94](https://togithub.com/promer94) in [https://github.com/vercel/swr/pull/1509](https://togithub.com/vercel/swr/pull/1509) - chroe: use yalc for local development by [@​promer94](https://togithub.com/promer94) in [https://github.com/vercel/swr/pull/1508](https://togithub.com/vercel/swr/pull/1508) - chore: Code refactoring by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1521](https://togithub.com/vercel/swr/pull/1521) - feat: Add new onDiscarded option by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1523](https://togithub.com/vercel/swr/pull/1523) - fix: Error events should be deduplicated by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1522](https://togithub.com/vercel/swr/pull/1522) - chore: Output test code coverage by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1511](https://togithub.com/vercel/swr/pull/1511) - chore: Mark returned states and mutate callback argument as readonly by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1514](https://togithub.com/vercel/swr/pull/1514) - test: Add tests for reconnect and merge-config by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1530](https://togithub.com/vercel/swr/pull/1530) - fix: Only trigger the success event if not discarded by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1529](https://togithub.com/vercel/swr/pull/1529) - chore: Code refactoring by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1533](https://togithub.com/vercel/swr/pull/1533) - Add revalidateFirstPage option to swr/infinite ([#​1401](https://togithub.com/vercel/swr/issues/1401)) by [@​timas130](https://togithub.com/timas130) in [https://github.com/vercel/swr/pull/1538](https://togithub.com/vercel/swr/pull/1538) - fix: Reusing cache provider by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1539](https://togithub.com/vercel/swr/pull/1539) - chore: fix ts comments by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1540](https://togithub.com/vercel/swr/pull/1540) - fix: Ensure mutate accepts undefined as the data by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1515](https://togithub.com/vercel/swr/pull/1515) - chore: Fix comment and startAt type by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1541](https://togithub.com/vercel/swr/pull/1541) - chore: Refactor cleanupState by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1544](https://togithub.com/vercel/swr/pull/1544) - feat: using latest version of `axios` with fetch interceptor by [@​danestves](https://togithub.com/danestves) in [https://github.com/vercel/swr/pull/1548](https://togithub.com/vercel/swr/pull/1548) - test: Add test case for mutation deduplication by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1549](https://togithub.com/vercel/swr/pull/1549) - test: speed up with [@​swc-node/jest](https://togithub.com/swc-node/jest) by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1569](https://togithub.com/vercel/swr/pull/1569) - chore: Optimizations by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1578](https://togithub.com/vercel/swr/pull/1578) - fix react-native issue by [@​aFINKndreas](https://togithub.com/aFINKndreas) in [https://github.com/vercel/swr/pull/1583](https://togithub.com/vercel/swr/pull/1583) - fix: Support for functions that return false by [@​TakahiroHimi](https://togithub.com/TakahiroHimi) in [https://github.com/vercel/swr/pull/1586](https://togithub.com/vercel/swr/pull/1586) - fix: adds undefined as valid Key type to allow falsy Key or Key() by [@​morgs32](https://togithub.com/morgs32) in [https://github.com/vercel/swr/pull/1594](https://togithub.com/vercel/swr/pull/1594) - fix: can't find variable removeEventListener by [@​zhaomengfan](https://togithub.com/zhaomengfan) in [https://github.com/vercel/swr/pull/1595](https://togithub.com/vercel/swr/pull/1595) - Revert "chore: Mark returned states and mutate callback argument as readonly" by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1570](https://togithub.com/vercel/swr/pull/1570) - fix: change config alteration process in withMiddleware to be immutable by [@​junsushin-dev](https://togithub.com/junsushin-dev) in [https://github.com/vercel/swr/pull/1556](https://togithub.com/vercel/swr/pull/1556) - fix: Allow empty mutate argument list for infinite by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1602](https://togithub.com/vercel/swr/pull/1602) - chore: Add `type: "module"` and use `.mjs` extension by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1604](https://togithub.com/vercel/swr/pull/1604) - Revert "chore: Add type: "module" and use .mjs extension ([#​1604](https://togithub.com/vercel/swr/issues/1604))" by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1618](https://togithub.com/vercel/swr/pull/1618) - enhance: bind removeEventListener by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1596](https://togithub.com/vercel/swr/pull/1596) - fix: typos by [@​nguyenyou](https://togithub.com/nguyenyou) in [https://github.com/vercel/swr/pull/1647](https://togithub.com/vercel/swr/pull/1647) - build: output without minification by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1650](https://togithub.com/vercel/swr/pull/1650) - Tweak types by [@​promer94](https://togithub.com/promer94) in [https://github.com/vercel/swr/pull/1640](https://togithub.com/vercel/swr/pull/1640) - fix: supports ssr in ie11([#​1657](https://togithub.com/vercel/swr/issues/1657)) by [@​Sh031224](https://togithub.com/Sh031224) in [https://github.com/vercel/swr/pull/1659](https://togithub.com/vercel/swr/pull/1659) - type: disbale inference when data generic is provided by [@​promer94](https://togithub.com/promer94) in [https://github.com/vercel/swr/pull/1658](https://togithub.com/vercel/swr/pull/1658) - chore: rename major branch to main by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1664](https://togithub.com/vercel/swr/pull/1664) - fix keyloader index and previousPageData type by [@​promer94](https://togithub.com/promer94) in [https://github.com/vercel/swr/pull/1669](https://togithub.com/vercel/swr/pull/1669) - Add defaults for SWRResponse by [@​TakahiroHimi](https://togithub.com/TakahiroHimi) in [https://github.com/vercel/swr/pull/1609](https://togithub.com/vercel/swr/pull/1609) - example: update typescript examples with strict ts mode by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1673](https://togithub.com/vercel/swr/pull/1673) - chore: upgrade eslint to v8 and prettier to v2 by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1674](https://togithub.com/vercel/swr/pull/1674) - fix: remove unnecessary async by [@​Cut0](https://togithub.com/Cut0) in [https://github.com/vercel/swr/pull/1676](https://togithub.com/vercel/swr/pull/1676) - types: remove duplicated typing def by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1675](https://togithub.com/vercel/swr/pull/1675) - chore: Add test case for `getKey` in `useSWRInfinite` by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1681](https://togithub.com/vercel/swr/pull/1681) #### New Contributors - [@​willheslam](https://togithub.com/willheslam) made their first contribution in [https://github.com/vercel/swr/pull/1393](https://togithub.com/vercel/swr/pull/1393) - [@​louisgv](https://togithub.com/louisgv) made their first contribution in [https://github.com/vercel/swr/pull/1406](https://togithub.com/vercel/swr/pull/1406) - [@​origin-master](https://togithub.com/origin-master) made their first contribution in [https://github.com/vercel/swr/pull/1409](https://togithub.com/vercel/swr/pull/1409) - [@​anirudh1713](https://togithub.com/anirudh1713) made their first contribution in [https://github.com/vercel/swr/pull/1431](https://togithub.com/vercel/swr/pull/1431) - [@​amannn](https://togithub.com/amannn) made their first contribution in [https://github.com/vercel/swr/pull/1463](https://togithub.com/vercel/swr/pull/1463) - [@​timas130](https://togithub.com/timas130) made their first contribution in [https://github.com/vercel/swr/pull/1538](https://togithub.com/vercel/swr/pull/1538) - [@​danestves](https://togithub.com/danestves) made their first contribution in [https://github.com/vercel/swr/pull/1548](https://togithub.com/vercel/swr/pull/1548) - [@​aFINKndreas](https://togithub.com/aFINKndreas) made their first contribution in [https://github.com/vercel/swr/pull/1583](https://togithub.com/vercel/swr/pull/1583) - [@​TakahiroHimi](https://togithub.com/TakahiroHimi) made their first contribution in [https://github.com/vercel/swr/pull/1586](https://togithub.com/vercel/swr/pull/1586) - [@​zhaomengfan](https://togithub.com/zhaomengfan) made their first contribution in [https://github.com/vercel/swr/pull/1595](https://togithub.com/vercel/swr/pull/1595) - [@​junsushin-dev](https://togithub.com/junsushin-dev) made their first contribution in [https://github.com/vercel/swr/pull/1556](https://togithub.com/vercel/swr/pull/1556) - [@​nguyenyou](https://togithub.com/nguyenyou) made their first contribution in [https://github.com/vercel/swr/pull/1647](https://togithub.com/vercel/swr/pull/1647) - [@​Sh031224](https://togithub.com/Sh031224) made their first contribution in [https://github.com/vercel/swr/pull/1659](https://togithub.com/vercel/swr/pull/1659) - [@​Cut0](https://togithub.com/Cut0) made their first contribution in [https://github.com/vercel/swr/pull/1676](https://togithub.com/vercel/swr/pull/1676) **Full Changelog**: vercel/swr@1.0.1...1.1.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "after 10pm every weekday,before 5am every weekday,every weekend" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, click this checkbox. --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/vercel/turborepo).
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [swr](https://swr.vercel.app) ([source](https://togithub.com/vercel/swr)) | [`1.0.1` -> `1.3.0`](https://renovatebot.com/diffs/npm/swr/1.0.1/1.3.0) | [![age](https://badges.renovateapi.com/packages/npm/swr/1.3.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/swr/1.3.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/swr/1.3.0/compatibility-slim/1.0.1)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/swr/1.3.0/confidence-slim/1.0.1)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>vercel/swr</summary> ### [`v1.3.0`](https://togithub.com/vercel/swr/releases/tag/1.3.0) [Compare Source](https://togithub.com/vercel/swr/compare/1.2.2...1.3.0) #### What's Changed - type: fix type error on SWRConfig by [@​Himself65](https://togithub.com/Himself65) in [#​1913](https://togithub.com/vercel/swr/issues/1913) - chore: update React 18 dependencies by [@​shuding](https://togithub.com/shuding) in [#​1824](https://togithub.com/vercel/swr/issues/1824) - test: fix an act warning by [@​koba04](https://togithub.com/koba04) in [#​1888](https://togithub.com/vercel/swr/issues/1888) - feat: support functional optimisticData by [@​huozhi](https://togithub.com/huozhi) in [#​1861](https://togithub.com/vercel/swr/issues/1861) - bugfix: make suspense and revalidateIfStale work together by [@​simowe](https://togithub.com/simowe) in [#​1851](https://togithub.com/vercel/swr/issues/1851) **Full Changelog**: vercel/swr@1.2.2...1.3.0 ### [`v1.2.2`](https://togithub.com/vercel/swr/releases/tag/1.2.2) [Compare Source](https://togithub.com/vercel/swr/compare/1.2.1...1.2.2) #### Highlights of This Release ##### `populateCache` Option Now Supports Function We added better Optimistic UI support in [v1.2.0](https://togithub.com/vercel/swr/releases/tag/1.2.0). However, what if your API is only returning a subset of the data (such as the mutated part), that can be populated into the cache? Usually, an extra revalidation after that mutation is needed. But now you can also use a function as `populateCache` to transform the mutate result into the full data: ```js await mutate(addTodo(newTodo), { optimisticData: [...data, newTodo], rollbackOnError: true, populateCache: (addedTodo, currentData) => { // `addedTodo` is what the API returns. It's not // returning a list of all current todos but only // the new added one. // In this case, we can transform the mutate result // together with current data, into the new data // that can be updated. return [...currentData, addedTodo]; }, // Since the API already gives us the updated information, // we don't need to revalidate here. revalidate: false, }); ``` The new definition: ```ts populateCache?: boolean | ((mutationResult: any, currentData: Data) => Data) ``` Here is a demo for it: https://codesandbox.io/s/swr-basic-forked-hi9svh ##### Bug Fixes #### What's Changed - refactor: revalidateIfStale has an effect on updates, not only mounting by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1837](https://togithub.com/vercel/swr/pull/1837) - fix: reset stale unmountedRef in suspense by [@​promer94](https://togithub.com/promer94) in [https://github.com/vercel/swr/pull/1843](https://togithub.com/vercel/swr/pull/1843) - test: add a test for the behavior of revalidateOnMount when the key has been changed by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1847](https://togithub.com/vercel/swr/pull/1847) - feat: Support `populateCache` as a function by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1818](https://togithub.com/vercel/swr/pull/1818) **Full Changelog**: vercel/swr@1.2.1...1.2.2 ### [`v1.2.1`](https://togithub.com/vercel/swr/releases/tag/1.2.1) [Compare Source](https://togithub.com/vercel/swr/compare/1.2.0...1.2.1) #### Highlights of This Release ##### `shouldRetryOnError` accepts a function Previously [`shouldRetryOnError`](https://swr.vercel.app/docs/error-handling#error-retry) is either true or false. Now it accepts a function that conditionally determines if SWR should retry. Here's a simple example: ```js const fetcher = url => fetch(url).then(res => { // Fetcher throws if the response code is not 2xx. if (!res.ok) throw res return res.json() }) useSWR(key, fetcher, { shouldRetryOnError: (error) => { // We skip retrying if the API is returning 404: if (error.status === 404) return false return true } }) ``` Thanks to [@​sairajchouhan](https://togithub.com/sairajchouhan) for contributing! #### What's Changed - `shouldRetryOnError` accepts a function that can be used to conditionally stop retrying by [@​sairajchouhan](https://togithub.com/sairajchouhan) in [https://github.com/vercel/swr/pull/1816](https://togithub.com/vercel/swr/pull/1816) - build(deps-dev): bump next from 12.0.8 to 12.0.9 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/vercel/swr/pull/1821](https://togithub.com/vercel/swr/pull/1821) - fix: useSWRInfinite revalidates with revalidateOnMount by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1830](https://togithub.com/vercel/swr/pull/1830) #### New Contributors - [@​sairajchouhan](https://togithub.com/sairajchouhan) made their first contribution in [https://github.com/vercel/swr/pull/1816](https://togithub.com/vercel/swr/pull/1816) **Full Changelog**: vercel/swr@1.2.0...1.2.1 ### [`v1.2.0`](https://togithub.com/vercel/swr/releases/tag/1.2.0) [Compare Source](https://togithub.com/vercel/swr/compare/1.1.2...1.2.0) #### Highlights of This Release ##### Optimistic Updates with Auto Error Rollback There are now some new options in `mutate`: ```js mutate(patchUser(user), { optimisticData: user, populateCache: true, rollbackOnError: true, revalidate: true, }) ``` Here the cache will be immediately updated to `user`, the “optimistic value”. And then a request (remote mutation) is started via `patchUser(user)` and the response will be written to the cache. If that request fails, the original result will be rolled back safely so the optimistic value will be gone. And after all those finish, a revalidation will start to fetch the latest value. This is extremely helpful for building the optimistic UI pattern. You can do the same for the global `mutate`, just remember to pass the key. Also, the current `mutate` APIs stay unchanged so `mutate(data, false)` works the same. Here's an example: https://codesandbox.io/s/swr-basic-forked-k5hps. https://user-images.githubusercontent.com/3676859/151381238-f3aba769-91b6-4bfc-9285-df1b9ef51773.mp4 ##### `.mjs` Support SWR now has `.mjs` exported for bundlers that prefer this format. This doesn’t break environments that don’t support `.mjs`. An alternative `.esm.js` and CJS bundle are also published. You can read more about ES modules [here](https://2ality.com/2017/05/es-module-specifiers.html). #### What's Changed - feat: Optimistic mutation with error rollback by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1745](https://togithub.com/vercel/swr/pull/1745) - fix: Required return type when mutating by [@​RKatarine](https://togithub.com/RKatarine) in [https://github.com/vercel/swr/pull/1772](https://togithub.com/vercel/swr/pull/1772) - fix: use the latest reference of fetcher with suspense mode by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1803](https://togithub.com/vercel/swr/pull/1803) - test: add delay for flaky focus test by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1762](https://togithub.com/vercel/swr/pull/1762) - test: remove flaky focus test case by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1793](https://togithub.com/vercel/swr/pull/1793) - test: use [@​swc/jest](https://togithub.com/swc/jest) by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1790](https://togithub.com/vercel/swr/pull/1790) - chore: Ignore coverage report by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1744](https://togithub.com/vercel/swr/pull/1744) - chore: Merge mutation states by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1748](https://togithub.com/vercel/swr/pull/1748) - chore: Rename CONCURRENT_REQUESTS to FETCH by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1749](https://togithub.com/vercel/swr/pull/1749) - chore: Merge extra request states in cache by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1752](https://togithub.com/vercel/swr/pull/1752) - chore: support mjs exports by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1760](https://togithub.com/vercel/swr/pull/1760) - chore: remove useless react-native field by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1761](https://togithub.com/vercel/swr/pull/1761) - chore: comment helper by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1757](https://togithub.com/vercel/swr/pull/1757) - chore: display name in devtool by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1779](https://togithub.com/vercel/swr/pull/1779) - chore: simplify example development by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1787](https://togithub.com/vercel/swr/pull/1787) - chore: build: improve watch commands by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1788](https://togithub.com/vercel/swr/pull/1788) - chore: Update examples and dependencies by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1789](https://togithub.com/vercel/swr/pull/1789) - chore: zeit -> vercel by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1791](https://togithub.com/vercel/swr/pull/1791) - chore: Clean up configurations by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1792](https://togithub.com/vercel/swr/pull/1792) - chore: move community health files to .github dir by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1794](https://togithub.com/vercel/swr/pull/1794) - chore: Add link to security email directly by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1795](https://togithub.com/vercel/swr/pull/1795) #### New Contributors - [@​RKatarine](https://togithub.com/RKatarine) made their first contribution in [https://github.com/vercel/swr/pull/1772](https://togithub.com/vercel/swr/pull/1772) **Full Changelog**: vercel/swr@1.1.2...1.2.0 ### [`v1.1.2`](https://togithub.com/vercel/swr/releases/tag/1.1.2) [Compare Source](https://togithub.com/vercel/swr/compare/1.1.1...1.1.2) #### Highlights of This Release ##### Use the Latest Fetcher Function SWR will now use the latest fetcher function passed to the hook, when sending the request. Previously it uses the initial snapshotted fetcher. ##### Avoid Unnecessary Auto Revalidations When refocusing on the window with state changes (like clicking a button that changes the SWR key immediately), SWR now avoids revalidations if they're not necessary. Details can be found in [#​1720](https://togithub.com/vercel/swr/issues/1720). ##### New Types for `useSWRInfinite` Two types for `useSWRInfinite` are added: `SWRInfinteHook` and `SWRInfinteKeyLoader`. You can use them to type the hook and the `getKey` function. ##### New `populateCache` option for `mutate` A new option to control if the mutation data should be written to the cache. You can find the details in [#​1729](https://togithub.com/vercel/swr/issues/1729). #### What's Changed - Make polyfill for `requestAnimationFrame` more robust by [@​thomaspaulmann](https://togithub.com/thomaspaulmann) in [https://github.com/vercel/swr/pull/1707](https://togithub.com/vercel/swr/pull/1707) - type(infinite): export SWRInfinteHook and SWRInfiniteKeyLoader from infinite, rename InfiniteFetcher to SWRInfiniteFetcher by [@​houkanshan](https://togithub.com/houkanshan) in [https://github.com/vercel/swr/pull/1714](https://togithub.com/vercel/swr/pull/1714) - feat: Ensure auto revalidations are executed after state updates by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1720](https://togithub.com/vercel/swr/pull/1720) - Add moduleNameMapper to jest by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1724](https://togithub.com/vercel/swr/pull/1724) - Improve test by [@​promer94](https://togithub.com/promer94) in [https://github.com/vercel/swr/pull/1725](https://togithub.com/vercel/swr/pull/1725) - feat: Use the latest reference of fetcher by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1727](https://togithub.com/vercel/swr/pull/1727) - fix: Re-export InfiniteFetcher by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1728](https://togithub.com/vercel/swr/pull/1728) - feat: Add `populateCache` option to `mutate` by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1729](https://togithub.com/vercel/swr/pull/1729) - Fix local state sharing example deps by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1737](https://togithub.com/vercel/swr/pull/1737) - Merge states for concurrent requests by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1741](https://togithub.com/vercel/swr/pull/1741) - Skip error retrying when document is not active and improve tests by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1742](https://togithub.com/vercel/swr/pull/1742) #### New Contributors - [@​thomaspaulmann](https://togithub.com/thomaspaulmann) made their first contribution in [https://github.com/vercel/swr/pull/1707](https://togithub.com/vercel/swr/pull/1707) - [@​houkanshan](https://togithub.com/houkanshan) made their first contribution in [https://github.com/vercel/swr/pull/1714](https://togithub.com/vercel/swr/pull/1714) **Full Changelog**: vercel/swr@1.1.1...1.1.2 ### [`v1.1.1`](https://togithub.com/vercel/swr/releases/tag/1.1.1) [Compare Source](https://togithub.com/vercel/swr/compare/1.1.0...1.1.1) #### Highlights of This Release ##### Dynamic `refreshInterval` You can now pass a function as `refreshInterval`, to dynamically return the interval (in millisecond) til the next request, based on the current data: ```typescript useSWR('key', fetcher, { refreshInterval: function (data: Data | undefined) { if (!data) return 3000 // Initial request return data.next_update } }) ``` If return `0`, polling will be stopped. #### What's Changed - feat: refreshInterval as a function by [@​Andrewnt219](https://togithub.com/Andrewnt219) in [https://github.com/vercel/swr/pull/1690](https://togithub.com/vercel/swr/pull/1690) - test: add refreshInterval function returns 0 by [@​Andrewnt219](https://togithub.com/Andrewnt219) in [https://github.com/vercel/swr/pull/1691](https://togithub.com/vercel/swr/pull/1691) - fix: If `newData` is deeply to the latest state, broadcast the latest state by [@​icyJoseph](https://togithub.com/icyJoseph) in [https://github.com/vercel/swr/pull/1697](https://togithub.com/vercel/swr/pull/1697) - fix: Return `undefined` data if key's falsy under suspense mode by [@​icyJoseph](https://togithub.com/icyJoseph) in [https://github.com/vercel/swr/pull/1698](https://togithub.com/vercel/swr/pull/1698) #### New Contributors - [@​Andrewnt219](https://togithub.com/Andrewnt219) made their first contribution in [https://github.com/vercel/swr/pull/1690](https://togithub.com/vercel/swr/pull/1690) - [@​icyJoseph](https://togithub.com/icyJoseph) made their first contribution in [https://github.com/vercel/swr/pull/1697](https://togithub.com/vercel/swr/pull/1697) **Full Changelog**: vercel/swr@1.1.0...1.1.1 ### [`v1.1.0`](https://togithub.com/vercel/swr/releases/tag/1.1.0) [Compare Source](https://togithub.com/vercel/swr/compare/1.0.1...1.1.0) #### Highlights for This Release ##### 1. Built-in & stable serialization for SWR keys ```js useSWR({ query: graphql`...`, variables }, fetcher) useSWR({ query: graphql`...`, variables }, fetcher) useSWR({ variables, query: graphql`...` }, fetcher) // ^all recognized as the same resource ``` For array keys too, it's safe to do the following: ```js useSWR([ `...`, { variables } ], fetcher) ``` ##### 2. `revalidateFirstPage` for `useSWRInfinite` This is a new added option for `useSWRInfinite` (defaults to `true`), you can use it to control if the first page should be revalidated when changing the size or doing a mutation. ##### 3. Better TypeScript support - Key / arguments - Conditional / dependent - Constant keys - Returned data ![image](https://user-images.githubusercontent.com/3676859/144089090-f46f109a-e2bc-465f-8a75-f4932bc2d7dd.png) #### What's Changed - Feature: make return state(data, error and isValidating) readonly by [@​anirudh1713](https://togithub.com/anirudh1713) in [https://github.com/vercel/swr/pull/1431](https://togithub.com/vercel/swr/pull/1431) - Stable hash by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1429](https://togithub.com/vercel/swr/pull/1429) - test: add render utilities and remove TestSWRConfig by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1435](https://togithub.com/vercel/swr/pull/1435) - Revert "Feature: make return state(data, error and isValidating) readonly" by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1443](https://togithub.com/vercel/swr/pull/1443) - Fix initial isValidating when isPaused() returns true by [@​anothertempore](https://togithub.com/anothertempore) in [https://github.com/vercel/swr/pull/1440](https://togithub.com/vercel/swr/pull/1440) - build: no emit on error by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1446](https://togithub.com/vercel/swr/pull/1446) - chore: remove unused typings by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1448](https://togithub.com/vercel/swr/pull/1448) - enhance: provider release handlers by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1449](https://togithub.com/vercel/swr/pull/1449) - test: refactor use-swr-cache-test by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1442](https://togithub.com/vercel/swr/pull/1442) - Chore: refactor code related to unsubscribing global listeners by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1451](https://togithub.com/vercel/swr/pull/1451) - Chore: code refactoring for swr/infinite by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1452](https://togithub.com/vercel/swr/pull/1452) - test: refactor concurrent rendering tests by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1457](https://togithub.com/vercel/swr/pull/1457) - test: refactor config tests by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1458](https://togithub.com/vercel/swr/pull/1458) - Revert "feat: add a warning for invalid arguments with suspense mode … by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1460](https://togithub.com/vercel/swr/pull/1460) - test: refactor mutation tests by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1459](https://togithub.com/vercel/swr/pull/1459) - fix: Support IE11 by [@​amannn](https://togithub.com/amannn) in [https://github.com/vercel/swr/pull/1463](https://togithub.com/vercel/swr/pull/1463) - test: refactor immutable and infinite hook tests by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1466](https://togithub.com/vercel/swr/pull/1466) - chore: Add React 18 to peerDependencies by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1467](https://togithub.com/vercel/swr/pull/1467) - test: refactor integration and loading tests by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1473](https://togithub.com/vercel/swr/pull/1473) - test: refactor key, middlewares, and suspense tests by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1474](https://togithub.com/vercel/swr/pull/1474) - test: refactor offline and refresh tests by [@​koba04](https://togithub.com/koba04) in [https://github.com/vercel/swr/pull/1483](https://togithub.com/vercel/swr/pull/1483) - build(deps): bump tmpl from 1.0.4 to 1.0.5 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/vercel/swr/pull/1484](https://togithub.com/vercel/swr/pull/1484) - Upgrade typescript to 4.4.3 by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1486](https://togithub.com/vercel/swr/pull/1486) - chore: Code refactoring by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1482](https://togithub.com/vercel/swr/pull/1482) - ci: multiple dir type checking by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1492](https://togithub.com/vercel/swr/pull/1492) - Type useSWR fetcher by [@​promer94](https://togithub.com/promer94) in [https://github.com/vercel/swr/pull/1477](https://togithub.com/vercel/swr/pull/1477) - chore: Improve project file structure by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1497](https://togithub.com/vercel/swr/pull/1497) - chore: Refine type interfaces by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1496](https://togithub.com/vercel/swr/pull/1496) - chore: Upgrade eslint and add local cache by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1499](https://togithub.com/vercel/swr/pull/1499) - fix: Invalidate the key when mutating without revalidating by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1498](https://togithub.com/vercel/swr/pull/1498) - example: add ref checking condition by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1504](https://togithub.com/vercel/swr/pull/1504) - fix: Refactor core revalidate function and fix isValidating state bug by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1493](https://togithub.com/vercel/swr/pull/1493) - chore: remove duplicate configs by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1507](https://togithub.com/vercel/swr/pull/1507) - typing: fix-type-generation by [@​promer94](https://togithub.com/promer94) in [https://github.com/vercel/swr/pull/1509](https://togithub.com/vercel/swr/pull/1509) - chroe: use yalc for local development by [@​promer94](https://togithub.com/promer94) in [https://github.com/vercel/swr/pull/1508](https://togithub.com/vercel/swr/pull/1508) - chore: Code refactoring by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1521](https://togithub.com/vercel/swr/pull/1521) - feat: Add new onDiscarded option by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1523](https://togithub.com/vercel/swr/pull/1523) - fix: Error events should be deduplicated by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1522](https://togithub.com/vercel/swr/pull/1522) - chore: Output test code coverage by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1511](https://togithub.com/vercel/swr/pull/1511) - chore: Mark returned states and mutate callback argument as readonly by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1514](https://togithub.com/vercel/swr/pull/1514) - test: Add tests for reconnect and merge-config by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1530](https://togithub.com/vercel/swr/pull/1530) - fix: Only trigger the success event if not discarded by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1529](https://togithub.com/vercel/swr/pull/1529) - chore: Code refactoring by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1533](https://togithub.com/vercel/swr/pull/1533) - Add revalidateFirstPage option to swr/infinite ([#​1401](https://togithub.com/vercel/swr/issues/1401)) by [@​timas130](https://togithub.com/timas130) in [https://github.com/vercel/swr/pull/1538](https://togithub.com/vercel/swr/pull/1538) - fix: Reusing cache provider by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1539](https://togithub.com/vercel/swr/pull/1539) - chore: fix ts comments by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1540](https://togithub.com/vercel/swr/pull/1540) - fix: Ensure mutate accepts undefined as the data by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1515](https://togithub.com/vercel/swr/pull/1515) - chore: Fix comment and startAt type by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1541](https://togithub.com/vercel/swr/pull/1541) - chore: Refactor cleanupState by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1544](https://togithub.com/vercel/swr/pull/1544) - feat: using latest version of `axios` with fetch interceptor by [@​danestves](https://togithub.com/danestves) in [https://github.com/vercel/swr/pull/1548](https://togithub.com/vercel/swr/pull/1548) - test: Add test case for mutation deduplication by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1549](https://togithub.com/vercel/swr/pull/1549) - test: speed up with [@​swc-node/jest](https://togithub.com/swc-node/jest) by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1569](https://togithub.com/vercel/swr/pull/1569) - chore: Optimizations by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1578](https://togithub.com/vercel/swr/pull/1578) - fix react-native issue by [@​aFINKndreas](https://togithub.com/aFINKndreas) in [https://github.com/vercel/swr/pull/1583](https://togithub.com/vercel/swr/pull/1583) - fix: Support for functions that return false by [@​TakahiroHimi](https://togithub.com/TakahiroHimi) in [https://github.com/vercel/swr/pull/1586](https://togithub.com/vercel/swr/pull/1586) - fix: adds undefined as valid Key type to allow falsy Key or Key() by [@​morgs32](https://togithub.com/morgs32) in [https://github.com/vercel/swr/pull/1594](https://togithub.com/vercel/swr/pull/1594) - fix: can't find variable removeEventListener by [@​zhaomengfan](https://togithub.com/zhaomengfan) in [https://github.com/vercel/swr/pull/1595](https://togithub.com/vercel/swr/pull/1595) - Revert "chore: Mark returned states and mutate callback argument as readonly" by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1570](https://togithub.com/vercel/swr/pull/1570) - fix: change config alteration process in withMiddleware to be immutable by [@​junsushin-dev](https://togithub.com/junsushin-dev) in [https://github.com/vercel/swr/pull/1556](https://togithub.com/vercel/swr/pull/1556) - fix: Allow empty mutate argument list for infinite by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1602](https://togithub.com/vercel/swr/pull/1602) - chore: Add `type: "module"` and use `.mjs` extension by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1604](https://togithub.com/vercel/swr/pull/1604) - Revert "chore: Add type: "module" and use .mjs extension ([#​1604](https://togithub.com/vercel/swr/issues/1604))" by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1618](https://togithub.com/vercel/swr/pull/1618) - enhance: bind removeEventListener by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1596](https://togithub.com/vercel/swr/pull/1596) - fix: typos by [@​nguyenyou](https://togithub.com/nguyenyou) in [https://github.com/vercel/swr/pull/1647](https://togithub.com/vercel/swr/pull/1647) - build: output without minification by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1650](https://togithub.com/vercel/swr/pull/1650) - Tweak types by [@​promer94](https://togithub.com/promer94) in [https://github.com/vercel/swr/pull/1640](https://togithub.com/vercel/swr/pull/1640) - fix: supports ssr in ie11([#​1657](https://togithub.com/vercel/swr/issues/1657)) by [@​Sh031224](https://togithub.com/Sh031224) in [https://github.com/vercel/swr/pull/1659](https://togithub.com/vercel/swr/pull/1659) - type: disbale inference when data generic is provided by [@​promer94](https://togithub.com/promer94) in [https://github.com/vercel/swr/pull/1658](https://togithub.com/vercel/swr/pull/1658) - chore: rename major branch to main by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1664](https://togithub.com/vercel/swr/pull/1664) - fix keyloader index and previousPageData type by [@​promer94](https://togithub.com/promer94) in [https://github.com/vercel/swr/pull/1669](https://togithub.com/vercel/swr/pull/1669) - Add defaults for SWRResponse by [@​TakahiroHimi](https://togithub.com/TakahiroHimi) in [https://github.com/vercel/swr/pull/1609](https://togithub.com/vercel/swr/pull/1609) - example: update typescript examples with strict ts mode by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1673](https://togithub.com/vercel/swr/pull/1673) - chore: upgrade eslint to v8 and prettier to v2 by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1674](https://togithub.com/vercel/swr/pull/1674) - fix: remove unnecessary async by [@​Cut0](https://togithub.com/Cut0) in [https://github.com/vercel/swr/pull/1676](https://togithub.com/vercel/swr/pull/1676) - types: remove duplicated typing def by [@​huozhi](https://togithub.com/huozhi) in [https://github.com/vercel/swr/pull/1675](https://togithub.com/vercel/swr/pull/1675) - chore: Add test case for `getKey` in `useSWRInfinite` by [@​shuding](https://togithub.com/shuding) in [https://github.com/vercel/swr/pull/1681](https://togithub.com/vercel/swr/pull/1681) #### New Contributors - [@​willheslam](https://togithub.com/willheslam) made their first contribution in [https://github.com/vercel/swr/pull/1393](https://togithub.com/vercel/swr/pull/1393) - [@​louisgv](https://togithub.com/louisgv) made their first contribution in [https://github.com/vercel/swr/pull/1406](https://togithub.com/vercel/swr/pull/1406) - [@​origin-master](https://togithub.com/origin-master) made their first contribution in [https://github.com/vercel/swr/pull/1409](https://togithub.com/vercel/swr/pull/1409) - [@​anirudh1713](https://togithub.com/anirudh1713) made their first contribution in [https://github.com/vercel/swr/pull/1431](https://togithub.com/vercel/swr/pull/1431) - [@​amannn](https://togithub.com/amannn) made their first contribution in [https://github.com/vercel/swr/pull/1463](https://togithub.com/vercel/swr/pull/1463) - [@​timas130](https://togithub.com/timas130) made their first contribution in [https://github.com/vercel/swr/pull/1538](https://togithub.com/vercel/swr/pull/1538) - [@​danestves](https://togithub.com/danestves) made their first contribution in [https://github.com/vercel/swr/pull/1548](https://togithub.com/vercel/swr/pull/1548) - [@​aFINKndreas](https://togithub.com/aFINKndreas) made their first contribution in [https://github.com/vercel/swr/pull/1583](https://togithub.com/vercel/swr/pull/1583) - [@​TakahiroHimi](https://togithub.com/TakahiroHimi) made their first contribution in [https://github.com/vercel/swr/pull/1586](https://togithub.com/vercel/swr/pull/1586) - [@​zhaomengfan](https://togithub.com/zhaomengfan) made their first contribution in [https://github.com/vercel/swr/pull/1595](https://togithub.com/vercel/swr/pull/1595) - [@​junsushin-dev](https://togithub.com/junsushin-dev) made their first contribution in [https://github.com/vercel/swr/pull/1556](https://togithub.com/vercel/swr/pull/1556) - [@​nguyenyou](https://togithub.com/nguyenyou) made their first contribution in [https://github.com/vercel/swr/pull/1647](https://togithub.com/vercel/swr/pull/1647) - [@​Sh031224](https://togithub.com/Sh031224) made their first contribution in [https://github.com/vercel/swr/pull/1659](https://togithub.com/vercel/swr/pull/1659) - [@​Cut0](https://togithub.com/Cut0) made their first contribution in [https://github.com/vercel/swr/pull/1676](https://togithub.com/vercel/swr/pull/1676) **Full Changelog**: vercel/swr@1.0.1...1.1.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "after 10pm every weekday,before 5am every weekday,every weekend" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, click this checkbox. --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/vercel/turborepo).
useSWR<{ id: number }>('/api/', (key) => ({ id: 123 }))
still works as beforeso users dont need to update their current code