Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {LOCALES} from './LOCALES';
// Freezing the array ensures that it cannot be unintentionally modified.
const EMPTY_ARRAY = Object.freeze([]);
const EMPTY_OBJECT = Object.freeze({});
const EMPTY_SET = new Set<string>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ CONSISTENCY-2 (docs)

The EMPTY_SET constant should be frozen like EMPTY_ARRAY and EMPTY_OBJECT to prevent unintentional modification. The comment on lines 19-20 states: "Freezing the array ensures that it cannot be unintentionally modified."

Suggested fix:

const EMPTY_SET = Object.freeze(new Set<string>());

This ensures consistency with the existing EMPTY_ARRAY and EMPTY_OBJECT constants and prevents accidental mutation.


Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object.freeze does not prevent mutations on Set

@kacper-mikolajczak kacper-mikolajczak Jan 29, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dang, the power of true Senior Engineer!

Although +1 in general for the AI about pin-pointing EMPTY_SET should truly stay immutable.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider overriding add, clear and delete ? To throw, so that any changes to the EMPTY_SET can be prevented.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that can be a follow up


// Using 28 days to align with OldDot and because all months are guaranteed to be at least 28 days.
const MONTH_DAYS = Object.freeze([...Array(28).keys()].map((i) => i + 1));
Expand Down Expand Up @@ -979,6 +980,7 @@ const CONST = {
connectionsVideoPaths,
EMPTY_ARRAY,
EMPTY_OBJECT,
EMPTY_SET,
DEFAULT_NUMBER_ID,
DEFAULT_MISSING_ID,
DEFAULT_COUNTRY_CODE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function MoneyRequestReportNavigation({reportID, shouldDisplayNarrowVersion}: Mo
const [currentSearchResults] = useOnyx(`${ONYXKEYS.COLLECTION.SNAPSHOT}${lastSearchQuery?.queryJSON?.hash}`, {canBeMissing: true});
const currentUserDetails = useCurrentUserPersonalDetails();
const {localeCompare, formatPhoneNumber, translate} = useLocalize();
const [isActionLoadingSet = new Set<string>()] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}`, {canBeMissing: true, selector: isActionLoadingSetSelector});
const [isActionLoadingSet = CONST.EMPTY_SET] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}`, {canBeMissing: true, selector: isActionLoadingSetSelector});

const [exportReportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, {
canEvict: false,
Expand Down
2 changes: 1 addition & 1 deletion src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ function Search({
const [violations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true});
const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: true});
const {accountID, email, login} = useCurrentUserPersonalDetails();
const [isActionLoadingSet = new Set<string>()] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}`, {canBeMissing: true, selector: isActionLoadingSetSelector});
const [isActionLoadingSet = CONST.EMPTY_SET] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}`, {canBeMissing: true, selector: isActionLoadingSetSelector});
const [allReportMetadata] = useOnyx(ONYXKEYS.COLLECTION.REPORT_METADATA, {canBeMissing: true});
const [visibleColumns] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM, {canBeMissing: true, selector: columnsSelector});
const [customCardNames] = useOnyx(ONYXKEYS.NVP_EXPENSIFY_COMPANY_CARDS_CUSTOM_NAMES, {canBeMissing: true});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function TransactionGroupListItem<TItem extends ListItem>({
const isExpenseReportType = searchType === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT;
const [transactionsVisibleLimit, setTransactionsVisibleLimit] = useState(CONST.TRANSACTION.RESULTS_PAGE_SIZE as number);
const [isExpanded, setIsExpanded] = useState(false);
const [isActionLoadingSet = new Set<string>()] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}`, {canBeMissing: true, selector: isActionLoadingSetSelector});
const [isActionLoadingSet = CONST.EMPTY_SET] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}`, {canBeMissing: true, selector: isActionLoadingSetSelector});
const [allReportMetadata] = useOnyx(ONYXKEYS.COLLECTION.REPORT_METADATA, {canBeMissing: true});
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true});

Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useArchivedReportsIdSet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {archivedReportsIdSetSelector} from '@selectors/ReportNameValuePairs';
import type {ArchivedReportsIDSet} from '@libs/SearchUIUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import useDeepCompareRef from './useDeepCompareRef';
import useOnyx from './useOnyx';
Expand All @@ -8,7 +9,7 @@ import useOnyx from './useOnyx';
* Hook that returns a Set of archived report IDs
*/
function useArchivedReportsIdSet(): ArchivedReportsIDSet {
const [archivedReportsIdSet = new Set<string>()] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, {
const [archivedReportsIdSet = CONST.EMPTY_SET] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, {
canBeMissing: true,
selector: archivedReportsIdSetSelector,
});
Expand Down
Loading