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: infinite api requests when the verification token is invalid #2736

Merged
merged 7 commits into from
Jan 6, 2024

Conversation

aryanas159
Copy link
Contributor

Fixes #2652

Changes:
Because of the continuous prop changes the useEffect was executing infinitely, I have added a state that allows only one API call to check where the token in invalid or not.
I have verified that this pull request:

  • has no linting errors (npm run lint)
  • has no test errors (npm run test)
  • is from a uniquely-named feature branch and is up to date with the develop branch.
  • is descriptively named and links to an issue number, i.e. Fixes #123
Untitled.video.-.Made.with.Clipchamp.6.mp4

@lindapaiste
Copy link
Collaborator

Changes: Because of the continuous prop changes the useEffect was executing infinitely

Yikes!

I have added a state that allows only one API call to check where the token in invalid or not.

This is definitely an improvement and should solve the problem. It feels like a bit of a band-aid solution though. You've identified that the core problem is having props in the useEffect dependencies, which causes the effect to run on every re-render. We can change the dependencies to [location, props.verifyEmailConfirmation] so that it depends only on the one function and not on the props object. I'm not sure if that works though because I'm not sure if props.verifyEmailConfirmation is a stable reference, especially since we're using bindActionCreators (which is completely unnecessary). Maybe it's time to clean up this component and bring it into the modern age. See the checklist in #2405 (comment). The following code will definitely only re-execute the effect if the token changes.

const { t } = useTranslation();

const location = useLocation();

const browserHistory = useHistory();

const dispatch = useDispatch();

const emailVerificationTokenState = useSelector(
  (state) => state.user.emailVerificationTokenState
);

const verificationToken = useMemo(() => {
  const searchParams = new URLSearchParams(location.search);
  return searchParams.get('t');
}, [location.search]);

useEffect(() => {
  if (verificationToken) {
    dispatch(verifyEmailConfirmation(verificationToken));
  }
}, [dispatch, verificationToken]);

@aryanas159
Copy link
Contributor Author

@lindapaiste Great suggestion, I have made the following changes you listed in #2405 (comment). It works well since the dependency array contains the verification token which is memoized there are no infinite loops.
Let me know if these kinds of changes are required for other components as well.

@aryanas159
Copy link
Contributor Author

@lindapaiste, could you please review the changes?

Copy link
Collaborator

@lindapaiste lindapaiste left a comment

Choose a reason for hiding this comment

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

Looking good. Just one minor change.

@lindapaiste
Copy link
Collaborator

I went ahead and committed my suggestion because I want to get this bug fixed.

As a side note, it's weird that the message that we show when the token is invalid is "Something went wrong." and not the "Token is invalid or has expired." message that we get back from the API. But that's something to address in a separate issue.

Copy link
Collaborator

@lindapaiste lindapaiste left a comment

Choose a reason for hiding this comment

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

It's so much cleaner now, thank you!

@lindapaiste lindapaiste merged commit 72f3afc into processing:develop Jan 6, 2024
@raclim raclim added this to the MINOR Release for 2.11.0 milestone Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants