Skip to content

fix: memoize useEnterpriseConnect result - #1275

Closed
fallintoplace wants to merge 2 commits into
auth0:mainfrom
fallintoplace:fix/memoize-enterprise-connect
Closed

fallintoplace wants to merge 2 commits into
auth0:mainfrom
fallintoplace:fix/memoize-enterprise-connect

Conversation

@fallintoplace

@fallintoplace fallintoplace commented Oct 4, 2026 •

Copy link
Copy Markdown
  • What: Keep the useEnterpriseConnect result stable between renders.
  • Why: Effects using this result rerun even when both callbacks are unchanged.
  • Implementation: Memoize the object with both callbacks as dependencies.

Summary by CodeRabbit

  • Bug Fixes
    • Enterprise sign-in now reflects updated configuration and redirect behavior when its context changes, while keeping callbacks current across rerenders.
    • The hook’s returned result remains stable when its underlying sign-in behavior has not changed, improving consistency for integrations and avoiding unnecessary updates during routine rerenders.

@fallintoplace
fallintoplace requested a review from a team as a code owner October 4, 2026 07:47
@coderabbitai

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: auth0/auth0-react/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d7b6bdbb-fa1c-41bb-939c-0df8d5c7944f
📥 Commits

Reviewing files that changed from the base of the PR and between 4a928af and 0dc0e23.

📒 Files selected for processing: 1
  • src/use-enterprise-connect.tsx

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

📝 Walkthrough

useEnterpriseConnect now memoizes its returned object. Tests verify stable references across rerenders and updated callback behavior when context callbacks change.

Changes: Enterprise connect hook

Layer / File(s) Summary
Memoize the hook result and verify callback updates
src/use-enterprise-connect.tsx, __tests__/use-enterprise-connect.test.tsx
The hook reuses its returned object while its callbacks remain unchanged. Tests verify stable references across rerenders, callback-specific updates, current context values, and subsequent stability.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: gyaneshgouraw

Merge Risk: ⚪ Minimal · up to 0dc0e

The change is mergeable with no identified correctness, availability, security, or data-integrity risk.

Architecture risk: 🔵 Low · up to 0dc0e

The change affects 2 systems.

Changed systems: src, __tests__

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (service) was modified; 1 changed file maps to changed impact.
  • observed — tests (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in tests/use-enterprise-connect.test.tsx: The test file now imports React’s useEffect and the auth context interface and initial context to support hook-stability and custom-context tests.
  • observed — Modified behavior in tests/use-enterprise-connect.test.tsx: Adds a test that records an effect dependent on the hook result, waits for client user loading, and rerenders three times; it expects the effect to run once and the result reference to remain unchanged.
  • observed — Modified behavior in tests/use-enterprise-connect.test.tsx: Adds parameterized tests that replace either getConfiguration or loginWithRedirect in a custom context. Each replacement must produce a new result, update only the corresponding callback, invoke the updated callback with current context values, and leave the result stable on a further rerender.
  • observed — Modified behavior in tests/use-enterprise-connect.test.tsx: The redirect-readiness waitFor assertion is reformatted onto one line; its condition is unchanged.
Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: memoizing the useEnterpriseConnect result.
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files.

✨ Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@yogeshchoudhary147

Copy link
Copy Markdown
Contributor

could you gpg-sign the commit before we merge?

@fallintoplace

Copy link
Copy Markdown
Author

Give me a second to sign this...

@yogeshchoudhary147

Copy link
Copy Markdown
Contributor

Thanks for the fix, @fallintoplace! We can't merge unsigned commits, and since we haven't heard back, I'm closing this for now. If you'd still like to get it in, feel free to open a new PR with a signed commit and we'll get it merged.

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.

3 participants