Skip to content

Commit 9398e0d

Browse files
committed
fix: prevent infinite renders in CreateWorkspacePageView by replacing useEffect with useEffectEvent
1 parent d843fa9 commit 9398e0d

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { Stack } from "components/Stack/Stack";
2626
import { Switch } from "components/Switch/Switch";
2727
import { UserAutocomplete } from "components/UserAutocomplete/UserAutocomplete";
2828
import { type FormikContextType, useFormik } from "formik";
29+
import { useEffectEvent } from "hooks/hookPolyfills";
2930
import type { ExternalAuthPollingState } from "hooks/useExternalAuth";
3031
import { ExternalLinkIcon } from "lucide-react";
3132
import { linkToTemplate, useLinks } from "modules/navigation";
@@ -162,7 +163,7 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
162163
]);
163164
const [selectedPresetIndex, setSelectedPresetIndex] = useState(0);
164165
// Build options and keep default label/value in sync
165-
useEffect(() => {
166+
useEffectEvent(() => {
166167
const options = [
167168
{ displayName: "None", value: "undefined", icon: "", description: "" },
168169
...presets.map((preset) => ({
@@ -182,12 +183,12 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
182183
setSelectedPresetIndex(0); // Explicitly set to "None"
183184
form.setFieldValue("template_version_preset_id", undefined);
184185
}
185-
}, [presets, form.setFieldValue]);
186+
});
186187

187188
const [presetParameterNames, setPresetParameterNames] = useState<string[]>(
188189
[],
189190
);
190-
useEffect(() => {
191+
useEffectEvent(() => {
191192
const selectedPresetOption = presetOptions[selectedPresetIndex];
192193
let selectedPreset: TypesGen.Preset | undefined;
193194
for (const preset of presets) {
@@ -217,13 +218,7 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
217218
value: presetParameter.Value,
218219
});
219220
}
220-
}, [
221-
presetOptions,
222-
selectedPresetIndex,
223-
presets,
224-
parameters,
225-
form.setFieldValue,
226-
]);
221+
});
227222

228223
return (
229224
<Margins size="medium">

0 commit comments

Comments
 (0)