Skip to content

Commit ee59500

Browse files
committed
replace attribute MutationObserver against change listener
1 parent b686ac9 commit ee59500

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

client/browser/FinderFileSelect.tsx

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ export default function FinderFileSelect(props) {
1919
link.media = 'all';
2020
link.rel = 'stylesheet';
2121
shadowRoot.insertBefore(link, shadowRoot.firstChild);
22-
const observer = new MutationObserver(attributesChanged);
2322
const inputElement = slotRef.current.assignedElements()[0];
2423
if (inputElement instanceof HTMLInputElement) {
2524
setSelectedFile(JSON.parse(inputElement.getAttribute('data-selected_file')));
26-
observer.observe(inputElement, {attributes: true});
25+
inputElement.addEventListener('change', valueChanged);
2726
}
2827
return () => {
29-
observer.disconnect();
28+
inputElement.removeEventListener('change', valueChanged);
3029
};
3130
}, []);
3231

@@ -52,18 +51,13 @@ export default function FinderFileSelect(props) {
5251
}
5352
}, []);
5453

55-
async function attributesChanged(mutationList) {
56-
for (const mutation of mutationList) {
57-
if (mutation.type === 'attributes' && mutation.attributeName === 'data-file_id') {
58-
const fileId = mutation.target.dataset.file_id;
59-
const response = await fetch(`${baseUrl}${fileId}/fetch`);
60-
if (response.ok) {
61-
setSelectedFile(await response.json());
62-
} else {
63-
console.error(`Failed to fetch file info for ID ${fileId}:`, response.statusText);
64-
}
65-
66-
}
54+
async function valueChanged(event) {
55+
const fileId = event.target.value;
56+
const response = await fetch(`${baseUrl}${fileId}/fetch`);
57+
if (response.ok) {
58+
setSelectedFile(await response.json());
59+
} else {
60+
console.error(`Failed to fetch file info for ID ${fileId}:`, response.statusText);
6761
}
6862
}
6963

0 commit comments

Comments
 (0)