Skip to content

Commit

Permalink
Fix bug preventing the same file from being imported twice
Browse files Browse the repository at this point in the history
Bug: suppose we have a file which causes the profiler to display an error when
imported. Importing the file once causes the error to be displayed correctly.
However, if the file is imported a second time, the error is not displayed
again.

This happens because we listen to the `input` element's `onChange` event.
Selecting the same file a second time does not cause the element's value to
change, so the `handleFiles` callback is not called.

This commit fixes this bug by emptying the `input` element's `value` in
`handleFiles`.

This bug is also present in the React DevTools Profiler.
  • Loading branch information
taneliang committed Sep 3, 2020
1 parent f8498d1 commit 98a9c72
Showing 1 changed file with 8 additions and 1 deletion.
Expand Up @@ -32,7 +32,11 @@ export default function ImportButton({onDataImported}: Props) {

const handleFiles = useCallback(async () => {
const input = inputRef.current;
if (input !== null && input.files.length > 0) {
if (input === null) {
return;
}

if (input.files.length > 0) {
try {
const readFile = await readInputData(input.files[0]);
const events: TimelineEvent[] = JSON.parse(readFile);
Expand All @@ -54,6 +58,9 @@ export default function ImportButton({onDataImported}: Props) {
});
}
}

// Reset input element to allow the same file to be re-imported
input.value = '';
}, [onDataImported, modalDialogDispatch]);

const uploadData = useCallback(() => {
Expand Down

0 comments on commit 98a9c72

Please sign in to comment.