Skip to content
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

WorkflowEditActionFormServerlessFunction component directly mutates props #8523

Closed
Devessier opened this issue Nov 15, 2024 · 0 comments · Fixed by #8580
Closed

WorkflowEditActionFormServerlessFunction component directly mutates props #8523

Devessier opened this issue Nov 15, 2024 · 0 comments · Fixed by #8580
Assignees
Labels
scope: front Issues that are affecting the frontend side only

Comments

@Devessier
Copy link
Contributor

Devessier commented Nov 15, 2024

The setNestedValue function operates on a shallow copy and not a deep copy of the functionInput. This is hiding that we mutate props, which is forbidden with React as you know.

I would do two things:

  1. Call structuredClone on the obj in the setNestedValue to ensure we never mutate the object references.
  2. Synchronously store the state of the form in a useState
export const setNestedValue = (obj: any, path: string[], value: any) => {
  const newObj = structuredClone(obj);
  path.reduce((o, key, index) => {
    if (index === path.length - 1) {
      o[key] = value;
    }
    return o[key] || {};
  }, newObj);
  return newObj;
};

Video demo (open it): https://share.cleanshot.com/bJgJTBwD

@Devessier Devessier self-assigned this Nov 15, 2024
@Bonapara Bonapara added scope: front Issues that are affecting the frontend side only and removed type: bug labels Nov 18, 2024
@Devessier Devessier moved this from 🆕 New to 🏗 In progress in Product development ✅ Nov 18, 2024
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in Product development ✅ Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: front Issues that are affecting the frontend side only
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants