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.
The SwitchInput components were using the defaultChecked prop (uncontrolled), which React only reads on the first render. Since the resource context hydrates asynchronously after mount, the first render always sees undefined or 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.
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
Hard refresh (Ctrl+Shift+R) on a resource with applyRules = true → Rules toggle shows ON
Hard refresh on a resource with emailWhitelistEnabled = true → Whitelist toggle shows ON
Hard refresh on a resource with sso = true → SSO toggle shows ON
Toggling any switch and saving still works correctly
No React controlled/uncontrolled warnings in console
Type of Change
Bug fix (non-breaking change which fixes an issue)
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/fosrl/pangolin/pull/2537
**Author:** [@Abhinav-kodes](https://github.com/Abhinav-kodes)
**Created:** 2/25/2026
**Status:** ✅ Merged
**Merged:** 2/25/2026
**Merged by:** [@oschwartz10612](https://github.com/oschwartz10612)
**Base:** `dev` ← **Head:** `fix/toggle-hydration-sync`
---
### 📝 Commits (1)
- [`c600da7`](https://github.com/fosrl/pangolin/commit/c600da71e3ffb873ba0ad27fe49363a44bccd9ae) fix: sync resource toggle states with context on initial load
### 📊 Changes
**2 files changed** (+20 additions, -6 deletions)
<details>
<summary>View changed files</summary>
📝 `src/app/[orgId]/settings/resources/proxy/[niceId]/authentication/page.tsx` (+13 -4)
📝 `src/app/[orgId]/settings/resources/proxy/[niceId]/rules/page.tsx` (+7 -2)
</details>
### 📄 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 `SwitchInput` components were using the `defaultChecked` prop (uncontrolled), which React only reads on the **first render**. Since the resource context hydrates asynchronously after mount, the first render always sees `undefined` or 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.tsx`
- `useState(resource.applyRules ?? false)` — added `?? false` fallback
- Added `useEffect` to sync `rulesEnabled` when `resource.applyRules` updates
- Changed `defaultChecked={rulesEnabled}` → `checked={rulesEnabled}` (controlled)
### `src/app/[orgId]/settings/resources/proxy/[niceId]/authentication/page.tsx`
- `useState(resource.sso ?? false)` — added `?? false` fallback
- Added `useEffect` to sync `ssoEnabled` when `resource.sso` updates
- Changed `defaultChecked={resource.sso}` → `checked={ssoEnabled}` (controlled)
- `useState(resource.emailWhitelistEnabled ?? false)` — added `?? false` fallback
- Added `useEffect` to sync `whitelistEnabled` when `resource.emailWhitelistEnabled` updates
- Changed `defaultChecked={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
- [ ] Hard refresh (`Ctrl+Shift+R`) on a resource with `applyRules = true` → Rules toggle shows ON
- [ ] Hard refresh on a resource with `emailWhitelistEnabled = true` → Whitelist toggle shows ON
- [ ] Hard refresh on a resource with `sso = true` → SSO toggle shows ON
- [ ] Toggling any switch and saving still works correctly
- [ ] No React controlled/uncontrolled warnings in console
## Type of Change
- [x] Bug fix (non-breaking change which fixes an issue)
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 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.