mirror of
https://github.com/fosrl/pangolin.git
synced 2026-05-08 05:39:49 -05:00
[PR #2537] [MERGED] fix: sync resource toggle states with context on initial load #9799
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/fosrl/pangolin/pull/2537
Author: @Abhinav-kodes
Created: 2/25/2026
Status: ✅ Merged
Merged: 2/25/2026
Merged by: @oschwartz10612
Base:
dev← Head:fix/toggle-hydration-sync📝 Commits (1)
c600da7fix: sync resource toggle states with context on initial load📊 Changes
2 files changed (+20 additions, -6 deletions)
View changed files
📝
src/app/[orgId]/settings/resources/proxy/[niceId]/authentication/page.tsx(+13 -4)📝
src/app/[orgId]/settings/resources/proxy/[niceId]/rules/page.tsx(+7 -2)📄 Description
Community Contribution License Agreement
By creating this pull request, I grant the project maintainers an unlimited,
perpetual license to use, modify, and redistribute these contributions under any terms they
choose, including both the AGPLv3 and the Fossorial Commercial license terms. I
represent that I have the right to grant this license for all contributed content.
Description
Fixes a hydration bug where the Enable Rules, SSO, and Email Whitelist toggles on resource settings pages would always render in the OFF state on cold load, regardless of the actual saved value in the database.
Closes fosrl/pangolin#2528
Root Cause
The
SwitchInputcomponents were using thedefaultCheckedprop (uncontrolled), which React only reads on the first render. Since the resource context hydrates asynchronously after mount, the first render always seesundefinedor a stale value, so the toggles always appeared OFF.Additionally, the state variables were initialized once via
useState(resource.X)with no mechanism to re-sync when the context updated.Changes
src/app/[orgId]/settings/resources/proxy/[niceId]/rules/page.tsxuseState(resource.applyRules ?? false)— added?? falsefallbackuseEffectto syncrulesEnabledwhenresource.applyRulesupdatesdefaultChecked={rulesEnabled}→checked={rulesEnabled}(controlled)src/app/[orgId]/settings/resources/proxy/[niceId]/authentication/page.tsxuseState(resource.sso ?? false)— added?? falsefallbackuseEffectto syncssoEnabledwhenresource.ssoupdatesdefaultChecked={resource.sso}→checked={ssoEnabled}(controlled)useState(resource.emailWhitelistEnabled ?? false)— added?? falsefallbackuseEffectto syncwhitelistEnabledwhenresource.emailWhitelistEnabledupdatesdefaultChecked={resource.emailWhitelistEnabled}→checked={whitelistEnabled}(controlled)Before / After
Before: Toggle always renders OFF on hard refresh, even when DB value is
true.After: Toggle correctly reflects the saved DB value immediately on load.
Testing
Ctrl+Shift+R) on a resource withapplyRules = true→ Rules toggle shows ONemailWhitelistEnabled = true→ Whitelist toggle shows ONsso = true→ SSO toggle shows ONType of Change
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.