Skip to content

Commit 89d2090

Browse files
committed
Fixed race condition that would occasionally set the dataset path to the first one when editing a job
1 parent 3f7a3d8 commit 89d2090

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

ui/src/app/jobs/new/page.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { defaultJobConfig, defaultDatasetConfig, migrateJobConfig } from './jobC
66
import { jobTypeOptions } from './options';
77
import { JobConfig } from '@/types';
88
import { objectCopy } from '@/utils/basic';
9-
import { useNestedState } from '@/utils/hooks';
9+
import { useNestedState, setNestedValue } from '@/utils/hooks';
1010
import { SelectInput } from '@/components/formInputs';
1111
import useSettings from '@/hooks/useSettings';
1212
import useGPUInfo from '@/hooks/useGPUInfo';
@@ -87,15 +87,19 @@ export default function TrainingForm() {
8787

8888
const datasetOptions = datasets.map(name => ({ value: path.join(settings.DATASETS_FOLDER, name), label: name }));
8989
setDatasetOptions(datasetOptions);
90-
const defaultDatasetPath = defaultDatasetConfig.folder_path;
9190

92-
for (let i = 0; i < jobConfig.config.process[0].datasets.length; i++) {
93-
const dataset = jobConfig.config.process[0].datasets[i];
94-
if (dataset.folder_path === defaultDatasetPath) {
95-
if (datasetOptions.length > 0) {
96-
setJobConfig(datasetOptions[0].value, `config.process[0].datasets[${i}].folder_path`);
91+
if (datasetOptions.length > 0) {
92+
const defaultDatasetPath = defaultDatasetConfig.folder_path;
93+
// Use functional updater so we check the *current* state, not a stale closure
94+
setJobConfig((prev: JobConfig) => {
95+
let updated = prev;
96+
for (let i = 0; i < prev.config.process[0].datasets.length; i++) {
97+
if (prev.config.process[0].datasets[i].folder_path === defaultDatasetPath) {
98+
updated = setNestedValue(updated, datasetOptions[0].value, `config.process[0].datasets[${i}].folder_path`);
99+
}
97100
}
98-
}
101+
return updated;
102+
});
99103
}
100104
}, [datasets, settings, isSettingsLoaded, datasetFetchStatus]);
101105

0 commit comments

Comments
 (0)