You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add a new ESLint rule that disallows returning Set or ReadonlySet from
useOnyx selectors. The deepEqual comparison used internally by useOnyx is
extremely slow for Set objects, causing unnecessary performance degradation.
The rule suggests returning an array instead and converting to a Set outside
the selector if needed.
Extract shared AST utilities (findProperty, resolveVariable, getVariableInit,
getVariableAsObject) into utils/astUtil.js, deduplicating identical helper
functions that were previously inlined in no-inline-useOnyx-selector and
provide-canBeMissing-in-useOnyx.
Detection coverage
The rule catches Set returns in the following patterns:
Inline arrow/function selectors (selector: (d) => new Set(d))
Ternary with Set in implicit arrow return — currently NOT caught by the rule:
selector: (d)=>d ? newSet(d) : newSet()
bodyReturnsNewSet does not recurse into ConditionalExpression consequent/alternate, so this pattern is silently missed. Either the rule should be updated to handle this, or a valid test should document it as a known limitation.
Return statement with ternary containing Set — also NOT caught:
selector: (d)=>{returnd ? newSet(d) : [];}
Same root cause — isNewSetExpression is checked against ReturnStatement.argument directly, which is a ConditionalExpression, not a NewExpression.
Bonus considerations
Map/ReadonlyMap — fast-equalsdeepEqual has the same O(n²) comparison behavior for Map as for Set. Worth considering whether the rule should also cover Map returns, or at least documenting the decision not to.
useMemo wrapped selectors — resolveSelectorFunction handles useCallback but not useMemo. While less common, const sel = useMemo(() => (d) => new Set(d), []) would not be caught.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
$ Expensify/App#82251
Summary
useOnyx selectors. The deepEqual comparison used internally by useOnyx is
extremely slow for Set objects, causing unnecessary performance degradation.
The rule suggests returning an array instead and converting to a Set outside
the selector if needed.
getVariableAsObject) into utils/astUtil.js, deduplicating identical helper
functions that were previously inlined in no-inline-useOnyx-selector and
provide-canBeMissing-in-useOnyx.
Detection coverage
The rule catches Set returns in the following patterns:
fn})
return s)