Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix useFeaturesList changing object pointers every rerender #3141

Merged
merged 1 commit into from
Oct 18, 2024

Conversation

Kevin-Chant
Copy link
Contributor

Features and Changes

On Firefox there's been a general error "the operation is insecure" on the main /features page for a few weeks now.
The reason for this is we have a useMemo in services/search.tsx which does a shallow replace on the router's query params whenever an object changes. That object in turn is a useMemo based on the items being searched over, and those items (in the case of /features) are the FeatureInterface[] returned by useFeaturesList.

The problem is that each time the hook is called (due to re-rendering for other reasons) the default empty array that's returned is a new object, so this was causing us to change the query params hundreds of times, which Firefox blocked as a security issue.

Testing

Using Firefox, load http://localhost:3000/features on main and on this branch and observe the difference.
Optionally, add a console log to the if (updateSearchQueryOnChange) clause in services/search.tsx to see the frequency at which we call router.replace

Screenshots

Before

image

After

image

Comment on lines +213 to +218
if (data) {
setFeatures(data.features);
setExperiments(data.linkedExperiments);
setHasArchived(data.hasArchived);
}
}, [data]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think I need to have an else to reset the fields back to [] if the data changes back to empty, but could be wrong

Copy link

Your preview environment pr-3141-bttf has been deployed.

Preview environment endpoints are available at:

@Kevin-Chant Kevin-Chant merged commit 0476f44 into main Oct 18, 2024
3 checks passed
@Kevin-Chant Kevin-Chant deleted the kc/fix-usefeatureslist-rerendering branch October 18, 2024 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants