Skip to content

Commit 2592245

Browse files
committed
Fix bug preventing the same file from being imported twice
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.
1 parent 583522b commit 2592245

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

packages/react-devtools-scheduling-profiler/src/ImportButton.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ export default function ImportButton({onDataImported}: Props) {
3232

3333
const handleFiles = useCallback(async () => {
3434
const input = inputRef.current;
35-
if (input !== null && input.files.length > 0) {
35+
if (input === null) {
36+
return;
37+
}
38+
39+
if (input.files.length > 0) {
3640
try {
3741
const readFile = await readInputData(input.files[0]);
3842
const events: TimelineEvent[] = JSON.parse(readFile);
@@ -54,6 +58,9 @@ export default function ImportButton({onDataImported}: Props) {
5458
});
5559
}
5660
}
61+
62+
// Reset input element to allow the same file to be re-imported
63+
input.value = '';
5764
}, [onDataImported, modalDialogDispatch]);
5865

5966
const uploadData = useCallback(() => {

0 commit comments

Comments
 (0)