From ac33b5c8b681c27ac520fbadd5855d5747a416db Mon Sep 17 00:00:00 2001 From: nemanjam Date: Sat, 17 Aug 2024 17:25:43 +0200 Subject: [PATCH] remove debounce from ScrollToTop --- package.json | 4 ---- src/components/react/ScrollToTop.tsx | 7 +------ yarn.lock | 27 --------------------------- 3 files changed, 1 insertion(+), 37 deletions(-) diff --git a/package.json b/package.json index 25c281f..da2ad40 100644 --- a/package.json +++ b/package.json @@ -38,11 +38,9 @@ "class-variance-authority": "^0.7.0", "clsx": "^2.1.1", "date-fns": "^3.6.0", - "debounce": "^2.1.0", "dotenv": "^16.4.5", "feed": "^4.2.2", "giscus": "^1.5.0", - "lodash.debounce": "^4.0.8", "mdast-util-to-string": "^4.0.0", "nanostores": "^0.10.3", "object-treeify": "^4.0.1", @@ -62,8 +60,6 @@ "@ianvs/prettier-plugin-sort-imports": "^4.3.1", "@iconify-json/mdi": "^1.1.66", "@tailwindcss/typography": "^0.5.13", - "@types/debounce": "^1.2.4", - "@types/lodash.debounce": "^4.0.9", "@types/mdast": "^4.0.3", "@types/react": "^18.3.3", "@types/react-dom": "^18.3.0", diff --git a/src/components/react/ScrollToTop.tsx b/src/components/react/ScrollToTop.tsx index 249e1cd..e4d150f 100644 --- a/src/components/react/ScrollToTop.tsx +++ b/src/components/react/ScrollToTop.tsx @@ -1,7 +1,5 @@ import React, { useEffect, useRef, useState } from 'react'; -import debounce from 'lodash.debounce'; - import { cn } from '@/utils/styles'; import type { ReactNode } from 'react'; @@ -56,10 +54,7 @@ const ScrollToTop: React.FC = ({ children }) => { } }; - // bellow 100 or it will break again on fast scroll - // todo: set threshold and remove debounce - const debouncedCallback = debounce(callback, 20); - const intersect = new IntersectionObserver(debouncedCallback); + const intersect = new IntersectionObserver(callback, { threshold: 0 }); if (topRef.current) intersect.observe(topRef.current); if (bottomRef.current) intersect.observe(bottomRef.current); diff --git a/yarn.lock b/yarn.lock index 5f48244..eccca82 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1214,11 +1214,6 @@ resolved "https://registry.yarnpkg.com/@types/cookie/-/cookie-0.6.0.tgz#eac397f28bf1d6ae0ae081363eca2f425bedf0d5" integrity sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA== -"@types/debounce@^1.2.4": - version "1.2.4" - resolved "https://registry.yarnpkg.com/@types/debounce/-/debounce-1.2.4.tgz#cb7e85d9ad5ababfac2f27183e8ac8b576b2abb3" - integrity sha512-jBqiORIzKDOToaF63Fm//haOCHuwQuLa2202RK4MozpA6lh93eCBc+/8+wZn5OzjJt3ySdc+74SXWXB55Ewtyw== - "@types/debug@^4.0.0": version "4.1.12" resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.12.tgz#a155f21690871953410df4b6b6f53187f0500917" @@ -1250,18 +1245,6 @@ resolved "https://registry.yarnpkg.com/@types/is-empty/-/is-empty-1.2.3.tgz#a2d55ea8a5ec57bf61e411ba2a9e5132fe4f0899" integrity sha512-4J1l5d79hoIvsrKh5VUKVRA1aIdsOb10Hu5j3J2VfP/msDnfTdGPmNp2E1Wg+vs97Bktzo+MZePFFXSGoykYJw== -"@types/lodash.debounce@^4.0.9": - version "4.0.9" - resolved "https://registry.yarnpkg.com/@types/lodash.debounce/-/lodash.debounce-4.0.9.tgz#0f5f21c507bce7521b5e30e7a24440975ac860a5" - integrity sha512-Ma5JcgTREwpLRwMM+XwBR7DaWe96nC38uCBDFKZWbNKD+osjVzdpnUSwBcqCptrp16sSOLBAUb50Car5I0TCsQ== - dependencies: - "@types/lodash" "*" - -"@types/lodash@*": - version "4.17.7" - resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.17.7.tgz#2f776bcb53adc9e13b2c0dfd493dfcbd7de43612" - integrity sha512-8wTvZawATi/lsmNu10/j2hk1KEP0IvjubqPE3cu1Xz7xfXXt5oCq3SNUz4fMIP4XGF9Ky+Ue2tBA3hcS7LSBlA== - "@types/mdast@^3.0.0": version "3.0.15" resolved "https://registry.yarnpkg.com/@types/mdast/-/mdast-3.0.15.tgz#49c524a263f30ffa28b71ae282f813ed000ab9f5" @@ -2499,11 +2482,6 @@ date-fns@^3.6.0: resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-3.6.0.tgz#f20ca4fe94f8b754951b24240676e8618c0206bf" integrity sha512-fRHTG8g/Gif+kSh50gaGEdToemgfj74aRX3swtiouboip5JDLAyDE9F11nHMIcvOaXeOC6D7SpNhi7uFyB7Uww== -debounce@^2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/debounce/-/debounce-2.1.0.tgz#eab25eaf254b848fcfccffbde75bdaa44842caa3" - integrity sha512-OkL3+0pPWCqoBc/nhO9u6TIQNTK44fnBnzuVtJAbp13Naxw9R6u21x+8tVTka87AhDZ3htqZ2pSSsZl9fqL2Wg== - debug@2.6.9: version "2.6.9" resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" @@ -4125,11 +4103,6 @@ lodash.castarray@^4.4.0: resolved "https://registry.yarnpkg.com/lodash.castarray/-/lodash.castarray-4.4.0.tgz#c02513515e309daddd4c24c60cfddcf5976d9115" integrity sha512-aVx8ztPv7/2ULbArGJ2Y42bG1mEQ5mGjpdvrbJcJFU3TbYybe+QlLS4pst9zV52ymy2in1KpFPiZnAOATxD4+Q== -lodash.debounce@^4.0.8: - version "4.0.8" - resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af" - integrity sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow== - lodash.isplainobject@^4.0.6: version "4.0.6" resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb"