Skip to content

fix: Prevents useEffect double render in React18 StrictMode#266

Merged
eng-services-aperture-github-bot-okta merged 8 commits into
masterfrom
ti-OKTA-635977
Sep 5, 2023
Merged

fix: Prevents useEffect double render in React18 StrictMode#266
eng-services-aperture-github-bot-okta merged 8 commits into
masterfrom
ti-OKTA-635977

Conversation

@trevoring-okta
Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown

@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