fix(planner): treat the trip opened before as still loading when another one opens

The store kept the previous trip until loadTrip ran after the first render, so the desktop planner mounted with that trip under the new id for a frame.
This commit is contained in:
Maurice
2026-11-23 15:10:36 +01:00
parent 855ec37935
commit 4fd8f3987f
2 changed files with 19 additions and 2 deletions
@@ -1,4 +1,4 @@
// FE-TP-TABLINK-001
// FE-TP-TABLINK-001, FE-TP-OPEN-001
import { act, renderHook, waitFor } from '@testing-library/react';
import type { ReactNode } from 'react';
@@ -108,3 +108,16 @@ describe('useTripPlanner — ?tab= while the planner is open', () => {
expect(sessionStorage.getItem('trip-tab-42')).toBe('collab');
});
});
describe('useTripPlanner: opening another trip', () => {
it('FE-TP-OPEN-001: the trip still held from the one opened before counts as loading, not as this one', async () => {
useTripStore.setState({ trip: buildTrip({ id: 7, title: 'Rome' }), isLoading: false });
const { result } = renderHook(() => useTripPlanner(), { wrapper });
expect(result.current.isLoading).toBe(true);
await act(async () => {
await Promise.resolve();
});
act(() => useTripStore.setState({ trip: buildTrip({ id: 42, title: 'Kyoto' }) }));
expect(result.current.isLoading).toBe(false);
});
});
@@ -724,10 +724,14 @@ export function useTripPlanner() {
return () => clearTimeout(timer)
}, [isLoading])
// The store still holds the trip opened before until loadTrip runs after the first
// render, so that trip counts as loading too rather than showing under this one's id.
const opening = isLoading || (trip != null && trip.id !== tripId)
return {
tripId, navigate, toast, t, language, locale, settings, placesPhotosEnabled,
trip, days, places, assignments, storedAssignments, packingItems, todoItems, categories, reservations, budgetItems, files,
selectedDayId, isLoading, tripActions, can, canUploadFiles,
selectedDayId, isLoading: opening, tripActions, can, canUploadFiles,
pushUndo, undo, canUndo, lastActionLabel, handleUndo,
enabledAddons, collabFeatures, journalId: journal.openJournalId, tripAccommodations, setTripAccommodations,
roadtripMode, toggleRoadtripMode, roadtripActive, roadtripFeedActive, roadtripRoutes, roadtripLineColors, roadtripMapLines, roadtripMapPlaces, collapsedRoadtripDays, toggleRoadtripDay, roadtripCorridor,