Skip to content

Commit e5ae6dc

Browse files
nabeelreclaude
andcommitted
Fix FileList live-reference bug in directory picker
FileList is a live object — e.target.value = "" empties it in place, so the previous Array.from(files) after the reset always returned []. Fix by snapshotting to Array before the reset. Also improve the no-.arrow-files error to list the files that actually arrived, making it easier to diagnose if the directory structure is different from what's expected. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e68fd0a commit e5ae6dc

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

src/App.jsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,19 @@ export default function App() {
6767
};
6868

6969
const handleDirChange = (e) => {
70-
const files = e.target.files;
71-
if (!files || files.length === 0) return;
70+
// Snapshot the FileList into an Array BEFORE resetting the input value.
71+
// FileList is a live object — e.target.value = "" empties it in place,
72+
// so any Array.from() call after the reset returns [].
73+
const fileArray = Array.from(e.target.files);
7274
e.target.value = "";
75+
if (fileArray.length === 0) return;
7376
const dirName =
74-
files[0]?.webkitRelativePath?.split("/")[0] ?? files[0]?.name ?? "dataset";
77+
fileArray[0]?.webkitRelativePath?.split("/")[0] ?? fileArray[0]?.name ?? "dataset";
7578
const descriptor = {
7679
id: `hf-disk::${dirName}`,
7780
label: dirName,
7881
source: "hf-disk",
79-
files: Array.from(files),
82+
files: fileArray,
8083
};
8184
setDatasets((prev) => {
8285
const without = prev.filter((d) => d.id !== descriptor.id);

src/data/HFDiskDataSource.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ import { tableFromIPC, DataType } from "apache-arrow";
1111
export class HFDiskDataSource extends DataSource {
1212
constructor(files) {
1313
super();
14-
this._shards = Array.from(files)
14+
const all = Array.from(files);
15+
this._shards = all
1516
.filter((f) => f.name.endsWith(".arrow"))
1617
.sort((a, b) => a.name.localeCompare(b.name));
17-
this._infoFile = Array.from(files).find((f) => f.name === "dataset_info.json");
18+
this._infoFile = all.find((f) => f.name === "dataset_info.json");
1819
this.dirName =
19-
files[0]?.webkitRelativePath?.split("/")[0] ?? files[0]?.name ?? "dataset";
20+
all[0]?.webkitRelativePath?.split("/")[0] ?? all[0]?.name ?? "dataset";
21+
this._allNames = all.map((f) => f.webkitRelativePath || f.name);
2022
}
2123

2224
async getInfo() {
@@ -38,9 +40,11 @@ export class HFDiskDataSource extends DataSource {
3840

3941
async getRows({ offset = 0, length = 100 } = {}) {
4042
if (this._shards.length === 0) {
43+
const preview = this._allNames.slice(0, 8).join(", ") || "none";
4144
throw new Error(
4245
`No .arrow files found in "${this.dirName}". ` +
43-
"Make sure you selected the directory containing the Arrow shards."
46+
`Files received: ${preview}${this._allNames.length > 8 ? ", …" : ""}. ` +
47+
"Select the directory that directly contains the .arrow shards."
4448
);
4549
}
4650

0 commit comments

Comments
 (0)