diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 68ae252..fb50b70 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -37,7 +37,7 @@ jobs: registry-url: 'https://registry.npmjs.org' - name: Install pnpm - uses: pnpm/action-setup@v3 + uses: pnpm/action-setup@v4 with: version: 9 run_install: false diff --git a/demo/package.json b/demo/package.json index 1fd0583..2164a3f 100755 --- a/demo/package.json +++ b/demo/package.json @@ -1,21 +1,20 @@ { "name": "react-inlinesvg-demo", - "version": "4.0.0", + "version": "4.2.0", "description": "An SVG loader component for ReactJS", "keywords": [], "dependencies": { - "loader-utils": "3.2.1", - "react": "^18.2.0", - "react-dom": "^18.2.0", + "react": "^18.3.1", + "react-dom": "^18.3.1", "react-inlinesvg": "latest", "react-scripts": "^5.0.1", - "styled-components": "^6.0.7" + "styled-components": "^6.1.15" }, "devDependencies": { - "@types/node": "18.15.3", - "@types/react": "18.0.25", - "@types/react-dom": "18.0.9", - "typescript": "4.9.5" + "@types/node": "22.13.4", + "@types/react": "18.3.18", + "@types/react-dom": "18.3.5", + "typescript": "5.7.3" }, "scripts": { "start": "react-scripts start", diff --git a/package.json b/package.json index 9fa7470..cae5f0c 100644 --- a/package.json +++ b/package.json @@ -60,12 +60,12 @@ "@gilbarbara/tsconfig": "^0.2.3", "@size-limit/preset-small-lib": "^11.1.6", "@testing-library/jest-dom": "^6.6.3", - "@testing-library/react": "^16.1.0", - "@types/node": "^22.10.6", + "@testing-library/react": "^16.2.0", + "@types/node": "^22.13.4", "@types/react": "^18.3.18", "@types/react-dom": "^18.3.5", "@vitejs/plugin-react": "^4.3.4", - "@vitest/coverage-v8": "^2.1.8", + "@vitest/coverage-v8": "^3.0.6", "browser-cache-mock": "^0.1.7", "del-cli": "^6.0.0", "fix-tsup-cjs": "^1.2.0", @@ -79,9 +79,9 @@ "size-limit": "^11.1.6", "start-server-and-test": "^2.0.10", "ts-node": "^10.9.2", - "tsup": "^8.3.5", + "tsup": "^8.3.6", "typescript": "^5.7.3", - "vitest": "^2.1.8", + "vitest": "^3.0.6", "vitest-fetch-mock": "^0.4.3" }, "scripts": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 735e628..d474d21 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,7 +17,7 @@ importers: version: 0.17.3 '@gilbarbara/eslint-config': specifier: ^0.8.4 - version: 0.8.4(@testing-library/dom@9.3.3)(@types/eslint@8.44.2)(@typescript-eslint/utils@8.20.0(eslint@8.57.1)(typescript@5.7.3))(prettier@3.0.2)(typescript@5.7.3)(vitest@2.1.8(@types/node@22.10.6)(jsdom@26.0.0)(terser@5.19.2))(webpack@5.88.2(esbuild@0.24.0)) + version: 0.8.4(@testing-library/dom@9.3.3)(@types/eslint@8.44.2)(@typescript-eslint/utils@8.20.0(eslint@8.57.1)(typescript@5.7.3))(prettier@3.0.2)(typescript@5.7.3)(vitest@3.0.6(@types/node@22.13.4)(jsdom@26.0.0)(terser@5.19.2))(webpack@5.88.2(esbuild@0.24.0)) '@gilbarbara/prettier-config': specifier: ^1.0.0 version: 1.0.0(prettier@3.0.2) @@ -31,11 +31,11 @@ importers: specifier: ^6.6.3 version: 6.6.3 '@testing-library/react': - specifier: ^16.1.0 - version: 16.1.0(@testing-library/dom@9.3.3)(@types/react-dom@18.3.5(@types/react@18.3.18))(@types/react@18.3.18)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + specifier: ^16.2.0 + version: 16.2.0(@testing-library/dom@9.3.3)(@types/react-dom@18.3.5(@types/react@18.3.18))(@types/react@18.3.18)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@types/node': - specifier: ^22.10.6 - version: 22.10.6 + specifier: ^22.13.4 + version: 22.13.4 '@types/react': specifier: ^18.3.18 version: 18.3.18 @@ -44,10 +44,10 @@ importers: version: 18.3.5(@types/react@18.3.18) '@vitejs/plugin-react': specifier: ^4.3.4 - version: 4.3.4(vite@5.0.12(@types/node@22.10.6)(terser@5.19.2)) + version: 4.3.4(vite@5.0.12(@types/node@22.13.4)(terser@5.19.2)) '@vitest/coverage-v8': - specifier: ^2.1.8 - version: 2.1.8(vitest@2.1.8(@types/node@22.10.6)(jsdom@26.0.0)(terser@5.19.2)) + specifier: ^3.0.6 + version: 3.0.6(vitest@3.0.6(@types/node@22.13.4)(jsdom@26.0.0)(terser@5.19.2)) browser-cache-mock: specifier: ^0.1.7 version: 0.1.7 @@ -86,19 +86,19 @@ importers: version: 2.0.10 ts-node: specifier: ^10.9.2 - version: 10.9.2(@types/node@22.10.6)(typescript@5.7.3) + version: 10.9.2(@types/node@22.13.4)(typescript@5.7.3) tsup: - specifier: ^8.3.5 - version: 8.3.5(jiti@2.3.3)(postcss@8.4.33)(typescript@5.7.3) + specifier: ^8.3.6 + version: 8.3.6(jiti@2.3.3)(postcss@8.4.33)(typescript@5.7.3) typescript: specifier: ^5.7.3 version: 5.7.3 vitest: - specifier: ^2.1.8 - version: 2.1.8(@types/node@22.10.6)(jsdom@26.0.0)(terser@5.19.2) + specifier: ^3.0.6 + version: 3.0.6(@types/node@22.13.4)(jsdom@26.0.0)(terser@5.19.2) vitest-fetch-mock: specifier: ^0.4.3 - version: 0.4.3(vitest@2.1.8(@types/node@22.10.6)(jsdom@26.0.0)(terser@5.19.2)) + version: 0.4.3(vitest@3.0.6(@types/node@22.13.4)(jsdom@26.0.0)(terser@5.19.2)) packages: @@ -302,8 +302,9 @@ packages: resolution: {integrity: sha512-L6mZmwFDK6Cjh1nRCLXpa6no13ZIioJDz7mdkzHv399pThrTa/k0nUlNaenOeh2kWu/iaOQYElEpKPUswUa9Vg==} engines: {node: '>=6.9.0'} - '@bcoe/v8-coverage@0.2.3': - resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==} + '@bcoe/v8-coverage@1.0.2': + resolution: {integrity: sha512-6zABk/ECA/QYSCQ1NGiVwwbQerUCZ+TQbp64Q3AgmfNvurHH0j8TtXa1qbShXA6qqkpAj4V5W8pP6mLe1mcMqA==} + engines: {node: '>=18'} '@colors/colors@1.5.0': resolution: {integrity: sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==} @@ -875,8 +876,8 @@ packages: resolution: {integrity: sha512-IteBhl4XqYNkM54f4ejhLRJiZNqcSCoXUOG2CPK7qbD322KjQozM4kHQOfkG2oln9b9HTYqs+Sae8vBATubxxA==} engines: {node: '>=14', npm: '>=6', yarn: '>=1'} - '@testing-library/react@16.1.0': - resolution: {integrity: sha512-Q2ToPvg0KsVL0ohND9A3zLJWcOXXcO8IDu3fj11KhNt0UlCWyFyvnCIBkd12tidB2lkiVRG8VFqdhcqhqnAQtg==} + '@testing-library/react@16.2.0': + resolution: {integrity: sha512-2cSskAvA1QNtKc8Y9VJQRv0tm3hLVgxRGDB+KYhIaPQJ1I+RHbhIXcM+zClKXzMes/wshsMVzf4B9vS4IZpqDQ==} engines: {node: '>=18'} peerDependencies: '@testing-library/dom': ^10.0.0 @@ -932,8 +933,8 @@ packages: '@types/json5@0.0.29': resolution: {integrity: sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==} - '@types/node@22.10.6': - resolution: {integrity: sha512-qNiuwC4ZDAUNcY47xgaSuS92cjf8JbSUoaKS77bmLG1rU7MlATVSiw/IlrjtIyyskXBZ8KkNfjK/P5na7rgXbQ==} + '@types/node@22.13.4': + resolution: {integrity: sha512-ywP2X0DYtX3y08eFVx5fNIw7/uIv8hYUKgXoK8oayJlLnKcRfEYCxWMVE1XagUdVtCJlZT1AU4LXEABW+L1Peg==} '@types/normalize-package-data@2.4.1': resolution: {integrity: sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==} @@ -1032,11 +1033,11 @@ packages: peerDependencies: vite: ^4.2.0 || ^5.0.0 || ^6.0.0 - '@vitest/coverage-v8@2.1.8': - resolution: {integrity: sha512-2Y7BPlKH18mAZYAW1tYByudlCYrQyl5RGvnnDYJKW5tCiO5qg3KSAy3XAxcxKz900a0ZXxWtKrMuZLe3lKBpJw==} + '@vitest/coverage-v8@3.0.6': + resolution: {integrity: sha512-JRTlR8Bw+4BcmVTICa7tJsxqphAktakiLsAmibVLAWbu1lauFddY/tXeM6sAyl1cgkPuXtpnUgaCPhTdz1Qapg==} peerDependencies: - '@vitest/browser': 2.1.8 - vitest: 2.1.8 + '@vitest/browser': 3.0.6 + vitest: 3.0.6 peerDependenciesMeta: '@vitest/browser': optional: true @@ -1054,34 +1055,34 @@ packages: vitest: optional: true - '@vitest/expect@2.1.8': - resolution: {integrity: sha512-8ytZ/fFHq2g4PJVAtDX57mayemKgDR6X3Oa2Foro+EygiOJHUXhCqBAAKQYYajZpFoIfvBCF1j6R6IYRSIUFuw==} + '@vitest/expect@3.0.6': + resolution: {integrity: sha512-zBduHf/ja7/QRX4HdP1DSq5XrPgdN+jzLOwaTq/0qZjYfgETNFCKf9nOAp2j3hmom3oTbczuUzrzg9Hafh7hNg==} - '@vitest/mocker@2.1.8': - resolution: {integrity: sha512-7guJ/47I6uqfttp33mgo6ga5Gr1VnL58rcqYKyShoRK9ebu8T5Rs6HN3s1NABiBeVTdWNrwUMcHH54uXZBN4zA==} + '@vitest/mocker@3.0.6': + resolution: {integrity: sha512-KPztr4/tn7qDGZfqlSPQoF2VgJcKxnDNhmfR3VgZ6Fy1bO8T9Fc1stUiTXtqz0yG24VpD00pZP5f8EOFknjNuQ==} peerDependencies: msw: ^2.4.9 - vite: ^5.0.0 + vite: ^5.0.0 || ^6.0.0 peerDependenciesMeta: msw: optional: true vite: optional: true - '@vitest/pretty-format@2.1.8': - resolution: {integrity: sha512-9HiSZ9zpqNLKlbIDRWOnAWqgcA7xu+8YxXSekhr0Ykab7PAYFkhkwoqVArPOtJhPmYeE2YHgKZlj3CP36z2AJQ==} + '@vitest/pretty-format@3.0.6': + resolution: {integrity: sha512-Zyctv3dbNL+67qtHfRnUE/k8qxduOamRfAL1BurEIQSyOEFffoMvx2pnDSSbKAAVxY0Ej2J/GH2dQKI0W2JyVg==} - '@vitest/runner@2.1.8': - resolution: {integrity: sha512-17ub8vQstRnRlIU5k50bG+QOMLHRhYPAna5tw8tYbj+jzjcspnwnwtPtiOlkuKC4+ixDPTuLZiqiWWQ2PSXHVg==} + '@vitest/runner@3.0.6': + resolution: {integrity: sha512-JopP4m/jGoaG1+CBqubV/5VMbi7L+NQCJTu1J1Pf6YaUbk7bZtaq5CX7p+8sY64Sjn1UQ1XJparHfcvTTdu9cA==} - '@vitest/snapshot@2.1.8': - resolution: {integrity: sha512-20T7xRFbmnkfcmgVEz+z3AU/3b0cEzZOt/zmnvZEctg64/QZbSDJEVm9fLnnlSi74KibmRsO9/Qabi+t0vCRPg==} + '@vitest/snapshot@3.0.6': + resolution: {integrity: sha512-qKSmxNQwT60kNwwJHMVwavvZsMGXWmngD023OHSgn873pV0lylK7dwBTfYP7e4URy5NiBCHHiQGA9DHkYkqRqg==} - '@vitest/spy@2.1.8': - resolution: {integrity: sha512-5swjf2q95gXeYPevtW0BLk6H8+bPlMb4Vw/9Em4hFxDcaOxS+e0LOX4yqNxoHzMR2akEB2xfpnWUzkZokmgWDg==} + '@vitest/spy@3.0.6': + resolution: {integrity: sha512-HfOGx/bXtjy24fDlTOpgiAEJbRfFxoX3zIGagCqACkFKKZ/TTOE6gYMKXlqecvxEndKFuNHcHqP081ggZ2yM0Q==} - '@vitest/utils@2.1.8': - resolution: {integrity: sha512-dwSoui6djdwbfFmIgbIjX2ZhIoG7Ex/+xpxyiEgIGzjliY8xGkcpITKTlp6B4MgtGkF2ilvm97cPM96XZaAgcA==} + '@vitest/utils@3.0.6': + resolution: {integrity: sha512-18ktZpf4GQFTbf9jK543uspU03Q2qya7ZGya5yiZ0Gx0nnnalBvd5ZBislbl2EhLjM8A8rt4OilqKG7QwcGkvQ==} '@webassemblyjs/ast@1.11.6': resolution: {integrity: sha512-IN1xI7PwOvLPgjcf180gC1bqn3q/QaOCwYUahIOhbYUu8KA/3tw2RT/T0Gidi1l7Hhj5D/INhJxiICObqpMu4Q==} @@ -1367,8 +1368,8 @@ packages: caniuse-lite@1.0.30001669: resolution: {integrity: sha512-DlWzFDJqstqtIVx1zeSpIMLjunf5SmwOw0N2Ck/QSQdS8PLS4+9HrLaYei4w8BIAL7IB/UEDu889d8vhCTPA0w==} - chai@5.1.2: - resolution: {integrity: sha512-aGtmf24DW6MLHHG5gCx4zaI3uBq3KRtxeVs0DjFH6Z0rDNbsvTxFASFvdj79pxjxZ8/5u3PIiN3IwEIQkiiuPw==} + chai@5.2.0: + resolution: {integrity: sha512-mCuXncKXk5iCLhfhwTc0izo0gtEmpz5CtG2y8GiOINBlMVS6v8TMRc5TaLWKS6692m9+dVVfzgeVxR5UxWHTYw==} engines: {node: '>=12'} chalk@2.4.2: @@ -1687,6 +1688,9 @@ packages: es-module-lexer@1.5.4: resolution: {integrity: sha512-MVNK56NiMrOwitFB7cqDwq0CQutbw+0BvLshJSse0MUNU+y1FC3bUS/AQg7oUng+/wKrrki7JfmwtVHkVfPLlw==} + es-module-lexer@1.6.0: + resolution: {integrity: sha512-qqnD1yMU6tk/jnaMosogGySTZP8YtUgAffA9nMN+E/rjxcfRQ6IEk7IiozUjgxKoFHBGjTLnrHB/YC45r/59EQ==} + es-object-atoms@1.0.0: resolution: {integrity: sha512-MZ4iQ6JwHOBQjahnjwaC1ZtIBH+2ohjamzAO3oaHcXYup7qxjF2fixyH+Q71voWHeOkI2q/TnJao/KfXYIZWbw==} engines: {node: '>= 0.4'} @@ -2681,6 +2685,9 @@ packages: loupe@3.1.2: resolution: {integrity: sha512-23I4pFZHmAemUnz8WZXbYRSKYj801VDaNv9ETuMh7IrMc7VuVVSo+Z9iLE3ni30+U48iDWfi30d3twAXBYmnCg==} + loupe@3.1.3: + resolution: {integrity: sha512-kkIp7XSkP78ZxJEsSxW3712C6teJVoeHHwgo9zJ380de7IYyJ2ISlxojcH2pC5OFLewESmnRi/+XCDIEEVyoug==} + lru-cache@10.0.1: resolution: {integrity: sha512-IJ4uwUTi2qCccrioU6g9g/5rvvVl13bsdczUUcqbciD9iLr095yj8DQKdObriEvuNSx325N1rV1O0sJFszx75g==} engines: {node: 14 || >=16.14} @@ -2703,8 +2710,8 @@ packages: resolution: {integrity: sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==} hasBin: true - magic-string@0.30.12: - resolution: {integrity: sha512-Ea8I3sQMVXr8JhN4z+H/d8zwo+tYDgHE9+5G4Wnrwhs0gaK9fXTKx0Tw5Xwsd/bCPTTZNRAdpyzvoeORe9LYpw==} + magic-string@0.30.17: + resolution: {integrity: sha512-sNPKHvyjVf7gyjwS4xGTaW/mCnF8wnjtifKBEhxfZ7E/S8tQ0rssrwGNn6q8JH/ohItJfSQp9mBtQYuTlH5QnA==} magicast@0.3.5: resolution: {integrity: sha512-L0WhttDl+2BOsybvEOLK7fW3UA0OQ0IQ2d6Zl2x/a6vVRs3bAY0ECOSHHeL5jD+SbOpOCUEi0y1DgHEn9Qn1AQ==} @@ -2988,8 +2995,8 @@ packages: resolution: {integrity: sha512-5HviZNaZcfqP95rwpv+1HDgUamezbqdSYTyzjTvwtJSnIH+3vnbmWsItli8OFEndS984VT55M3jduxZbX351gg==} engines: {node: '>=12'} - pathe@1.1.2: - resolution: {integrity: sha512-whLdWMYL2TwI08hn8/ZqAbrVemu0LNaNNJZX73O6qaIdCTfXutsLhMkjdENX0qhsQ9uIimo4/aQOmXkoon2nDQ==} + pathe@2.0.3: + resolution: {integrity: sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==} pathval@2.0.0: resolution: {integrity: sha512-vE7JKRyES09KiunauX7nd2Q9/L7lhok4smP9RZTDeD4MVs72Dp2qNFVz39Nz5a0FVEW0BJR6C0DYrq6unoziZA==} @@ -3543,16 +3550,19 @@ packages: tinyexec@0.3.1: resolution: {integrity: sha512-WiCJLEECkO18gwqIp6+hJg0//p23HXp4S+gGtAKu3mI2F2/sXC4FvHvXvB0zJVVaTPhx1/tOwdbRsa1sOBIKqQ==} + tinyexec@0.3.2: + resolution: {integrity: sha512-KQQR9yN7R5+OSwaK0XQoj22pwHoTlgYqmUscPYoknOoWCWfj/5/ABTMRi69FrKU5ffPVh5QcFikpWJI/P1ocHA==} + tinyglobby@0.2.9: resolution: {integrity: sha512-8or1+BGEdk1Zkkw2ii16qSS7uVrQJPre5A9o/XkWPATkk23FZh/15BKFxPnlTy6vkljZxLqYCzzBMj30ZrSvjw==} engines: {node: '>=12.0.0'} - tinypool@1.0.1: - resolution: {integrity: sha512-URZYihUbRPcGv95En+sz6MfghfIc2OJ1sv/RmhWZLouPY0/8Vo80viwPvg3dlaS9fuq7fQMEfgRRK7BBZThBEA==} + tinypool@1.0.2: + resolution: {integrity: sha512-al6n+QEANGFOMf/dmUMsuS5/r9B06uwlyNjZZql/zv8J7ybHCgoihBNORZCY2mzUuAnomQa2JdhyHKzZxPCrFA==} engines: {node: ^18.0.0 || >=20.0.0} - tinyrainbow@1.2.0: - resolution: {integrity: sha512-weEDEq7Z5eTHPDh4xjX789+fHfF+P8boiFB+0vbWzpbnbsEr/GRaohi/uMKxg8RZMXnl1ItAi/IUHWMsjDV7kQ==} + tinyrainbow@2.0.0: + resolution: {integrity: sha512-op4nsTR47R6p0vMUUoYl/a+ljLFVtlfaXkLQmqfLR1qHma1h/ysYk4hEXZ880bf2CYgTskvTa/e196Vd5dDQXw==} engines: {node: '>=14.0.0'} tinyspy@3.0.2: @@ -3624,8 +3634,8 @@ packages: tslib@2.6.2: resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} - tsup@8.3.5: - resolution: {integrity: sha512-Tunf6r6m6tnZsG9GYWndg0z8dEV7fD733VBFzFJ5Vcm1FtlXB8xBD/rtrBi2a3YKEV7hHtxiZtW5EAVADoe1pA==} + tsup@8.3.6: + resolution: {integrity: sha512-XkVtlDV/58S9Ye0JxUUTcrQk4S+EqlOHKzg6Roa62rdjL1nGWNUstG0xgI4vanHdfIpjP448J8vlN0oK6XOJ5g==} engines: {node: '>=18'} hasBin: true peerDependencies: @@ -3753,9 +3763,9 @@ packages: resolution: {integrity: sha512-YuKoXDAhBYxY7SfOKxHBDoSyENFeW5VvIIQp2TGQuit8gpK6MnWaQelBKxso72DoxTZfZdcP3W90LqpSkgPzLQ==} engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} - vite-node@2.1.8: - resolution: {integrity: sha512-uPAwSr57kYjAUux+8E2j0q0Fxpn8M9VoyfGiRI8Kfktz9NcYMCenwY5RnZxnF1WTu3TGiYipirIzacLL3VVGFg==} - engines: {node: ^18.0.0 || >=20.0.0} + vite-node@3.0.6: + resolution: {integrity: sha512-s51RzrTkXKJrhNbUzQRsarjmAae7VmMPAsRT7lppVpIg6mK3zGthP9Hgz0YQQKuNcF+Ii7DfYk3Fxz40jRmePw==} + engines: {node: ^18.0.0 || ^20.0.0 || >=22.0.0} hasBin: true vite@5.0.12: @@ -3792,20 +3802,23 @@ packages: peerDependencies: vitest: '>=2.0.0' - vitest@2.1.8: - resolution: {integrity: sha512-1vBKTZskHw/aosXqQUlVWWlGUxSJR8YtiyZDJAFeW2kPAeX6S3Sool0mjspO+kXLuxVWlEDDowBAeqeAQefqLQ==} - engines: {node: ^18.0.0 || >=20.0.0} + vitest@3.0.6: + resolution: {integrity: sha512-/iL1Sc5VeDZKPDe58oGK4HUFLhw6b5XdY1MYawjuSaDA4sEfYlY9HnS6aCEG26fX+MgUi7MwlduTBHHAI/OvMA==} + engines: {node: ^18.0.0 || ^20.0.0 || >=22.0.0} hasBin: true peerDependencies: '@edge-runtime/vm': '*' - '@types/node': ^18.0.0 || >=20.0.0 - '@vitest/browser': 2.1.8 - '@vitest/ui': 2.1.8 + '@types/debug': ^4.1.12 + '@types/node': ^18.0.0 || ^20.0.0 || >=22.0.0 + '@vitest/browser': 3.0.6 + '@vitest/ui': 3.0.6 happy-dom: '*' jsdom: '*' peerDependenciesMeta: '@edge-runtime/vm': optional: true + '@types/debug': + optional: true '@types/node': optional: true '@vitest/browser': @@ -4209,7 +4222,7 @@ snapshots: '@babel/parser': 7.26.5 '@babel/template': 7.25.9 '@babel/types': 7.26.5 - debug: 4.3.7 + debug: 4.4.0 globals: 11.12.0 transitivePeerDependencies: - supports-color @@ -4225,7 +4238,7 @@ snapshots: '@babel/helper-string-parser': 7.25.9 '@babel/helper-validator-identifier': 7.25.9 - '@bcoe/v8-coverage@0.2.3': {} + '@bcoe/v8-coverage@1.0.2': {} '@colors/colors@1.5.0': optional: true @@ -4405,7 +4418,7 @@ snapshots: '@eslint/eslintrc@2.1.4': dependencies: ajv: 6.12.6 - debug: 4.3.7 + debug: 4.4.0 espree: 9.6.1 globals: 13.21.0 ignore: 5.3.2 @@ -4418,7 +4431,7 @@ snapshots: '@eslint/js@8.57.1': {} - '@gilbarbara/eslint-config@0.8.4(@testing-library/dom@9.3.3)(@types/eslint@8.44.2)(@typescript-eslint/utils@8.20.0(eslint@8.57.1)(typescript@5.7.3))(prettier@3.0.2)(typescript@5.7.3)(vitest@2.1.8(@types/node@22.10.6)(jsdom@26.0.0)(terser@5.19.2))(webpack@5.88.2(esbuild@0.24.0))': + '@gilbarbara/eslint-config@0.8.4(@testing-library/dom@9.3.3)(@types/eslint@8.44.2)(@typescript-eslint/utils@8.20.0(eslint@8.57.1)(typescript@5.7.3))(prettier@3.0.2)(typescript@5.7.3)(vitest@3.0.6(@types/node@22.13.4)(jsdom@26.0.0)(terser@5.19.2))(webpack@5.88.2(esbuild@0.24.0))': dependencies: '@babel/core': 7.26.0 '@babel/eslint-parser': 7.26.5(@babel/core@7.26.0)(eslint@8.57.1) @@ -4426,7 +4439,7 @@ snapshots: '@babel/preset-react': 7.26.3(@babel/core@7.26.0) '@typescript-eslint/eslint-plugin': 8.20.0(@typescript-eslint/parser@8.20.0(eslint@8.57.1)(typescript@5.7.3))(eslint@8.57.1)(typescript@5.7.3) '@typescript-eslint/parser': 8.20.0(eslint@8.57.1)(typescript@5.7.3) - '@vitest/eslint-plugin': 1.1.25(@typescript-eslint/utils@8.20.0(eslint@8.57.1)(typescript@5.7.3))(eslint@8.57.1)(typescript@5.7.3)(vitest@2.1.8(@types/node@22.10.6)(jsdom@26.0.0)(terser@5.19.2)) + '@vitest/eslint-plugin': 1.1.25(@typescript-eslint/utils@8.20.0(eslint@8.57.1)(typescript@5.7.3))(eslint@8.57.1)(typescript@5.7.3)(vitest@3.0.6(@types/node@22.13.4)(jsdom@26.0.0)(terser@5.19.2)) eslint: 8.57.1 eslint-config-airbnb: 19.0.4(eslint-plugin-import@2.31.0)(eslint-plugin-jsx-a11y@6.10.2(eslint@8.57.1))(eslint-plugin-react-hooks@5.1.0(eslint@8.57.1))(eslint-plugin-react@7.37.4(eslint@8.57.1))(eslint@8.57.1) eslint-config-airbnb-base: 15.0.0(eslint-plugin-import@2.31.0)(eslint@8.57.1) @@ -4448,7 +4461,7 @@ snapshots: prettier: 3.0.2 typescript: 5.7.3 optionalDependencies: - vitest: 2.1.8(@types/node@22.10.6)(jsdom@26.0.0)(terser@5.19.2) + vitest: 3.0.6(@types/node@22.13.4)(jsdom@26.0.0)(terser@5.19.2) transitivePeerDependencies: - '@testing-library/dom' - '@types/eslint' @@ -4472,7 +4485,7 @@ snapshots: '@humanwhocodes/config-array@0.13.0': dependencies: '@humanwhocodes/object-schema': 2.0.3 - debug: 4.3.7 + debug: 4.4.0 minimatch: 3.1.2 transitivePeerDependencies: - supports-color @@ -4499,7 +4512,7 @@ snapshots: '@jridgewell/gen-mapping@0.3.5': dependencies: '@jridgewell/set-array': 1.2.1 - '@jridgewell/sourcemap-codec': 1.4.15 + '@jridgewell/sourcemap-codec': 1.5.0 '@jridgewell/trace-mapping': 0.3.25 '@jridgewell/resolve-uri@3.1.1': {} @@ -4518,7 +4531,7 @@ snapshots: '@jridgewell/trace-mapping@0.3.25': dependencies: '@jridgewell/resolve-uri': 3.1.1 - '@jridgewell/sourcemap-codec': 1.4.15 + '@jridgewell/sourcemap-codec': 1.5.0 '@jridgewell/trace-mapping@0.3.9': dependencies: @@ -4649,7 +4662,7 @@ snapshots: lodash: 4.17.21 redent: 3.0.0 - '@testing-library/react@16.1.0(@testing-library/dom@9.3.3)(@types/react-dom@18.3.5(@types/react@18.3.18))(@types/react@18.3.18)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': + '@testing-library/react@16.2.0(@testing-library/dom@9.3.3)(@types/react-dom@18.3.5(@types/react@18.3.18))(@types/react@18.3.18)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': dependencies: '@babel/runtime': 7.23.8 '@testing-library/dom': 9.3.3 @@ -4706,7 +4719,7 @@ snapshots: '@types/json5@0.0.29': {} - '@types/node@22.10.6': + '@types/node@22.13.4': dependencies: undici-types: 6.20.0 @@ -4766,7 +4779,7 @@ snapshots: dependencies: '@typescript-eslint/typescript-estree': 8.20.0(typescript@5.7.3) '@typescript-eslint/utils': 8.20.0(eslint@8.57.1)(typescript@5.7.3) - debug: 4.3.7 + debug: 4.4.0 eslint: 8.57.1 ts-api-utils: 2.0.0(typescript@5.7.3) typescript: 5.7.3 @@ -4781,7 +4794,7 @@ snapshots: dependencies: '@typescript-eslint/types': 8.11.0 '@typescript-eslint/visitor-keys': 8.11.0 - debug: 4.3.7 + debug: 4.4.0 fast-glob: 3.3.2 is-glob: 4.0.3 minimatch: 9.0.5 @@ -4796,7 +4809,7 @@ snapshots: dependencies: '@typescript-eslint/types': 8.20.0 '@typescript-eslint/visitor-keys': 8.20.0 - debug: 4.3.7 + debug: 4.4.0 fast-glob: 3.3.2 is-glob: 4.0.3 minimatch: 9.0.5 @@ -4840,82 +4853,82 @@ snapshots: '@ungap/structured-clone@1.2.0': {} - '@vitejs/plugin-react@4.3.4(vite@5.0.12(@types/node@22.10.6)(terser@5.19.2))': + '@vitejs/plugin-react@4.3.4(vite@5.0.12(@types/node@22.13.4)(terser@5.19.2))': dependencies: '@babel/core': 7.26.0 '@babel/plugin-transform-react-jsx-self': 7.25.9(@babel/core@7.26.0) '@babel/plugin-transform-react-jsx-source': 7.25.9(@babel/core@7.26.0) '@types/babel__core': 7.20.5 react-refresh: 0.14.2 - vite: 5.0.12(@types/node@22.10.6)(terser@5.19.2) + vite: 5.0.12(@types/node@22.13.4)(terser@5.19.2) transitivePeerDependencies: - supports-color - '@vitest/coverage-v8@2.1.8(vitest@2.1.8(@types/node@22.10.6)(jsdom@26.0.0)(terser@5.19.2))': + '@vitest/coverage-v8@3.0.6(vitest@3.0.6(@types/node@22.13.4)(jsdom@26.0.0)(terser@5.19.2))': dependencies: '@ampproject/remapping': 2.3.0 - '@bcoe/v8-coverage': 0.2.3 - debug: 4.3.7 + '@bcoe/v8-coverage': 1.0.2 + debug: 4.4.0 istanbul-lib-coverage: 3.2.2 istanbul-lib-report: 3.0.1 istanbul-lib-source-maps: 5.0.6 istanbul-reports: 3.1.7 - magic-string: 0.30.12 + magic-string: 0.30.17 magicast: 0.3.5 std-env: 3.8.0 test-exclude: 7.0.1 - tinyrainbow: 1.2.0 - vitest: 2.1.8(@types/node@22.10.6)(jsdom@26.0.0)(terser@5.19.2) + tinyrainbow: 2.0.0 + vitest: 3.0.6(@types/node@22.13.4)(jsdom@26.0.0)(terser@5.19.2) transitivePeerDependencies: - supports-color - '@vitest/eslint-plugin@1.1.25(@typescript-eslint/utils@8.20.0(eslint@8.57.1)(typescript@5.7.3))(eslint@8.57.1)(typescript@5.7.3)(vitest@2.1.8(@types/node@22.10.6)(jsdom@26.0.0)(terser@5.19.2))': + '@vitest/eslint-plugin@1.1.25(@typescript-eslint/utils@8.20.0(eslint@8.57.1)(typescript@5.7.3))(eslint@8.57.1)(typescript@5.7.3)(vitest@3.0.6(@types/node@22.13.4)(jsdom@26.0.0)(terser@5.19.2))': dependencies: '@typescript-eslint/utils': 8.20.0(eslint@8.57.1)(typescript@5.7.3) eslint: 8.57.1 optionalDependencies: typescript: 5.7.3 - vitest: 2.1.8(@types/node@22.10.6)(jsdom@26.0.0)(terser@5.19.2) + vitest: 3.0.6(@types/node@22.13.4)(jsdom@26.0.0)(terser@5.19.2) - '@vitest/expect@2.1.8': + '@vitest/expect@3.0.6': dependencies: - '@vitest/spy': 2.1.8 - '@vitest/utils': 2.1.8 - chai: 5.1.2 - tinyrainbow: 1.2.0 + '@vitest/spy': 3.0.6 + '@vitest/utils': 3.0.6 + chai: 5.2.0 + tinyrainbow: 2.0.0 - '@vitest/mocker@2.1.8(vite@5.0.12(@types/node@22.10.6)(terser@5.19.2))': + '@vitest/mocker@3.0.6(vite@5.0.12(@types/node@22.13.4)(terser@5.19.2))': dependencies: - '@vitest/spy': 2.1.8 + '@vitest/spy': 3.0.6 estree-walker: 3.0.3 - magic-string: 0.30.12 + magic-string: 0.30.17 optionalDependencies: - vite: 5.0.12(@types/node@22.10.6)(terser@5.19.2) + vite: 5.0.12(@types/node@22.13.4)(terser@5.19.2) - '@vitest/pretty-format@2.1.8': + '@vitest/pretty-format@3.0.6': dependencies: - tinyrainbow: 1.2.0 + tinyrainbow: 2.0.0 - '@vitest/runner@2.1.8': + '@vitest/runner@3.0.6': dependencies: - '@vitest/utils': 2.1.8 - pathe: 1.1.2 + '@vitest/utils': 3.0.6 + pathe: 2.0.3 - '@vitest/snapshot@2.1.8': + '@vitest/snapshot@3.0.6': dependencies: - '@vitest/pretty-format': 2.1.8 - magic-string: 0.30.12 - pathe: 1.1.2 + '@vitest/pretty-format': 3.0.6 + magic-string: 0.30.17 + pathe: 2.0.3 - '@vitest/spy@2.1.8': + '@vitest/spy@3.0.6': dependencies: tinyspy: 3.0.2 - '@vitest/utils@2.1.8': + '@vitest/utils@3.0.6': dependencies: - '@vitest/pretty-format': 2.1.8 - loupe: 3.1.2 - tinyrainbow: 1.2.0 + '@vitest/pretty-format': 3.0.6 + loupe: 3.1.3 + tinyrainbow: 2.0.0 '@webassemblyjs/ast@1.11.6': dependencies: @@ -5011,7 +5024,7 @@ snapshots: agent-base@7.1.0: dependencies: - debug: 4.3.7 + debug: 4.4.0 transitivePeerDependencies: - supports-color @@ -5256,7 +5269,7 @@ snapshots: caniuse-lite@1.0.30001669: {} - chai@5.1.2: + chai@5.2.0: dependencies: assertion-error: 2.0.1 check-error: 2.1.1 @@ -5693,6 +5706,8 @@ snapshots: es-module-lexer@1.5.4: {} + es-module-lexer@1.6.0: {} + es-object-atoms@1.0.0: dependencies: es-errors: 1.3.0 @@ -6696,7 +6711,7 @@ snapshots: istanbul-lib-source-maps@5.0.6: dependencies: '@jridgewell/trace-mapping': 0.3.25 - debug: 4.3.7 + debug: 4.4.0 istanbul-lib-coverage: 3.2.2 transitivePeerDependencies: - supports-color @@ -6737,7 +6752,7 @@ snapshots: jest-worker@27.5.1: dependencies: - '@types/node': 22.10.6 + '@types/node': 22.13.4 merge-stream: 2.0.0 supports-color: 8.1.1 @@ -6857,6 +6872,8 @@ snapshots: loupe@3.1.2: {} + loupe@3.1.3: {} + lru-cache@10.0.1: {} lru-cache@10.4.3: {} @@ -6873,14 +6890,14 @@ snapshots: lz-string@1.5.0: {} - magic-string@0.30.12: + magic-string@0.30.17: dependencies: '@jridgewell/sourcemap-codec': 1.5.0 magicast@0.3.5: dependencies: - '@babel/parser': 7.25.8 - '@babel/types': 7.25.8 + '@babel/parser': 7.26.5 + '@babel/types': 7.26.5 source-map-js: 1.2.1 make-dir@4.0.0: @@ -7155,7 +7172,7 @@ snapshots: path-type@5.0.0: {} - pathe@1.1.2: {} + pathe@2.0.3: {} pathval@2.0.0: {} @@ -7773,14 +7790,16 @@ snapshots: tinyexec@0.3.1: {} + tinyexec@0.3.2: {} + tinyglobby@0.2.9: dependencies: fdir: 6.4.2(picomatch@4.0.2) picomatch: 4.0.2 - tinypool@1.0.1: {} + tinypool@1.0.2: {} - tinyrainbow@1.2.0: {} + tinyrainbow@2.0.0: {} tinyspy@3.0.2: {} @@ -7820,14 +7839,14 @@ snapshots: ts-interface-checker@0.1.13: {} - ts-node@10.9.2(@types/node@22.10.6)(typescript@5.7.3): + ts-node@10.9.2(@types/node@22.13.4)(typescript@5.7.3): dependencies: '@cspotcode/source-map-support': 0.8.1 '@tsconfig/node10': 1.0.9 '@tsconfig/node12': 1.0.11 '@tsconfig/node14': 1.0.3 '@tsconfig/node16': 1.0.4 - '@types/node': 22.10.6 + '@types/node': 22.13.4 acorn: 8.10.0 acorn-walk: 8.2.0 arg: 4.1.3 @@ -7847,13 +7866,13 @@ snapshots: tslib@2.6.2: {} - tsup@8.3.5(jiti@2.3.3)(postcss@8.4.33)(typescript@5.7.3): + tsup@8.3.6(jiti@2.3.3)(postcss@8.4.33)(typescript@5.7.3): dependencies: bundle-require: 5.0.0(esbuild@0.24.0) cac: 6.7.14 chokidar: 4.0.1 consola: 3.2.3 - debug: 4.3.7 + debug: 4.4.0 esbuild: 0.24.0 joycon: 3.1.1 picocolors: 1.1.1 @@ -8004,13 +8023,13 @@ snapshots: dependencies: builtins: 5.0.1 - vite-node@2.1.8(@types/node@22.10.6)(terser@5.19.2): + vite-node@3.0.6(@types/node@22.13.4)(terser@5.19.2): dependencies: cac: 6.7.14 - debug: 4.3.7 - es-module-lexer: 1.5.4 - pathe: 1.1.2 - vite: 5.0.12(@types/node@22.10.6)(terser@5.19.2) + debug: 4.4.0 + es-module-lexer: 1.6.0 + pathe: 2.0.3 + vite: 5.0.12(@types/node@22.13.4)(terser@5.19.2) transitivePeerDependencies: - '@types/node' - less @@ -8021,44 +8040,44 @@ snapshots: - supports-color - terser - vite@5.0.12(@types/node@22.10.6)(terser@5.19.2): + vite@5.0.12(@types/node@22.13.4)(terser@5.19.2): dependencies: esbuild: 0.19.11 postcss: 8.4.33 rollup: 4.24.0 optionalDependencies: - '@types/node': 22.10.6 + '@types/node': 22.13.4 fsevents: 2.3.3 terser: 5.19.2 - vitest-fetch-mock@0.4.3(vitest@2.1.8(@types/node@22.10.6)(jsdom@26.0.0)(terser@5.19.2)): + vitest-fetch-mock@0.4.3(vitest@3.0.6(@types/node@22.13.4)(jsdom@26.0.0)(terser@5.19.2)): dependencies: - vitest: 2.1.8(@types/node@22.10.6)(jsdom@26.0.0)(terser@5.19.2) + vitest: 3.0.6(@types/node@22.13.4)(jsdom@26.0.0)(terser@5.19.2) - vitest@2.1.8(@types/node@22.10.6)(jsdom@26.0.0)(terser@5.19.2): + vitest@3.0.6(@types/node@22.13.4)(jsdom@26.0.0)(terser@5.19.2): dependencies: - '@vitest/expect': 2.1.8 - '@vitest/mocker': 2.1.8(vite@5.0.12(@types/node@22.10.6)(terser@5.19.2)) - '@vitest/pretty-format': 2.1.8 - '@vitest/runner': 2.1.8 - '@vitest/snapshot': 2.1.8 - '@vitest/spy': 2.1.8 - '@vitest/utils': 2.1.8 - chai: 5.1.2 - debug: 4.3.7 + '@vitest/expect': 3.0.6 + '@vitest/mocker': 3.0.6(vite@5.0.12(@types/node@22.13.4)(terser@5.19.2)) + '@vitest/pretty-format': 3.0.6 + '@vitest/runner': 3.0.6 + '@vitest/snapshot': 3.0.6 + '@vitest/spy': 3.0.6 + '@vitest/utils': 3.0.6 + chai: 5.2.0 + debug: 4.4.0 expect-type: 1.1.0 - magic-string: 0.30.12 - pathe: 1.1.2 + magic-string: 0.30.17 + pathe: 2.0.3 std-env: 3.8.0 tinybench: 2.9.0 - tinyexec: 0.3.1 - tinypool: 1.0.1 - tinyrainbow: 1.2.0 - vite: 5.0.12(@types/node@22.10.6)(terser@5.19.2) - vite-node: 2.1.8(@types/node@22.10.6)(terser@5.19.2) + tinyexec: 0.3.2 + tinypool: 1.0.2 + tinyrainbow: 2.0.0 + vite: 5.0.12(@types/node@22.13.4)(terser@5.19.2) + vite-node: 3.0.6(@types/node@22.13.4)(terser@5.19.2) why-is-node-running: 2.3.0 optionalDependencies: - '@types/node': 22.10.6 + '@types/node': 22.13.4 jsdom: 26.0.0 transitivePeerDependencies: - less diff --git a/src/index.tsx b/src/index.tsx index 3ac03c0..e4d95d8 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -99,7 +99,7 @@ function ReactInlineSVG(props: Props) { status: STATUS.READY, }); } catch (error: any) { - handleError(new Error(error.message)); + handleError(error); } }, [content, handleError, props]); @@ -149,7 +149,7 @@ function ReactInlineSVG(props: Props) { isActive.current = true; if (!canUseDOM() || isInitialized.current) { - return () => undefined; + return undefined; } try { @@ -178,13 +178,9 @@ function ReactInlineSVG(props: Props) { [], ); - // Handle prop changes + // Handles `src` changes useEffect(() => { - if (!canUseDOM()) { - return; - } - - if (!previousProps) { + if (!canUseDOM() || !previousProps) { return; } @@ -196,27 +192,55 @@ function ReactInlineSVG(props: Props) { } load(); - } else if (previousProps.title !== title || previousProps.description !== description) { + } + }, [handleError, load, previousProps, src]); + + // Handles content loading + useEffect(() => { + if (status === STATUS.LOADED) { getElement(); } - }, [description, getElement, handleError, load, previousProps, src, title]); + }, [status, getElement]); - // handle state + // Handles `title` and `description` changes useEffect(() => { - if (!previousState) { + if (!canUseDOM() || !previousProps || previousProps.src !== src) { return; } - if (previousState.status !== STATUS.LOADING && status === STATUS.LOADING) { - getContent(); + if (previousProps.title !== title || previousProps.description !== description) { + getElement(); } + }, [description, getElement, previousProps, src, title]); - if (previousState.status !== STATUS.LOADED && status === STATUS.LOADED) { - getElement(); + // handle state + useEffect(() => { + if (!previousState) { + return; } - if (previousState.status !== STATUS.READY && status === STATUS.READY) { - onLoad?.(src, isCached); + switch (status) { + case STATUS.LOADING: { + if (previousState.status !== STATUS.LOADING) { + getContent(); + } + + break; + } + case STATUS.LOADED: { + if (previousState.status !== STATUS.LOADED) { + getElement(); + } + + break; + } + case STATUS.READY: { + if (previousState.status !== STATUS.READY) { + onLoad?.(src, isCached); + } + + break; + } } }, [getContent, getElement, isCached, onLoad, previousState, src, status]); @@ -243,7 +267,7 @@ function ReactInlineSVG(props: Props) { } if (element) { - return cloneElement(element as ReactElement, { + return cloneElement(element as ReactElement, { ref: innerRef, ...elementProps, }); @@ -262,18 +286,17 @@ export default function InlineSVG(props: Props) { } const { loader } = props; - const hasCallback = useRef(false); const [isReady, setReady] = useState(cacheStore.isReady); useEffect(() => { - if (!hasCallback.current) { - cacheStore.onReady(() => { - setReady(true); - }); - - hasCallback.current = true; + if (isReady) { + return; } - }, []); + + cacheStore.onReady(() => { + setReady(true); + }); + }, [isReady]); if (!isReady) { return loader; diff --git a/src/modules/cache.ts b/src/modules/cache.ts index 294846e..1116031 100644 --- a/src/modules/cache.ts +++ b/src/modules/cache.ts @@ -29,10 +29,24 @@ export default class CacheStore { .catch(error => { // eslint-disable-next-line no-console console.error(`Failed to open cache: ${error.message}`); + this.cacheApi = undefined; }) .finally(() => { this.isReady = true; - this.subscribers.forEach(callback => callback()); + // Copy to avoid mutation issues + const callbacks = [...this.subscribers]; + + // Clear array efficiently + this.subscribers.length = 0; + + callbacks.forEach(callback => { + try { + callback(); + } catch (error: any) { + // eslint-disable-next-line no-console + console.error(`Error in CacheStore subscriber callback: ${error.message}`); + } + }); }); } else { this.isReady = true; @@ -131,17 +145,16 @@ export default class CacheStore { } private async handleLoading(url: string, callback: () => Promise) { - let retryCount = 0; + for (let retryCount = 0; retryCount < CACHE_MAX_RETRIES; retryCount++) { + if (this.cacheStore.get(url)?.status !== STATUS.LOADING) { + return; + } - while (this.cacheStore.get(url)?.status === STATUS.LOADING && retryCount < CACHE_MAX_RETRIES) { // eslint-disable-next-line no-await-in-loop await sleep(0.1); - retryCount += 1; } - if (retryCount >= CACHE_MAX_RETRIES) { - await callback(); - } + await callback(); } public keys(): Array { @@ -164,10 +177,7 @@ export default class CacheStore { if (this.cacheApi) { const keys = await this.cacheApi.keys(); - for (const key of keys) { - // eslint-disable-next-line no-await-in-loop - await this.cacheApi.delete(key); - } + await Promise.allSettled(keys.map(key => this.cacheApi!.delete(key))); } this.cacheStore.clear(); diff --git a/test/modules/cache.spec.ts b/test/modules/cache.spec.ts index 9a3fa9b..292111c 100644 --- a/test/modules/cache.spec.ts +++ b/test/modules/cache.spec.ts @@ -140,10 +140,14 @@ describe('CacheStore (external)', () => { value: true, }); const mockReady = vi.fn(); - const cacheStore = new CacheStore(); + let cacheStore: CacheStore; - // wait for the cache to be ready - cacheStore.onReady(mockReady); + beforeAll(async () => { + // wait for the cache to be ready + cacheStore = new CacheStore(); + cacheStore.onReady(mockReady); + await waitFor(() => expect(mockReady).toHaveBeenCalledTimes(1)); + }); beforeEach(() => { fetchMock.mockResponse(() => Promise.resolve(reactContent)); @@ -198,6 +202,33 @@ describe('CacheStore (external)', () => { expect(fetchMock).toHaveBeenCalledTimes(0); }); + it('should correctly cache and return empty responses', async () => { + fetchMock.mockResponseOnce(() => Promise.resolve('')); + + // First fetch: Expect it to store the empty response + await expect(cacheStore.get(jsUrl)).resolves.toBe(''); + expect(fetchMock).toHaveBeenCalledTimes(1); + expect(cacheStore.isCached(jsUrl)).toBeTrue(); + + expect(cacheStore.data()).toEqual([{ [jsUrl]: { content: '', status: STATUS.LOADED } }]); + + // Second fetch: Should return cached empty response without calling fetch + await expect(cacheStore.get(jsUrl)).resolves.toBe(''); + expect(fetchMock).toHaveBeenCalledTimes(1); // Should still be 1 if properly cached + + // Delete and refetch: Should trigger another fetch + await cacheStore.delete(jsUrl); + + expect(cacheStore.isCached(jsUrl)).toBeFalse(); + expect(cacheStore.keys()).toHaveLength(0); + + fetchMock.mockResponseOnce(() => Promise.resolve(jsContent)); + + await expect(cacheStore.get(jsUrl)).resolves.toBe(jsContent); + + expect(fetchMock).toHaveBeenCalledTimes(2); // Fetch count should increase + }); + it('should handle delete', async () => { await cacheStore.get(reactUrl); diff --git a/test/unsupported.spec.tsx b/test/unsupported.spec.tsx index 01167c0..8bc67a4 100644 --- a/test/unsupported.spec.tsx +++ b/test/unsupported.spec.tsx @@ -53,7 +53,7 @@ describe('unsupported environments', () => { const { container } = setup(); await waitFor(() => { - expect(mockOnError).toHaveBeenCalledWith(new Error('fetch is not a function')); + expect(mockOnError).toHaveBeenCalledWith(new TypeError('fetch is not a function')); }); expect(container.firstChild).toMatchSnapshot();