Skip to content

[Due for payment 2026-02-18] [$250] Nix the useDeepCompareRef hook #79510

@roryabraham

Description

@roryabraham

Proposal: Standardize Object Stability to Enable Modern Rendering

Background

In our current architecture, we utilize the useDeepCompareRef hook across 6 distinct locations to stabilize object references between renders using the fast-equals library. This hook is designed to perform deep equality comparisons and update a stored ref value synchronously during the render phase to prevent downstream useMemo or useEffect recomputations. With the introduction of React 18 and the React Compiler, the build pipeline now audits components for “render purity” and idempotency. The compiler’s static analysis identifies hooks that perform side effects—such as mutating a ref during render—and automatically opts those components out of memoization-based optimizations to prevent potential runtime instability.

Problem

When components rely on useDeepCompareRef to stabilize references, if the hook performs synchronous mutations during the render phase, then the UI encounters inconsistent state updates that violate React’s idempotency requirements.

Solution

Replace all instances of useDeepCompareRef with React-compliant useMemo patterns as detailed in this Pull Request and remove the src/hooks/useDeepCompareRef.ts hook entirely. This restores render purity across the identified components, enabling the React Compiler to perform automatic optimizations and ensuring long-term UI stability.

Validation and Performance:

Performance testing confirms that replacing useDeepCompareRef with useMemo shows no regression in testable cases, with a 5-10% improvement in rendering efficiency in 3 cases (ReportScreen, useArchivedReportsIdSet, useSidebarOrderedReports). While WorkspaceWorkflowsApprovalsExpensesFromPage could not be verified due to lack of admin access, the standardized approach ensures the component is no longer bypassed by the React Compiler, allowing for future automated optimizations.

Issue OwnerCurrent Issue Owner: @dylanexpensify

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type
No fields configured for issues without a type.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions