Skip to content

perf(nextjs): fewer identity-server requests per server render - #562

Open
DonOmalVindula wants to merge 1 commit into
asgardeo:mainfrom
DonOmalVindula:fix/nextjs-provider-upstream-calls
Open

perf(nextjs): fewer identity-server requests per server render#562
DonOmalVindula wants to merge 1 commit into
asgardeo:mainfrom
DonOmalVindula:fix/nextjs-provider-upstream-calls

Conversation

@DonOmalVindula

Copy link
Copy Markdown
Contributor

Problem

AsgardeoServerProvider runs on every server render of the layout and, for a signed-in user, made six requests to the identity server each time: SCIM2 Me and Schemas twice (getUserAction and getUserProfileAction each fetch both), the user's organizations, and the branding preference, which was never cached and always requested for en-US. The React SDK does this work once per app load.

Fix

  • The user is derived from the profile response (generateUserProfile(profile, schemas), exactly what getUser() computes; when the profile fell back to the ID token claims, those are used directly). This removes two SCIM2 requests per render.
  • The branding preference is cached in memory (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.
  • The branding request uses the configured preferences.i18n.language (falling back to en-US), and failures go through the SDK logger instead of console.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

  • New cache unit tests (dedupe within TTL, reload after TTL, separate keys, failures not cached) and a caching test on the action; 65 tests pass.
  • pnpm lint and tsc --noEmit for @asgardeo/nextjs.

Changeset included (@asgardeo/nextjs patch).

🤖 Generated with Claude Code

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>
@coderabbitai

coderabbitai Bot commented Sep 6, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 54 minutes.

Check out review usage here.

View limit details

Limit 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.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 82459edf-2790-498f-b907-4f207f886a62

📥 Commits

Reviewing files that changed from the base of the PR and between 409ebae and 4aedc9b.

📒 Files selected for processing (6)
  • .changeset/nextjs-provider-upstream-calls.md
  • packages/nextjs/src/server/AsgardeoProvider.tsx
  • packages/nextjs/src/server/actions/__tests__/getBrandingPreference.test.ts
  • packages/nextjs/src/server/actions/getBrandingPreference.ts
  • packages/nextjs/src/utils/__tests__/brandingPreferenceCache.test.ts
  • packages/nextjs/src/utils/brandingPreferenceCache.ts

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.

❤️ Share

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

@asgardeo-github-bot

Copy link
Copy Markdown

🦋 Changeset detected

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

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.

2 participants