Skip to content

Fix bug when changing from string to null in forms#281

Merged
cristian-tamblay merged 1 commit into
developfrom
fix/null-string-type-change
Sep 2, 2025
Merged

Fix bug when changing from string to null in forms#281
cristian-tamblay merged 1 commit into
developfrom
fix/null-string-type-change

Conversation

@Irozuku
Copy link
Copy Markdown
Collaborator

@Irozuku Irozuku commented Sep 1, 2025

This pull request refactors the FormSchemaFieldWithOptions.jsx component to optimize how the JSON schema for form fields is computed and to fix a re-render loop bug that occurred when switching parameter types.

Bug Description & Reproduction Steps

Previously, the paramJsonSchema object was created inline inside fieldProps, which meant a new object reference was generated on every render. This caused the useEffect that depended on fieldProps.paramJsonSchema to run unnecessarily, even when nothing semantically changed.

This became a problem when multiple parameters had validation errors:

  1. Go to the PCA converter settings.
  2. Change the first parameter (N Components) to string, triggering a "required" error.
  3. Change the parameter back to null.
  4. Scroll down to Power Iteration Normalization, change it to null, and then back to string.
  5. At this point, the parameters list would enter an infinite re-render loop.

Why It Happened

  • Each re-render created a new paramJsonSchema object.
  • This triggered the useEffect validator again, which called handleSetError.
  • Calling handleSetError caused the parent list of parameters to re-render.
  • The cycle repeated as the newly rendered components generated new schema objects, retriggering validation continuously.

Fix

  • Wrapped the creation of paramJsonSchema in a useMemo hook, with dependencies [title, description, required, options, selectedType].
  • This ensures that paramJsonSchema retains the same reference unless one of its dependencies actually changes, breaking the re-render loop and significantly improving performance.

Performance and React Optimization

  • Avoids unnecessary useEffect executions on every render.
  • Prevents infinite re-renders when toggling parameter types with active validation errors.
  • Improves rendering efficiency by reducing object churn in fieldProps.

@cristian-tamblay cristian-tamblay merged commit bdcc175 into develop Sep 2, 2025
4 checks passed
@cristian-tamblay cristian-tamblay deleted the fix/null-string-type-change branch September 2, 2025 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants