Skip to content

Fix/rerender lazy state init#10475

Open
siddhartha928 wants to merge 3 commits into
wso2:masterfrom
siddhartha928:fix/rerender-lazy-state-init
Open

Fix/rerender lazy state init#10475
siddhartha928 wants to merge 3 commits into
wso2:masterfrom
siddhartha928:fix/rerender-lazy-state-init

Conversation

@siddhartha928

@siddhartha928 siddhartha928 commented Jun 28, 2026

Copy link
Copy Markdown

Purpose

Fix performance issue where useState initial values were being re-evaluated on every render instead of only once on mount. closes wso2/product-is#27955 (comment)

React evaluates a plain expression passed to useState(expr) on every render (the result is discarded after the first render, but the computation still runs). Wrapping it as useState(() => expr) changes to a lazy initializer pattern ensuring the function is called only once during component mount.

Fixed in 6 files:

admin.claims.v1 — getExcludedStoresFromClaim(claim) (array computation from claim data)
admin.console-settings.v1 — getActiveTabFromUrl() (URL parsing)
admin.login-flow-builder.v1 — cloneDeep(application?.authenticationSequence) (deep object clone)
admin.logs.v1 — getCurrentTimeZone() (timezone lookup)
admin.org-insights.v1 — dayjs().format("HH:mm:ss") (date formatting)
admin.tenants.v1 — getActiveTabFromUrl() (URL parsing)

Related Issues

  • N/A

Related PRs

  • N/A

Checklist

  • e2e cypress tests locally verified. (for internal contributers)
  • Manual test round performed and verified.
  • UX/UI review done on the final implementation.
  • Documentation provided. (Add links if there are any)
  • Relevant backend changes deployed and verified
  • Unit tests provided. (Add links if there are any)
  • Integration tests provided. (Add links if there are any)

Security checks

Developer Checklist (Mandatory)

  • Complete the Developer Checklist in the related product-is issue to track any behavioral change or migration impact.
  • Behavioral change? No. This is a pure performance fix. Initialization logic is unchanged; only when it runs changes (mount only vs. every render). No visible difference to users.
  • Migration impact? No.
  • New configuration? No.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Six React components convert their useState initial values from eagerly evaluated expressions to lazy initializer functions (() => value), so the computations run only on initial mount instead of on every render.

Changes

Lazy useState initializer conversions

Layer / File(s) Summary
Lazy useState initializer conversions
features/admin.claims.v1/.../edit-mapped-attributes-local-claims.tsx, features/admin.console-settings.v1/.../console-settings-tabs.tsx, features/admin.login-flow-builder.v1/.../authentication-flow-provider.tsx, features/admin.logs.v1/.../time-range-selector.tsx, features/admin.org-insights.v1/.../org-insights.tsx, features/admin.tenants.v1/.../system-settings-tabs.tsx
Each file wraps its useState initial value in a function: getExcludedStoresFromClaim, getActiveTabFromUrl, cloneDeep, getCurrentTimeZone, dayjs().format, and getActiveTabFromUrl respectively.

Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error)

Check name Status Explanation Resolution
Changeset Required ❌ Error The PR’s changed files are feature components only; no new .changeset/*.md file is included, and .changeset contains only README.md/config.json. Add a new .changeset/*.md for the affected packages (e.g. @wso2is/console and related modules) with the correct version bump.
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: converting state initialization to lazy useState initializers to avoid reruns on re-render.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description check ✅ Passed The PR description follows the template and includes purpose, related links, checklist items, security checks, and developer checklist details.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • 🛠️ create changeset

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.

@siddhartha928

Copy link
Copy Markdown
Author

recheck

@siddhartha928

Copy link
Copy Markdown
Author

@pavinduLakshan Could you please review this

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.

[React Doctor] rerender-lazy-state-init: useState(getExcludedStoresFromClaim()) calls initializer on every render — us... (6 occurrences)

3 participants