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: Prevents useEffect double render in React18 StrictMode #266

Merged
merged 8 commits into from
Sep 5, 2023

Conversation

trevoring-okta
Copy link
Contributor

@trevoring-okta trevoring-okta commented Sep 5, 2023

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Adding Tests
  • Build related changes
  • CI related changes
  • Documentation changes
  • Other... Please describe:

What is the current behavior?

In React18 StrictMode, useEffects run twice on component mount. This causes handleLoginRedirect() to run twice in the LoginCallback component, triggering an AuthSdkError from auth-js.

Issue Number: #263

Internal Ref: OKTA-635977

What is the new behavior?

Adds a top-level variable in LoginCallback that prevents handleLoginRedirect() from running twice. Solution follows React18 guidance

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

  • Unit testing required bumping jest to 29.x to have access to jest.isolateModulesAsync()
  • e2e testing required bumping the test-harness-app to React18 and adding a new start:dev script (as well as a .env.development file) to enable testing on a development build since this bug only exists in React18 dev mode. The v6-app was also bumped to maintain parity

@stormsilver
Copy link

The pipeline for publishing this appears to have failed: https://github.com/okta/okta-react/actions/runs/6088093926/job/16518033829

The currently available version on NPM is still 6.7.0.

@eddiemonge
Copy link

@trevoring-okta Dispatch Downstream Update Samples Event

@jaredperreault-okta jaredperreault-okta mentioned this pull request Feb 26, 2024
14 tasks
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.

5 participants