fix(client,sdk): the smaller silent failures, and a dead SDK test file

The SDK's parity suite had an unescaped apostrophe in an it() title, so the
file did not parse and vitest reported it as "no tests". Both guards in it
were dead - including the byte-identical egress-policy check the package's own
notes call the worst possible bug in that module to lose. No CI job runs the
SDK suite, so it landed quietly; the next npm publish would have failed on it,
since prepublishOnly runs the tests.

Also in the SDK: the dev preview answered trek:geolocation without checking
the geolocation:read grant, so a plugin whose manifest is missing the
permission works perfectly in dev and is dead once installed. That is the
lenient direction, which is the one that ships broken plugins.

Client side: the background-task poll never dismissed a 404'd import job and
spun forever, "Update All" collapsed its busy flag after the first plugin
settled, the lightbox had no cancellation so a slow signed URL rendered the
wrong image, the plugin geolocation watch was torn down by any unrelated
settings write, manual date entry accepted 31 February, cover previews were
never revoked, and check-all issued one request per packing item.
This commit is contained in:
Maurice
2026-08-23 10:08:38 +02:00
committed by Maurice
parent b3d8bf08f1
commit c75e958fc0
27 changed files with 476 additions and 53 deletions
@@ -1,4 +1,4 @@
// FE-COMP-TRIPFORM-001 to FE-COMP-TRIPFORM-082
// FE-COMP-TRIPFORM-001 to FE-COMP-TRIPFORM-084
import type { Mock } from 'vitest';
import { render, screen, waitFor, fireEvent } from '../../../tests/helpers/render';
import userEvent from '@testing-library/user-event';
@@ -1214,4 +1214,37 @@ describe('TripFormModal', () => {
await waitFor(() => expect(staleResolved).toBe(true));
expect(screen.queryByText('Stale failure')).not.toBeInTheDocument();
});
it('FE-COMP-TRIPFORM-083: a closed modal fetches nothing until it is opened', async () => {
// The trip planner keeps the modal mounted behind the page.
const seen: string[] = [];
server.use(
http.get('/api/auth/users', () => { seen.push('users'); return HttpResponse.json({ users: [] }); }),
http.get('/api/trips/:id/members', () => { seen.push('members'); return HttpResponse.json({ members: [] }); }),
);
const trip = buildTrip({ id: 5 });
const { rerender } = render(<TripFormModal {...defaultProps} isOpen={false} trip={trip} />);
await new Promise(resolve => setTimeout(resolve, 0));
expect(seen).toEqual([]);
rerender(<TripFormModal {...defaultProps} isOpen trip={trip} />);
await waitFor(() => expect(seen).toContain('users'));
expect(seen).toContain('members');
});
it('FE-COMP-TRIPFORM-084: staging another cover revokes the preview it replaces', async () => {
const revokeObjectURL = vi.fn();
const original = URL.revokeObjectURL;
Object.defineProperty(URL, 'revokeObjectURL', { writable: true, configurable: true, value: revokeObjectURL });
createObjectURL.mockReturnValueOnce('blob:first').mockReturnValueOnce('blob:second');
render(<TripFormModal {...defaultProps} trip={null} />);
fireEvent.change(fileInput(), { target: { files: [pngFile()] } });
await waitFor(() => expect(createObjectURL).toHaveBeenCalledTimes(1));
fireEvent.change(fileInput(), { target: { files: [pngFile()] } });
await waitFor(() => expect(revokeObjectURL).toHaveBeenCalledWith('blob:first'));
Object.defineProperty(URL, 'revokeObjectURL', { writable: true, configurable: true, value: original });
});
});
+22 -7
View File
@@ -40,6 +40,8 @@ export default function TripFormModal({ isOpen, onClose, onSave, trip, onCoverUp
const isEditing = !!trip
const fileRef = useRef<HTMLInputElement>(null)
const coverSearchSeq = useRef(0)
// The staged cover lives on as an object URL until it is replaced or the modal goes.
const previewUrlRef = useRef<string | null>(null)
const toast = useToast()
const { t } = useTranslation()
const currentUser = useAuthStore(s => s.user)
@@ -104,6 +106,10 @@ export default function TripFormModal({ isOpen, onClose, onSave, trip, onCoverUp
setCoverPreview(null)
setCoverSearchQuery('')
}
if (previewUrlRef.current) {
URL.revokeObjectURL(previewUrlRef.current)
previewUrlRef.current = null
}
setPendingCoverFile(null)
setPendingUnsplashUrl(null)
setCoverSearchResults([])
@@ -112,16 +118,17 @@ export default function TripFormModal({ isOpen, onClose, onSave, trip, onCoverUp
setPendingDateShift(null)
setDateShiftMode('keep_bookings')
setError('')
setExistingMembers([])
// The planner keeps this modal mounted while it is closed, so nothing may be
// fetched until it is actually open.
if (isOpen) {
authApi.getAppConfig().then((c: { trip_reminders_enabled?: boolean }) => {
if (c?.trip_reminders_enabled !== undefined) setTripRemindersEnabled(c.trip_reminders_enabled)
}).catch(() => {})
}
authApi.listUsers().then(d => setAllUsers(d.users || [])).catch(() => {})
if (trip) {
tripsApi.getMembers(trip.id).then(d => setExistingMembers(d.members || [])).catch(() => {})
} else {
setExistingMembers([])
authApi.listUsers().then(d => setAllUsers(d.users || [])).catch(() => {})
if (trip) {
tripsApi.getMembers(trip.id).then(d => setExistingMembers(d.members || [])).catch(() => {})
}
}
}, [trip, isOpen])
@@ -131,6 +138,12 @@ export default function TripFormModal({ isOpen, onClose, onSave, trip, onCoverUp
}
}, [tripRemindersEnabled])
// A staged cover that never got uploaded would otherwise pin the full image for
// as long as the tab lives.
useEffect(() => () => {
if (previewUrlRef.current) URL.revokeObjectURL(previewUrlRef.current)
}, [])
const handleSubmit = async (e) => {
e.preventDefault()
setError('')
@@ -219,7 +232,9 @@ export default function TripFormModal({ isOpen, onClose, onSave, trip, onCoverUp
} else {
// New trip: stage for upload after creation
setPendingCoverFile(normalized)
setCoverPreview(URL.createObjectURL(normalized))
if (previewUrlRef.current) URL.revokeObjectURL(previewUrlRef.current)
previewUrlRef.current = URL.createObjectURL(normalized)
setCoverPreview(previewUrlRef.current)
}
}