fix: guard initial file load in search mode and discard stale search results
Add a check in FileList.connectedCallback to skip loading all files when data-search-mode attribute is present, preventing empty result sets from overwriting search results on partial matches. Introduce a monotonically increasing search ID counter in RBoxApp to discard responses from outdated search requests, ensuring only the latest query result is rendered and stale error messages are suppressed.
This commit is contained in:
parent
987dd33a8c
commit
bff5742ced
@ -18,7 +18,9 @@ export class FileList extends HTMLElement {
|
||||
this.addEventListener('click', this.boundHandleClick);
|
||||
this.addEventListener('dblclick', this.boundHandleDblClick);
|
||||
this.addEventListener('change', this.boundHandleChange);
|
||||
await this.loadContents(null);
|
||||
if (!this.hasAttribute('data-search-mode')) {
|
||||
await this.loadContents(null);
|
||||
}
|
||||
}
|
||||
|
||||
disconnectedCallback() {
|
||||
|
||||
@ -28,6 +28,7 @@ export class RBoxApp extends HTMLElement {
|
||||
this.navigationStack = [];
|
||||
this.boundHandlePopState = this.handlePopState.bind(this);
|
||||
this.popstateAttached = false;
|
||||
this.currentSearchId = 0;
|
||||
}
|
||||
|
||||
async connectedCallback() {
|
||||
@ -567,8 +568,10 @@ export class RBoxApp extends HTMLElement {
|
||||
}
|
||||
|
||||
async performSearch(query) {
|
||||
const searchId = ++this.currentSearchId;
|
||||
try {
|
||||
const files = await api.searchFiles(query);
|
||||
if (searchId !== this.currentSearchId) return;
|
||||
const mainContent = this.querySelector('#main-content');
|
||||
mainContent.innerHTML = `
|
||||
<div class="search-results">
|
||||
@ -580,7 +583,9 @@ export class RBoxApp extends HTMLElement {
|
||||
fileList.setFiles(files);
|
||||
this.attachListeners();
|
||||
} catch (error) {
|
||||
console.error('Search failed:', error);
|
||||
if (searchId === this.currentSearchId) {
|
||||
console.error('Search failed:', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user