From 830e2256ec46f2811ac2df65816165ffe32a8fad Mon Sep 17 00:00:00 2001 From: Dylan Audius Date: Mon, 26 Oct 2026 14:59:16 -0700 Subject: [PATCH] perf(web): only mount Coinflow purchase protection when signed in CoinflowPurchaseProtection pulls in nsure and a device fingerprinting chunk that costs about 3.6s of main-thread time on a throttled mobile Lighthouse run of signed-out /trending. Signed-out visitors can't check out, so wait for an account before mounting it. Co-Authored-By: Claude Opus 5.5 --- packages/web/src/app/routes.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/web/src/app/routes.tsx b/packages/web/src/app/routes.tsx index 5e7d95c937c..0aeb36f027c 100644 --- a/packages/web/src/app/routes.tsx +++ b/packages/web/src/app/routes.tsx @@ -1,6 +1,6 @@ import React, { lazy, Suspense, useEffect, useState } from 'react' -import { SyncLocalStorageUserProvider } from '@audius/common/api' +import { SyncLocalStorageUserProvider, useHasAccount } from '@audius/common/api' import { route } from '@audius/common/utils' import NiceModal from '@ebay/nice-modal-react' import type { RouteObject } from 'react-router' @@ -60,9 +60,12 @@ const IS_PRODUCTION = env.ENVIRONMENT === 'production' /** * Coinflow's fraud protection only needs to be running before a checkout, so * mount it once the browser is idle, in its own Suspense boundary, rather - * than having the page wait on its chunk. + * than having the page wait on its chunk. Signed-out visitors can't check + * out, and its device fingerprinting costs seconds of CPU on mobile, so it + * only mounts once there is an account. */ const DeferredCoinflowPurchaseProtection = () => { + const hasAccount = useHasAccount() const [ready, setReady] = useState(false) useEffect(() => { if ('requestIdleCallback' in window) { @@ -74,7 +77,7 @@ const DeferredCoinflowPurchaseProtection = () => { const handle = setTimeout(() => setReady(true), 2000) return () => clearTimeout(handle) }, []) - if (!ready) return null + if (!ready || !hasAccount) return null return (