Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: resolve Tribe tab updates against fresh URL; assert explicit label/id pairing (#2522)

Adam Eivycfa9de4a7929
diff --git a/client/src/components/media/StylePresetPicker.test.jsx b/client/src/components/media/StylePresetPicker.test.jsx
index ae56823cb4..b8994dd089 100644
--- a/client/src/components/media/StylePresetPicker.test.jsx
+++ b/client/src/components/media/StylePresetPicker.test.jsx
@@ -8,17 +8,23 @@ vi.mock('../../services/apiSystem', () => ({
import StylePresetPicker from './StylePresetPicker';
describe('StylePresetPicker label association', () => {
- it('pairs the label with the select (htmlFor/id)', async () => {
+ it('pairs the label with the select via explicit htmlFor/id', async () => {
render(<StylePresetPicker value={null} onChange={() => {}} />);
- // findByLabelText both settles the async preset fetch and asserts the
- // label→control association is wired.
+ // findByLabelText settles the async preset fetch; asserting htmlFor === id
+ // proves the *visible* label is wired (findByLabelText alone would also
+ // accept an aria-label with a detached visible label).
const select = await screen.findByLabelText('Style preset');
+ const label = screen.getByText('Style preset').closest('label');
expect(select.tagName).toBe('SELECT');
+ expect(select.id).toBeTruthy();
+ expect(label.getAttribute('for')).toBe(select.id);
});
it('honors a custom label prop', async () => {
render(<StylePresetPicker value={null} onChange={() => {}} label="Cover style" />);
- expect((await screen.findByLabelText('Cover style')).tagName).toBe('SELECT');
+ const select = await screen.findByLabelText('Cover style');
+ const label = screen.getByText('Cover style').closest('label');
+ expect(label.getAttribute('for')).toBe(select.id);
});
it('gives each instance a unique control id', async () => {
diff --git a/client/src/pages/Loops.test.jsx b/client/src/pages/Loops.test.jsx
index c7195da960..2deacf6202 100644
--- a/client/src/pages/Loops.test.jsx
+++ b/client/src/pages/Loops.test.jsx
@@ -22,11 +22,14 @@ vi.mock('../hooks/useAutoRefetch', () => ({
import Loops from './Loops';
describe('Loops new-loop form label associations', () => {
- it('pairs the Interval label with the custom-interval input (htmlFor/id)', async () => {
+ it('pairs the Interval label with the custom-interval input via explicit htmlFor/id', async () => {
render(<Loops />);
- // getByLabelText only resolves when the <label> is wired to the control.
const input = await screen.findByLabelText('Interval');
+ const label = screen.getByText('Interval');
expect(input.tagName).toBe('INPUT');
expect(input.getAttribute('placeholder')).toBe('custom');
+ // Prove the explicit htmlFor/id pairing (not merely an aria-label match).
+ expect(input.id).toBeTruthy();
+ expect(label.getAttribute('for')).toBe(input.id);
});
});
diff --git a/client/src/pages/Tribe.jsx b/client/src/pages/Tribe.jsx
index c948adb090..c746064126 100644
--- a/client/src/pages/Tribe.jsx
+++ b/client/src/pages/Tribe.jsx
@@ -658,12 +658,20 @@ export default function Tribe() {
const [searchParams, setSearchParams] = useSearchParams();
const rawTab = searchParams.get('tab');
const activeTab = TAB_IDS.includes(rawTab) ? rawTab : DEFAULT_TAB;
+ // Resolve inside the setSearchParams updater so functional updates (e.g.
+ // startNewRelationship) read the FRESHEST tab from the URL, not the value
+ // captured when a since-superseded async closure was created — otherwise a
+ // create-in-flight + tab switch could clobber the user's current tab.
const setActiveTab = (next) => {
- const resolved = typeof next === 'function' ? next(activeTab) : next;
- const params = new URLSearchParams(searchParams);
- if (resolved === DEFAULT_TAB) params.delete('tab');
- else params.set('tab', resolved);
- setSearchParams(params, { replace: true });
+ setSearchParams((prev) => {
+ const prevRaw = prev.get('tab');
+ const prevTab = TAB_IDS.includes(prevRaw) ? prevRaw : DEFAULT_TAB;
+ const resolved = typeof next === 'function' ? next(prevTab) : next;
+ const params = new URLSearchParams(prev);
+ if (resolved === DEFAULT_TAB) params.delete('tab');
+ else params.set('tab', resolved);
+ return params;
+ }, { replace: true });
};
const [loading, setLoading] = useState(true);
const [saving, setSaving] = useState(false);
diff --git a/client/src/pages/Tribe.test.jsx b/client/src/pages/Tribe.test.jsx
index 8934f2983f..02371ddb8b 100644
--- a/client/src/pages/Tribe.test.jsx
+++ b/client/src/pages/Tribe.test.jsx
@@ -63,4 +63,16 @@ describe('Tribe deep-linkable tabs', () => {
expect(screen.getByTestId('location').textContent).toBe('/tribe')
);
});
+
+ it('preserves a non-default tab when the Add action fires a functional update', async () => {
+ // "Add" calls startNewRelationship, which uses a functional setActiveTab
+ // updater that keeps the current tab unless it is focus/map. On Care it must
+ // resolve against the fresh URL and stay on care — not fall back to circle.
+ renderAt('/tribe?tab=care');
+ await screen.findByRole('button', { name: 'Add' });
+ fireEvent.click(screen.getByRole('button', { name: 'Add' }));
+ await waitFor(() =>
+ expect(screen.getByTestId('location').textContent).toBe('/tribe?tab=care')
+ );
+ });
});