[CP Staging] Revert "follow up: useSearchSelector hook and remove useless code"#73877
Conversation
Codecov Report❌ Patch coverage is
... and 13 files with indirect coverage changes 🚀 New features to boost your workflow:
|
|
@rlinoz looks like this was merged without a test passing. Please add a note explaining why this was done and remove the |
|
straight revert, no emergency |
❌ PERF-6 (docs)In the large useEffect around line 109-154 in BaseOnboardingWorkspaceInvite.tsx, the dependencies include entire objects like Reasoning: Passing entire objects/arrays as dependencies causes hooks to re-execute whenever any property changes, even unrelated ones. This creates unnecessary re-computations. Suggested fix: Extract specific properties from these objects as dependencies: }, [options.personalDetails, policy?.employeeList, betas, debouncedSearchTerm, excludedUsers, areOptionsInitialized]);Remove |
❌ PERF-6 (docs)In WorkspaceInvitePage.tsx, the large useEffect around line 109-179 has the same issue - dependencies include entire objects Reasoning: Passing entire objects/arrays as dependencies causes hooks to re-execute whenever any property changes, even unrelated ones. Specifying individual properties creates more granular dependency tracking. Suggested fix: Remove redundant dependencies and use only the primitive values: }, [options.personalDetails, policy?.employeeList, betas, debouncedSearchTerm, excludedUsers, areOptionsInitialized]); |
❌ PERF-6 (docs)In BaseOnboardingWorkspaceInvite.tsx around line 156-222, the Reasoning: These array dependencies cause the entire sections array to be recalculated whenever any item in these arrays changes reference, even if the actual data hasn't changed. This is particularly problematic since these arrays are updated frequently in the useEffect above. Suggested fix: Consider either:
}, [areOptionsInitialized, selectedOptions.length, debouncedSearchTerm, personalDetails.length, translate, usersToInvite.length, countryCode]);Note: This may require additional refactoring to ensure the sections update correctly when item contents change, not just lengths. |
❌ PERF-6 (docs)In WorkspaceInvitePage.tsx around line 186-223, the Reasoning: Array dependencies cause unnecessary recalculations when array references change, even if data is identical. This creates a performance bottleneck. Suggested fix: Use more granular dependencies: }, [areOptionsInitialized, selectedOptions.length, debouncedSearchTerm, personalDetails.length, translate, usersToInvite.length, countryCode]);Note: This optimization requires ensuring sections update correctly when actual item contents change. Consider using a hash or version number if item contents need to trigger updates beyond length changes. |
❌ PERF-4 (docs)In BaseOnboardingWorkspaceInvite.tsx around line 228-232, the Reasoning: The Suggested fix: Add }, [completeOnboarding, onboardingPolicyID, policy?.employeeList, selectedOptions, welcomeNote, welcomeNoteSubject, formatPhoneNumber]); |
❌ PERF-4 (docs)In WorkspaceInvitePage.tsx around line 277, the Reasoning: The callback uses Suggested fix: Add }, [route.params.policyID, selectedOptions]); |
❌ PERF-6 (docs)In WorkspaceInvitePage.tsx around line 281-292, the Reasoning: Using entire arrays as dependencies causes the header message to recalculate whenever array references change. Since this useMemo only checks the length/existence of these arrays, using the arrays themselves as dependencies is excessive. Suggested fix: Use array lengths instead: }, [excludedUsers, translate, debouncedSearchTerm, policy?.name, usersToInvite.length, personalDetails.length, countryCode]); |
❌ PERF-6 (docs)In BaseOnboardingWorkspaceInvite.tsx around line 290-301, the Reasoning: The useMemo only checks the length of these arrays ( Suggested fix: Use array lengths as dependencies: }, [excludedUsers, translate, debouncedSearchTerm, policy?.name, usersToInvite.length, personalDetails.length, countryCode]); |
|
❌ PERF-6 (docs)In both files, the Reasoning: Suggested fix: Check what properties Example if it only uses }, [debouncedSearchTerm, defaultOptions.personalDetails, excludedUsers, countryCode]); |
❌ PERF-6 (docs)In BaseOnboardingWorkspaceInvite.tsx around line 306-334, the Reasoning: While depending on individual style properties is correct, ensure all used styles are in the dependency array. However, typically Suggested fix: Remove style dependencies if }, [completeOnboarding, inviteUser, onboardingIsMediumOrLargerScreenWidth, selectedOptions.length, translate]);Or if styles must be included, use the entire }, [completeOnboarding, inviteUser, onboardingIsMediumOrLargerScreenWidth, selectedOptions.length, styles, translate]); |
❌ PERF-6 (docs)In WorkspaceInvitePage.tsx around line 294-306, the Reasoning: Depending on individual style properties is unnecessarily granular. The Suggested fix: Either depend on the entire }, [inviteUser, policy?.alertMessage, selectedOptions.length, shouldShowAlertPrompt, translate]); |
|
Revert "follow up: useSearchSelector hook and remove useless code" (cherry picked from commit 87661b8) (cherry-picked to staging by puneetlath)
|
|
❌ PERF-2 (docs)In BaseOnboardingWorkspaceInvite.tsx (~line 160-169) and WorkspaceInvitePage.tsx (~line 194-203), the filterSelectedOptions = selectedOptions.filter((option) => {
const accountID = option.accountID;
const isOptionInPersonalDetails = Object.values(personalDetails).some(...);
const searchValue = getSearchValueForPhoneOrEmail(debouncedSearchTerm, countryCode);
const isPartOfSearchTerm = !!option.text?.toLowerCase().includes(searchValue) || !!option.login?.toLowerCase().includes(searchValue);
return isPartOfSearchTerm || isOptionInPersonalDetails;
});Reasoning:
Suggested fix: const searchValue = getSearchValueForPhoneOrEmail(debouncedSearchTerm, countryCode);
filterSelectedOptions = selectedOptions.filter((option) => {
// Early return for simple text match check
const isPartOfSearchTerm = !!option.text?.toLowerCase().includes(searchValue) || !!option.login?.toLowerCase().includes(searchValue);
if (isPartOfSearchTerm) {
return true;
}
// Only perform expensive operation if needed
const accountID = option.accountID;
return Object.values(personalDetails).some((personalDetail) => personalDetail.accountID === accountID);
}); |
Performance Review SummaryI've reviewed PR #73877 which reverts the useSearchSelector hook implementation. I found multiple performance issues in the reverted code: Critical Issues Found:
Code Quality Concerns:
Recommendation:Consider whether this revert is necessary. The original Total inline comments created: 16 |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Cherry-picked to staging by https://github.com/puneetlath in version: 9.2.41-4 🚀
|
|
🚀 Deployed to production by https://github.com/puneetlath in version: 9.2.41-6 🚀
|
|
🚀 Cherry-picked to staging by https://github.com/puneetlath in version: 9.2.42-0 🚀
|
|
🚀 Deployed to production by https://github.com/luacmartins in version: 9.2.42-11 🚀
|
Reverts #72677
$ #73874
$ #73875