perf(nextjs): fewer identity-server requests per server render - #562
Open
DonOmalVindula wants to merge 1 commit into
Open
perf(nextjs): fewer identity-server requests per server render#562DonOmalVindula wants to merge 1 commit into
DonOmalVindula wants to merge 1 commit into
Conversation
AsgardeoProvider requested the SCIM2 Me and Schemas resources twice per render (getUser and getUserProfile each fetch both) and fetched the branding preference on every request. - Derive the user from the profile response instead of calling getUser. - Cache the branding preference in memory for a few minutes per base URL, type, name and locale; concurrent callers share the in-flight request and a failed fetch is not cached. - Request the branding for the configured preferences.i18n.language instead of a hard-coded en-US, and log branding failures through the SDK logger. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Warning Review limit reachedNext included review available in 54 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (6)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🦋 Changeset detectedThe changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
AsgardeoServerProviderruns on every server render of the layout and, for a signed-in user, made six requests to the identity server each time: SCIM2MeandSchemastwice (getUserActionandgetUserProfileActioneach fetch both), the user's organizations, and the branding preference, which was never cached and always requested foren-US. The React SDK does this work once per app load.Fix
generateUserProfile(profile, schemas), exactly whatgetUser()computes; when the profile fell back to the ID token claims, those are used directly). This removes two SCIM2 requests per render.withBrandingPreferenceCache) for five minutes per base URL, type, name and locale. Concurrent renders share the in-flight request and a failed fetch is not cached, so the next render retries.preferences.i18n.language(falling back toen-US), and failures go through the SDK logger instead ofconsole.warn.Not changed here: the default of fetching the branding (
inheritFromBranding !== false) differs from the React SDK (=== true), but flipping it would silently remove branding from existing Next.js apps, so it is left as is.Testing
pnpm lintandtsc --noEmitfor@asgardeo/nextjs.Changeset included (
@asgardeo/nextjspatch).🤖 Generated with Claude Code