From c9a0c17d53c5c1cb3c9d797551d630104aacbb60 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 20 Mar 2026 09:38:21 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Optimize=20BackToTop=20?= =?UTF-8?q?scroll=20event=20listener?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Throttled the scroll event listener in `BackToTop` using `requestAnimationFrame` to prevent main-thread blocking and excessive React re-renders. Also added `{ passive: true }` to the event listener to allow the browser to scroll smoothly. Expected impact: Significant reduction in CPU usage and jank during fast scrolling. Co-authored-by: anyulled <100741+anyulled@users.noreply.github.com> --- components/elements/BackToTop.tsx | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/components/elements/BackToTop.tsx b/components/elements/BackToTop.tsx index 3fdb6396..e2ef4b5e 100644 --- a/components/elements/BackToTop.tsx +++ b/components/elements/BackToTop.tsx @@ -5,12 +5,29 @@ export default function BackToTop({ target }: Readonly<{ target: string }>) { const [hasScrolled, setHasScrolled] = useState(false); useEffect(() => { + /* + * ⚡ Bolt Optimization: + * - Throttles scroll events using requestAnimationFrame to prevent main-thread blocking and excessive re-renders. + * - Uses passive event listener to allow the browser to perform smooth scrolling without waiting for JS execution. + * Expected impact: Significant reduction in CPU usage and jank during fast scrolling. + */ + const state = { isTicking: false, tickingId: 0 }; + const onScroll = () => { - setHasScrolled(window.scrollY > 100); + if (!state.isTicking) { + state.tickingId = window.requestAnimationFrame(() => { + setHasScrolled(window.scrollY > 100); + state.isTicking = false; + }); + state.isTicking = true; + } }; - window.addEventListener("scroll", onScroll); - return () => window.removeEventListener("scroll", onScroll); + window.addEventListener("scroll", onScroll, { passive: true }); + return () => { + window.removeEventListener("scroll", onScroll); + window.cancelAnimationFrame(state.tickingId); + }; }, []); const handleClick = () => { From f142adbdedf52c7cce53bf74ec0cdb857e7cf5ce Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 20 Mar 2026 09:43:28 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Fix=20formatting=20issu?= =?UTF-8?q?es=20in=20BackToTop=20and=20.commitlintrc.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ran `npm run format` to automatically apply prettier formatting across the codebase to fix CI format check failures. Co-authored-by: anyulled <100741+anyulled@users.noreply.github.com> --- .commitlintrc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.commitlintrc.yml b/.commitlintrc.yml index e1fe5765..5455a457 100644 --- a/.commitlintrc.yml +++ b/.commitlintrc.yml @@ -1,5 +1,5 @@ extends: - - '@commitlint/config-conventional' + - "@commitlint/config-conventional" rules: type-enum: - 2