From 433f1bbe8ebad8c9b8a3d855226dcc9eeb35bf58 Mon Sep 17 00:00:00 2001 From: promer94 Date: Thu, 2 May 2024 12:03:28 +0800 Subject: [PATCH 01/10] ci: fix ci error and upgrade action version (#2952) * fix aatw command * upgrade action version * try fix attw * try fix attw * try upgrade attw version * ci: skip useSWRInfinite suspense test for now * restore debug motification * restore debug motification --- .github/workflows/install/action.yml | 4 +- .github/workflows/test-canary.yml | 2 +- .github/workflows/test-legacy-react.yml | 2 +- .github/workflows/test-release.yml | 9 +- .github/workflows/trigger-release.yml | 33 +---- package.json | 4 +- pnpm-lock.yaml | 158 ++++++++++++------------ test/use-swr-infinite-preload.test.tsx | 9 +- 8 files changed, 98 insertions(+), 123 deletions(-) diff --git a/.github/workflows/install/action.yml b/.github/workflows/install/action.yml index f7dd261a53..f512090304 100644 --- a/.github/workflows/install/action.yml +++ b/.github/workflows/install/action.yml @@ -4,10 +4,10 @@ runs: using: composite steps: - name: Setup pnpm - uses: pnpm/action-setup@v2.2.4 + uses: pnpm/action-setup@v3 - name: Use Node.js 18 - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: 18 cache: pnpm diff --git a/.github/workflows/test-canary.yml b/.github/workflows/test-canary.yml index 906c918d0d..c2625ca0ac 100644 --- a/.github/workflows/test-canary.yml +++ b/.github/workflows/test-canary.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install uses: ./.github/workflows/install diff --git a/.github/workflows/test-legacy-react.yml b/.github/workflows/test-legacy-react.yml index 3f3f73852f..8ac54ed673 100644 --- a/.github/workflows/test-legacy-react.yml +++ b/.github/workflows/test-legacy-react.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install uses: ./.github/workflows/install diff --git a/.github/workflows/test-release.yml b/.github/workflows/test-release.yml index 79e974b4dc..279864e186 100644 --- a/.github/workflows/test-release.yml +++ b/.github/workflows/test-release.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install uses: ./.github/workflows/install @@ -23,6 +23,7 @@ jobs: pnpm clean pnpm build pnpm run-all-checks + npm pack pnpm attw pnpm test pnpm test:build @@ -32,7 +33,7 @@ jobs: image: mcr.microsoft.com/playwright:v1.34.3-focal steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install uses: ./.github/workflows/install @@ -45,7 +46,7 @@ jobs: pnpm test:e2e - name: Upload test results if: always() - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: playwright-report path: playwright-report @@ -57,7 +58,7 @@ jobs: id-token: write steps: - name: Check out - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install uses: ./.github/workflows/install diff --git a/.github/workflows/trigger-release.yml b/.github/workflows/trigger-release.yml index 6efdb045bf..2beba63aec 100644 --- a/.github/workflows/trigger-release.yml +++ b/.github/workflows/trigger-release.yml @@ -17,10 +17,6 @@ on: - minor - major - secrets: - RELEASE_BOT_GITHUB_TOKEN: - required: true - name: Trigger Release env: @@ -34,36 +30,13 @@ jobs: environment: release-${{ github.event.inputs.releaseType }}-${{ github.event.inputs.semverType }} steps: - - name: Setup node - uses: actions/setup-node@v3 - if: ${{ steps.docs-change.outputs.docsChange == 'nope' }} - with: - node-version: 18 - check-latest: true - - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 10 token: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }} - - - run: npm i -g pnpm@${PNPM_VERSION} - - - id: get-store-path - run: echo STORE_PATH=$(pnpm store path) >> $GITHUB_OUTPUT - - - uses: actions/cache@v3 - timeout-minutes: 5 - id: cache-pnpm-store - with: - path: ${{ steps.get-store-path.outputs.STORE_PATH }} - key: pnpm-store-${{ hashFiles('pnpm-lock.yaml') }} - restore-keys: | - pnpm-store- - pnpm-store-${{ hashFiles('pnpm-lock.yaml') }} - - - run: pnpm install - + - name: Install + uses: ./.github/workflows/install - run: | pnpm clean pnpm build diff --git a/package.json b/package.json index 7016e944bd..48f82533f0 100644 --- a/package.json +++ b/package.json @@ -100,7 +100,7 @@ "watch": "bunchee -w", "build": "bunchee", "build:e2e": "pnpm next build e2e/site", - "attw": "attw --pack", + "attw": "attw --pack .", "types:check": "tsc --noEmit", "prepublishOnly": "pnpm clean && pnpm build", "publish-beta": "pnpm publish --tag beta", @@ -121,7 +121,7 @@ ] }, "devDependencies": { - "@arethetypeswrong/cli": "^0.7.0", + "@arethetypeswrong/cli": "^0.15.3", "@playwright/test": "^1.34.3", "@swc/core": "^1.3.62", "@swc/jest": "0.2.26", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ece8a9d926..ee979f3512 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,5 +1,9 @@ lockfileVersion: '6.0' +settings: + autoInstallPeers: false + excludeLinksFromLockfile: false + importers: .: @@ -9,8 +13,8 @@ importers: version: 1.2.0(react@18.2.0) devDependencies: '@arethetypeswrong/cli': - specifier: ^0.7.0 - version: 0.7.0 + specifier: ^0.15.3 + version: 0.15.3 '@playwright/test': specifier: ^1.34.3 version: 1.34.3 @@ -130,35 +134,34 @@ packages: '@jridgewell/trace-mapping': 0.3.23 dev: true - /@andrewbranch/untar.js@1.0.2: - resolution: {integrity: sha512-hL80MHK3b++pEp6K23+Nl5r5D1F19DRagp2ruCBIv4McyCiLKq67vUNvEQY1aGCAKNZ8GxV23n5MhOm7RwO8Pg==} + /@andrewbranch/untar.js@1.0.3: + resolution: {integrity: sha512-Jh15/qVmrLGhkKJBdXlK1+9tY4lZruYjsgkDFj08ZmDiWVBLJcqkok7Z0/R0In+i1rScBpJlSvrTS2Lm41Pbnw==} dev: true - /@arethetypeswrong/cli@0.7.0: - resolution: {integrity: sha512-fNX9abfPkhYPUlfSI38L0TtbJWIIGuMF1TQsnw9GzAeg6FFWEj5HYoI0pRj049p++BgM9/ikRy1RS2BBDkCHXQ==} + /@arethetypeswrong/cli@0.15.3: + resolution: {integrity: sha512-sIMA9ZJBWDEg1+xt5RkAEflZuf8+PO8SdKj17x6PtETuUho+qlZJg4DgmKc3q+QwQ9zOB5VLK6jVRbFdNLdUIA==} + engines: {node: '>=18'} hasBin: true dependencies: - '@arethetypeswrong/core': 0.7.0 + '@arethetypeswrong/core': 0.15.1 chalk: 4.1.2 cli-table3: 0.6.3 commander: 10.0.1 - marked: 5.1.1 - marked-terminal: 5.2.0(marked@5.1.1) - transitivePeerDependencies: - - encoding + marked: 9.1.6 + marked-terminal: 6.2.0(marked@9.1.6) + semver: 7.5.4 dev: true - /@arethetypeswrong/core@0.7.0: - resolution: {integrity: sha512-qwWmIm8YNvmSOgDXEDJUEjd1yGX4bTY0838A+wCTHlOm2n/lFhjauZjAxfKu9DHn2TSGnHahD07tGDPp4I7fSg==} + /@arethetypeswrong/core@0.15.1: + resolution: {integrity: sha512-FYp6GBAgsNz81BkfItRz8RLZO03w5+BaeiPma1uCfmxTnxbtuMrI/dbzGiOk8VghO108uFI0oJo0OkewdSHw7g==} + engines: {node: '>=18'} dependencies: - '@andrewbranch/untar.js': 1.0.2 - fetch-ponyfill: 7.1.0 - fflate: 0.7.4 + '@andrewbranch/untar.js': 1.0.3 + fflate: 0.8.2 semver: 7.5.4 - typescript: 5.1.3 + ts-expose-internals-conditionally: 1.0.0-empty.0 + typescript: 5.3.3 validate-npm-package-name: 5.0.0 - transitivePeerDependencies: - - encoding dev: true /@babel/code-frame@7.23.5: @@ -1202,6 +1205,11 @@ packages: resolution: {integrity: sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==} dev: true + /@sindresorhus/is@4.6.0: + resolution: {integrity: sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw==} + engines: {node: '>=10'} + dev: true + /@sinonjs/commons@2.0.0: resolution: {integrity: sha512-uLa0j859mMrg2slwQYdO/AkrOfmH+X6LTVmNTS9CqexuE2IvVORIkSpJLqePAbEnKJ77aMmCwr1NUZ57120Xcg==} dependencies: @@ -2283,6 +2291,11 @@ packages: engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} dev: true + /chalk@5.3.0: + resolution: {integrity: sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==} + engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} + dev: true + /char-regex@1.0.2: resolution: {integrity: sha512-kWWXztvZ5SBQV+eRgKFeh8q5sLuZY2+8WUIzlxWVTg+oGwY14qylx1KbKzHd8P6ZYkAg0xyIDU9JMHhyJMZ1jw==} engines: {node: '>=10'} @@ -2587,6 +2600,10 @@ packages: resolution: {integrity: sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==} dev: true + /emojilib@2.4.0: + resolution: {integrity: sha512-5U0rVMU5Y2n2+ykNLQqMoqklN9ICBT/KsvC1Gz6vqHbz2AXXGkG+Pm5rMWk/8Vjrr/mY9985Hi8DYzn1F09Nyw==} + dev: true + /entities@4.4.0: resolution: {integrity: sha512-oYp7156SP8LkeGD0GF85ad1X9Ai79WtRsZ2gxJqtBuzH+98YUV6jkHEKlZkMbcrjJjIVJNIDP/3WL9wQkoPbWA==} engines: {node: '>=0.12'} @@ -2945,16 +2962,8 @@ packages: bser: 2.1.1 dev: true - /fetch-ponyfill@7.1.0: - resolution: {integrity: sha512-FhbbL55dj/qdVO3YNK7ZEkshvj3eQ7EuIGV2I6ic/2YiocvyWv+7jg2s4AyS0wdRU75s3tA8ZxI/xPigb0v5Aw==} - dependencies: - node-fetch: 2.6.12 - transitivePeerDependencies: - - encoding - dev: true - - /fflate@0.7.4: - resolution: {integrity: sha512-5u2V/CDW15QM1XbbgS+0DfPxVB+jUKhWEKuuFuHncbk3tEEqzmoXL+2KyOFuKGqOnmdIy0/davWF1CkuwtibCw==} + /fflate@0.8.2: + resolution: {integrity: sha512-cPJU47OaAoCbg0pBvzsgpTPhmhqI5eJjh/JIu8tPj5q+T7iLvW/JAYUqmE7KOB4R1ZyEhzBaIQpQpardBF5z8A==} dev: true /file-entry-cache@6.0.1: @@ -4240,24 +4249,24 @@ packages: tmpl: 1.0.5 dev: true - /marked-terminal@5.2.0(marked@5.1.1): - resolution: {integrity: sha512-Piv6yNwAQXGFjZSaiNljyNFw7jKDdGrw70FSbtxEyldLsyeuV5ZHm/1wW++kWbrOF1VPnUgYOhB2oLL0ZpnekA==} - engines: {node: '>=14.13.1 || >=16.0.0'} + /marked-terminal@6.2.0(marked@9.1.6): + resolution: {integrity: sha512-ubWhwcBFHnXsjYNsu+Wndpg0zhY4CahSpPlA70PlO0rR9r2sZpkyU+rkCsOWH+KMEkx847UpALON+HWgxowFtw==} + engines: {node: '>=16.0.0'} peerDependencies: - marked: ^1.0.0 || ^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0 + marked: '>=1 <12' dependencies: ansi-escapes: 6.2.0 cardinal: 2.1.1 - chalk: 5.2.0 + chalk: 5.3.0 cli-table3: 0.6.3 - marked: 5.1.1 - node-emoji: 1.11.0 - supports-hyperlinks: 2.3.0 + marked: 9.1.6 + node-emoji: 2.1.3 + supports-hyperlinks: 3.0.0 dev: true - /marked@5.1.1: - resolution: {integrity: sha512-bTmmGdEINWmOMDjnPWDxGPQ4qkDLeYorpYbEtFOXzOruTwUE671q4Guiuchn4N8h/v6NGd7916kXsm3Iz4iUSg==} - engines: {node: '>= 18'} + /marked@9.1.6: + resolution: {integrity: sha512-jcByLnIFkd5gSXZmjNvS1TlmRhCXZjIzHYlaGkPlLIekG55JDR2Z4va9tZwCiP+/RDERiNhMOFu01xd6O5ct1Q==} + engines: {node: '>= 16'} hasBin: true dev: true @@ -4387,22 +4396,14 @@ packages: - babel-plugin-macros dev: true - /node-emoji@1.11.0: - resolution: {integrity: sha512-wo2DpQkQp7Sjm2A0cq+sN7EHKO6Sl0ctXeBdFZrL9T9+UywORbufTcTZxom8YqpLQt/FqNMUkOpkZrJVYSKD3A==} - dependencies: - lodash: 4.17.21 - dev: true - - /node-fetch@2.6.12: - resolution: {integrity: sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==} - engines: {node: 4.x || >=6.0.0} - peerDependencies: - encoding: ^0.1.0 - peerDependenciesMeta: - encoding: - optional: true + /node-emoji@2.1.3: + resolution: {integrity: sha512-E2WEOVsgs7O16zsURJ/eH8BqhF029wGpEOnv7Urwdo2wmQanOACwJQh0devF9D9RhoZru0+9JXIS0dBXIAz+lA==} + engines: {node: '>=18'} dependencies: - whatwg-url: 5.0.0 + '@sindresorhus/is': 4.6.0 + char-regex: 1.0.2 + emojilib: 2.4.0 + skin-tone: 2.0.0 dev: true /node-int64@0.4.0: @@ -5073,6 +5074,13 @@ packages: resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==} dev: true + /skin-tone@2.0.0: + resolution: {integrity: sha512-kUMbT1oBJCpgrnKoSr0o6wPtvRWT9W9UKvGLwfJYO2WuahZRHOpEyL1ckyMGgMWh0UdpmaoFqKKD29WTomNEGA==} + engines: {node: '>=8'} + dependencies: + unicode-emoji-modifier-base: 1.0.0 + dev: true + /slash@3.0.0: resolution: {integrity: sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==} engines: {node: '>=8'} @@ -5276,9 +5284,9 @@ packages: has-flag: 4.0.0 dev: true - /supports-hyperlinks@2.3.0: - resolution: {integrity: sha512-RpsAZlpWcDwOPQA22aCH4J0t7L8JmAvsCxfOSEwm7cQs3LshN36QaTkwd70DnBOXDWGssw2eUoc8CaRWT0XunA==} - engines: {node: '>=8'} + /supports-hyperlinks@3.0.0: + resolution: {integrity: sha512-QBDPHyPQDRTy9ku4URNGY5Lah8PAaXs6tAAwp55sL5WCsSW7GIfdf6W5ixfziW+t7wh3GVvHyHHyQ1ESsoRvaA==} + engines: {node: '>=14.18'} dependencies: has-flag: 4.0.0 supports-color: 7.2.0 @@ -5336,10 +5344,6 @@ packages: url-parse: 1.5.10 dev: true - /tr46@0.0.3: - resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==} - dev: true - /tr46@3.0.0: resolution: {integrity: sha512-l7FvfAHlcmulp8kr+flpQZmVwtu7nfRV7NZujtN0OqES8EL4O4e0qqzL0DC5gAvx/ZC/9lk6rhcUwYvkBnBnYA==} engines: {node: '>=12'} @@ -5347,6 +5351,10 @@ packages: punycode: 2.1.1 dev: true + /ts-expose-internals-conditionally@1.0.0-empty.0: + resolution: {integrity: sha512-F8m9NOF6ZhdOClDVdlM8gj3fDCav4ZIFSs/EI3ksQbAAXVSCN/Jh5OCJDDZWBuBy9psFc6jULGDlPwjMYMhJDw==} + dev: true + /tslib@1.14.1: resolution: {integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==} dev: true @@ -5405,6 +5413,12 @@ packages: hasBin: true dev: true + /typescript@5.3.3: + resolution: {integrity: sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==} + engines: {node: '>=14.17'} + hasBin: true + dev: true + /unbox-primitive@1.0.2: resolution: {integrity: sha512-61pPlCD9h51VoreyJ0BReideM3MDKMKnh6+V9L08331ipq6Q8OFXZYiqP6n/tbHx4s5I9uRhcye6BrbkizkBDw==} dependencies: @@ -5414,6 +5428,11 @@ packages: which-boxed-primitive: 1.0.2 dev: true + /unicode-emoji-modifier-base@1.0.0: + resolution: {integrity: sha512-yLSH4py7oFH3oG/9K+XWrz1pSi3dfUrWEnInbxMfArOfc1+33BlGPQtLsOYwvdMy11AwUBetYuaRxSPqgkq+8g==} + engines: {node: '>=4'} + dev: true + /universalify@0.2.0: resolution: {integrity: sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==} engines: {node: '>= 4.0.0'} @@ -5480,10 +5499,6 @@ packages: makeerror: 1.0.12 dev: true - /webidl-conversions@3.0.1: - resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==} - dev: true - /webidl-conversions@7.0.0: resolution: {integrity: sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==} engines: {node: '>=12'} @@ -5509,13 +5524,6 @@ packages: webidl-conversions: 7.0.0 dev: true - /whatwg-url@5.0.0: - resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==} - dependencies: - tr46: 0.0.3 - webidl-conversions: 3.0.1 - dev: true - /which-boxed-primitive@1.0.2: resolution: {integrity: sha512-bwZdv0AKLpplFY2KZRX6TvyuN7ojjr7lwkg6ml0roIy9YeuSr7JS372qlNW18UQYzgYK9ziGcerWqZOmEn9VNg==} dependencies: @@ -5640,7 +5648,3 @@ packages: resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} engines: {node: '>=10'} dev: true - -settings: - autoInstallPeers: false - excludeLinksFromLockfile: false diff --git a/test/use-swr-infinite-preload.test.tsx b/test/use-swr-infinite-preload.test.tsx index 2dadb694fd..a32840be76 100644 --- a/test/use-swr-infinite-preload.test.tsx +++ b/test/use-swr-infinite-preload.test.tsx @@ -121,7 +121,7 @@ describe('useSWRInfinite - preload', () => { expect(fetcher).toBeCalledTimes(1) }) - it('avoid suspense waterfall by prefetching the resources', async () => { + it.skip('avoid suspense waterfall by prefetching the resources', async () => { const key1 = createKey() const getKey1 = getKeyFunction(key1) const key2 = createKey() @@ -132,7 +132,6 @@ describe('useSWRInfinite - preload', () => { const fetcher1 = () => response1 const fetcher2 = () => response2 - function Page() { const { data: data1 } = useSWRInfinite(getKey1, fetcher1, { suspense: true @@ -140,16 +139,14 @@ describe('useSWRInfinite - preload', () => { const { data: data2 } = useSWRInfinite(getKey2, fetcher2, { suspense: true }) - return (
data:{data1}:{data2}
) } - preload(getKey1(0), fetcher1) - preload(getKey1(0), fetcher2) + preload(getKey2(0), fetcher2) renderWithConfig( @@ -157,7 +154,7 @@ describe('useSWRInfinite - preload', () => { ) screen.getByText('loading') - // Should avoid waterfall(50ms + 50ms) + //Should avoid waterfall(50ms + 50ms) await act(() => sleep(80)) screen.getByText('data:foo:bar') }) From cc9fc2507b40934aa4c1e4dc66f16c97ba5d411c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludwig=20B=C3=A4cklund?= Date: Thu, 2 May 2024 06:07:38 +0200 Subject: [PATCH 02/10] Add SWRInfiniteMutatorOptions type to export (#2954) --- src/infinite/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/infinite/index.ts b/src/infinite/index.ts index 99e4d2b400..0bdc556d0c 100644 --- a/src/infinite/index.ts +++ b/src/infinite/index.ts @@ -358,5 +358,6 @@ export { SWRInfiniteHook, SWRInfiniteKeyLoader, SWRInfiniteFetcher, - SWRInfiniteCompareFn + SWRInfiniteCompareFn, + SWRInfiniteMutatorOptions } From 52be4854ae3096432a2266938b9bd1f58fbefd25 Mon Sep 17 00:00:00 2001 From: Toru Kobayashi Date: Thu, 2 May 2024 13:11:53 +0900 Subject: [PATCH 03/10] test: update the revalidate function test for useSWRInfinite (#2955) --- test/use-swr-infinite.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/use-swr-infinite.test.tsx b/test/use-swr-infinite.test.tsx index ee8ee45bc2..cec8e7f462 100644 --- a/test/use-swr-infinite.test.tsx +++ b/test/use-swr-infinite.test.tsx @@ -1861,7 +1861,7 @@ describe('useSWRInfinite', () => { return (
{ - boundMutate(undefined, { + boundMutate(data, { // only revalidate 'apple' & 'pineapple' (page=2) revalidate: (d, [_, i]: [string, number]) => { return d === 'apple' || i === 2 From 5c34bfb4da0c956f42a5bb75609134a848546499 Mon Sep 17 00:00:00 2001 From: Josh Kelley Date: Thu, 2 May 2024 00:19:36 -0400 Subject: [PATCH 04/10] Export ScopedMutator type (#2937) --- src/core/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/index.ts b/src/core/index.ts index 9bc09f5d16..b5419ddb53 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -25,5 +25,6 @@ export type { MutatorOptions, Middleware, Arguments, - State + State, + ScopedMutator } from '../_internal' From 2a5000ed29aa12d000c6f1dc017672dac3044f60 Mon Sep 17 00:00:00 2001 From: taku-hatano <68222525+taku-hatano@users.noreply.github.com> Date: Thu, 9 May 2024 02:16:14 +0900 Subject: [PATCH 05/10] fix: check if config.fallback is undefined (#2913) * fix: check if config.fallback is undefined * chore: use UNDEFINED * test: test for config.fallback is undefined --- src/core/use-swr.ts | 6 +++++- test/use-swr-config.test.tsx | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/core/use-swr.ts b/src/core/use-swr.ts index 8b6644f284..9f8648c60d 100644 --- a/src/core/use-swr.ts +++ b/src/core/use-swr.ts @@ -144,7 +144,11 @@ export const useSWRHandler = ( // Resolve the fallback data from either the inline option, or the global provider. // If it's a promise, we simply let React suspend and resolve it for us. - let fallback = isUndefined(fallbackData) ? config.fallback[key] : fallbackData + let fallback = isUndefined(fallbackData) + ? isUndefined(config.fallback) + ? UNDEFINED + : config.fallback[key] + : fallbackData if (fallback && isPromiseLike(fallback)) { fallback = use(fallback) } diff --git a/test/use-swr-config.test.tsx b/test/use-swr-config.test.tsx index 87ac30a5d0..ce87a45d8b 100644 --- a/test/use-swr-config.test.tsx +++ b/test/use-swr-config.test.tsx @@ -184,4 +184,23 @@ describe('useSWR - configs', () => { expect(config.fallback).toEqual({ a: 2, c: 2 }) expect(config.use).toEqual([middleware2]) }) + + it('should not occur error when fallback is undefined', async () => { + const key = createKey() + const fetcher = () => 'data' + + function Page() { + const { data } = useSWR(key) + return
data: {data}
+ } + + renderWithConfig(, { + fetcher, + fallback: undefined + }) + // hydration + screen.getByText('data:') + // mount + await screen.findByText('data: data') + }) }) From cb2946ddcafbeedecf724aa19b3929865c026bc7 Mon Sep 17 00:00:00 2001 From: Leo McArdle Date: Sat, 11 May 2024 12:46:18 +0100 Subject: [PATCH 06/10] fix(infinte): export SWRInfiniteKeyedMutator type (#2900) * fix(types): export InfiniteKeyedMutator * type(infinite): expose SWRInfiniteKeyedMutator type --------- Co-authored-by: Toru Kobayashi --- src/infinite/index.ts | 2 ++ src/infinite/types.ts | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/infinite/index.ts b/src/infinite/index.ts index 0bdc556d0c..f410b5befb 100644 --- a/src/infinite/index.ts +++ b/src/infinite/index.ts @@ -31,6 +31,7 @@ import type { SWRInfiniteFetcher, SWRInfiniteCacheValue, SWRInfiniteCompareFn, + SWRInfiniteKeyedMutator, SWRInfiniteMutatorOptions } from './types' import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js' @@ -359,5 +360,6 @@ export { SWRInfiniteKeyLoader, SWRInfiniteFetcher, SWRInfiniteCompareFn, + SWRInfiniteKeyedMutator, SWRInfiniteMutatorOptions } diff --git a/src/infinite/types.ts b/src/infinite/types.ts index b9c58283a4..4237b6abae 100644 --- a/src/infinite/types.ts +++ b/src/infinite/types.ts @@ -47,7 +47,7 @@ interface SWRInfiniteRevalidateFn { (data: Data, key: Arguments): boolean } -type InfiniteKeyedMutator = ( +export type SWRInfiniteKeyedMutator = ( data?: Data | Promise | MutatorCallback, opts?: boolean | SWRInfiniteMutatorOptions ) => Promise @@ -65,7 +65,7 @@ export interface SWRInfiniteResponse setSize: ( size: number | ((_size: number) => number) ) => Promise - mutate: InfiniteKeyedMutator + mutate: SWRInfiniteKeyedMutator } export interface SWRInfiniteHook { From fedf233a48d40d1cd96517941b5f9e15ff2fc3ab Mon Sep 17 00:00:00 2001 From: Jiwon Choi Date: Sat, 11 May 2024 22:51:01 +0900 Subject: [PATCH 07/10] chore: add react peerDeps 19 (#2963) chore: add react peer dep 19 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 48f82533f0..949c544443 100644 --- a/package.json +++ b/package.json @@ -156,7 +156,7 @@ "typescript": "5.1.3" }, "peerDependencies": { - "react": "^16.11.0 || ^17.0.0 || ^18.0.0" + "react": "^16.11.0 || ^17.0.0 || ^18.0.0 || ^19.0.0-0" }, "prettier": { "tabWidth": 2, From 682039a43bc0d8776e609eb5f9b6eeb9f3db91ea Mon Sep 17 00:00:00 2001 From: vercel-release-bot Date: Fri, 24 May 2024 22:11:27 +0000 Subject: [PATCH 08/10] 2.2.6-beta.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 949c544443..33c28e7796 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "swr", - "version": "2.2.6-beta.2", + "version": "2.2.6-beta.3", "description": "React Hooks library for remote data fetching", "keywords": [ "swr", From b2126a6cf7df4be535851f2a1560d8478e9c4f7d Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Sat, 1 Jun 2024 01:56:39 +0200 Subject: [PATCH 09/10] fix: Improve comparison performance (#2973) use deep comparison instead of hashing the fetch body --- package.json | 1 + pnpm-lock.yaml | 16 ++++++++++++---- src/_internal/utils/config.ts | 7 ++++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 33c28e7796..81ec0c9599 100644 --- a/package.json +++ b/package.json @@ -167,6 +167,7 @@ "trailingComma": "none" }, "dependencies": { + "dequal": "^2.0.3", "use-sync-external-store": "^1.2.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ee979f3512..234663aad8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,13 +1,12 @@ lockfileVersion: '6.0' -settings: - autoInstallPeers: false - excludeLinksFromLockfile: false - importers: .: dependencies: + dequal: + specifier: ^2.0.3 + version: 2.0.3 use-sync-external-store: specifier: ^1.2.0 version: 1.2.0(react@18.2.0) @@ -2536,6 +2535,11 @@ packages: engines: {node: '>=0.4.0'} dev: true + /dequal@2.0.3: + resolution: {integrity: sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==} + engines: {node: '>=6'} + dev: false + /detect-newline@3.1.0: resolution: {integrity: sha512-TLz+x/vEXm/Y7P7wn1EJFNLxYpUD4TgMosxY6fAVJUnJMbupHBOncxyWUG9OpTaH9EBD7uFI5LfEgmMOc54DsA==} engines: {node: '>=8'} @@ -5648,3 +5652,7 @@ packages: resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} engines: {node: '>=10'} dev: true + +settings: + autoInstallPeers: false + excludeLinksFromLockfile: false diff --git a/src/_internal/utils/config.ts b/src/_internal/utils/config.ts index a2eae1b3e4..ce05caea25 100644 --- a/src/_internal/utils/config.ts +++ b/src/_internal/utils/config.ts @@ -6,12 +6,14 @@ import type { ScopedMutator, Cache } from '../types' -import { stableHash } from './hash' + import { initCache } from './cache' import { preset } from './web-preset' import { slowConnection } from './env' import { isUndefined, noop, mergeObjects } from './shared' +import { dequal } from 'dequal/lite' + // error retry const onErrorRetry = ( _: unknown, @@ -37,8 +39,7 @@ const onErrorRetry = ( setTimeout(revalidate, timeout, opts) } -const compare = (currentData: any, newData: any) => - stableHash(currentData) == stableHash(newData) +const compare = dequal // Default cache provider const [cache, mutate] = initCache(new Map()) as [Cache, ScopedMutator] From 1585a3e37d90ad0df8097b099db38f1afb43c95d Mon Sep 17 00:00:00 2001 From: vercel-release-bot Date: Fri, 31 May 2024 23:58:45 +0000 Subject: [PATCH 10/10] 2.2.6-beta.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 81ec0c9599..a727566f38 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "swr", - "version": "2.2.6-beta.3", + "version": "2.2.6-beta.4", "description": "React Hooks library for remote data fetching", "keywords": [ "swr",