fix: SettingsPage syncs active tab when ?tab changes post-mount (closes #479)#551
Merged
Conversation
…loses #479) SettingsPage initialised activeTab from ?tab only once in useState. External navigation (back/forward, programmatic pushes) while the page stayed mounted silently desynchronised the displayed tab from the URL. Fix: add a useEffect that watches searchParams and calls setActiveTab only when the resolved tab differs from the current one, guarding against update loops. Extract the param→tab resolution into a standalone pure helper (frontend/src/lib/settingsTabParam.ts) so it can be node-strip tested without React. 13 new behavioural unit tests cover all tabs, both legacy aliases (Bootstrap/Advanced → Automation), empty and null inputs. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Coverage Report✅ 81.1% on Gate passed |
Coverage Report✅ 81.1% on Gate passed |
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.
Summary
SettingsPageread?tabfrom the URL only in theuseStatelazy initializer, so external navigation (back/forward, programmatichistory.push) while the page stayed mounted left the displayed tab out of sync with the URL.useEffectwatchingsearchParamsthat callssetActiveTabonly when the normalised value differs from the current tab, preventing update loops.frontend/src/lib/settingsTabParam.ts(resolveSettingsTab) so the logic is testable without React or a browser.'Bootstrap'/'Advanced'→'Automation'), empty string, andnull.normaliseLegacyTabinline logic removed from the component;TABSconstant retained for the JSX tab bar.Closes #479
Test plan
pytest tests/unit/test_settings_tab_param.py -v— 14 tests, all passpytest tests/unit/ -q— 1957 passed, 0 failurespnpm exec tsc -b --noEmit(frontend) — exit 0pnpm exec eslint src/pages/SettingsPage.tsx src/lib/settingsTabParam.ts— exit 0🤖 Generated with Claude Code