From 2a4378c40b48ebf35e97b37758eca8990f2f84b8 Mon Sep 17 00:00:00 2001 From: Tomasz Zawadzki Date: Tue, 11 Aug 2026 15:26:52 +0200 Subject: [PATCH] perf: skip minute-tick subscription for actors without a live status (#11441) Co-authored-by: Claude Fable 5 --- src/features/liveNow/index.tsx | 8 +++++++- src/state/shell/tick-every-minute.tsx | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/features/liveNow/index.tsx b/src/features/liveNow/index.tsx index fb1f04b728..23f33a5ffc 100644 --- a/src/features/liveNow/index.tsx +++ b/src/features/liveNow/index.tsx @@ -97,7 +97,13 @@ export function useLiveNowConfig(): LiveNowConfig { export function useActorStatus(actor?: bsky.profile.AnyProfileView) { const shadowed = useMaybeProfileShadow(actor) - const tick = useTickEveryMinute() + /* + * The minute tick only exists to re-validate an existing status's expiry, + * so actors without a status record skip the subscription entirely. This + * keeps the every-minute tick from re-rendering every post in a feed. + */ + const hasStatus = !!(shadowed && 'status' in shadowed && shadowed.status) + const tick = useTickEveryMinute(hasStatus) const config = useLiveNowConfig() const moderationOpts = useModerationOpts() diff --git a/src/state/shell/tick-every-minute.tsx b/src/state/shell/tick-every-minute.tsx index 7c4a3512db..a24e114fdc 100644 --- a/src/state/shell/tick-every-minute.tsx +++ b/src/state/shell/tick-every-minute.tsx @@ -1,4 +1,4 @@ -import {createContext, useContext, useEffect, useState} from 'react' +import {createContext, use, useEffect, useState} from 'react' type StateContext = number @@ -16,6 +16,15 @@ export function Provider({children}: React.PropsWithChildren<{}>) { return {children} } -export function useTickEveryMinute() { - return useContext(stateContext) +/** + * Returns a timestamp that updates once per minute, re-rendering the caller + * on every tick. Pass `enabled: false` to skip subscribing entirely - the + * caller then never re-renders on tick and receives a stable `0`. Relies on + * React 19 `use()`, which may be called conditionally. + */ +export function useTickEveryMinute(enabled: boolean = true) { + if (enabled) { + return use(stateContext) + } + return 0 }