fix(spa): debounce commit must not wipe selection/page when query is unchanged (CI flake + real UX race) (#208 #209)
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 7m55s
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 12s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 10m11s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped

This commit is contained in:
2026-07-10 08:07:24 +02:00
parent 279052ccd4
commit 9e6ea3567c
2 changed files with 17 additions and 1 deletions
+10 -1
View File
@@ -79,6 +79,7 @@ export function MediaBrowseScreen() {
const [notice, setNotice] = useState<Notice | null>(null);
const activeRef = useRef(true);
const seqRef = useRef(0);
const lastQueryRef = useRef(initialQuery.trim());
useEffect(() => {
activeRef.current = true;
@@ -88,10 +89,17 @@ export function MediaBrowseScreen() {
}, []);
// Debounce the per-kind free-text box; it composes straight into the browse (Lucene) query.
// The no-change guard matters: this timer also fires once on mount (and after kind changes),
// and must not reset the page or wipe an in-progress selection when the query is unchanged.
useEffect(() => {
const handle = window.setTimeout(() => {
const next = queryInput.trim();
if (lastQueryRef.current === next) {
return;
}
lastQueryRef.current = next;
setPageNum(0);
setQuery(queryInput.trim());
setQuery(next);
setSelected(new Map());
}, 300);
@@ -123,6 +131,7 @@ export function MediaBrowseScreen() {
setPageNum(0);
setQueryInput('');
setQuery('');
lastQueryRef.current = '';
setSelected(new Map());
// Keep the URL shareable/back-navigable without remounting the whole screen.
window.history.replaceState(null, '', `/app/media?kind=${next.slug}`);
+7
View File
@@ -73,6 +73,7 @@ export function SearchScreen() {
const [notice, setNotice] = useState<Notice | null>(null);
const activeRef = useRef(true);
const seqRef = useRef(0);
const lastQueryRef = useRef(initialQuery.trim());
const hasQuery = query.trim().length > 0;
useEffect(() => {
@@ -82,9 +83,15 @@ export function SearchScreen() {
};
}, []);
// The no-change guard matters: this timer also fires once on mount and must not wipe an
// in-progress selection when the query is unchanged.
useEffect(() => {
const handle = window.setTimeout(() => {
const trimmed = queryInput.trim();
if (lastQueryRef.current === trimmed) {
return;
}
lastQueryRef.current = trimmed;
setQuery(trimmed);
// A new query means a new result set — drop any stale selection (mirrors MediaBrowseScreen).
setSelected(new Map());