-
Notifications
You must be signed in to change notification settings - Fork 1k
fix: remove response setting for the first message #20364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This is a good observation. The first message is incorrect because it assumes 0 inputs. The first message the webui sends is the inputs, and the next response is the true initial form.
So I wonder if we need a way to open the websocket with some initial input values? Or ignore the first state back? @jaaydenh I think you would have the most insight here. |
@Emyrk could I ask you to QA it locally and see if it works as expected? I don’t want to spend more time thinking about it without being sure this actually fixes the problem. I tested it myself, but a double check never hurts. 🙏 |
@BrunoQuaresma it does fix it. The error message you see in this video happens on dogfood too when it also resets the Screencast.From.2025-10-17.11-50-58.webm |
@steve-Coder-Ent about the error message, I think it happens because you are selecting the already selected option, which unselects it and sets the field value to
So the following code should not be necessary, correct? // On page load, sends initial workspace build parameters to the websocket.
// This ensures the backend has the form's complete initial state,
// vital for rendering dynamic UI elements dependent on initial parameter values.
const sendInitialParameters = useEffectEvent(() => {
if (initialParamsSentRef.current) return;
if (autofillParameters.length === 0) return;
const initialParamsToSend: Record<string, string> = {};
for (const param of autofillParameters) {
if (param.name && param.value) {
initialParamsToSend[param.name] = param.value;
}
}
if (Object.keys(initialParamsToSend).length === 0) return;
sendMessage(initialParamsToSend);
initialParamsSentRef.current = true;
}); Which also makes me wonder, if the BE already has all the necessary information, why can’t the first websocket message contain the correct values? |
This does fix the issue atleast temporarily but the root cause is that the frontend is using formik's touched fields state to keep track of which form fields should always be sent to the server on every request. If a field, that has a legitimate value that we want to maintain on the frontend, is not sent in a request, then the backend will always return that field with its default value which is the incorrect behavior in this case. I am still investigating what the proper fix should be. |
@jaayden is this something you’d like to assign to yourself, or should I take it over? I just want to make sure we don’t duplicate efforts. I’d be more than happy to help and dive deeper into this, but if you think you can get it done faster, I’m totally fine with that. Please let me know what you think. |
I noticed that the connection wasn’t returning all the parameters in the first message, which caused the form to miss some field values. I was able to fix it by not setting the latest message before sending the initial parameters. After running some tests, everything seems to work nicely. Because of that, I also noticed that
useSyncFormParameters
might not be necessary anymore.Update ----
The root cause is that formik's form.initialTouched was being used with the assumption that it would retain the touched state of the fields. However, this state was getting lost when handleChange was getting called when a dynamic parameter changed.
If the websocket request does not include a field on the form with an existing value, the server will respond with the default for that parameter, which cause that parameter to lose the existing value that is set.
The fix is to keep track explicitly keep track of touched fields on the form using form.setFieldTouched.
Fix #20257