You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using a custom value editor with a select dropdown in the React Query Builder, the entire custom value editor re-renders whenever the props.handleOnChange function is triggered by selecting an option in the dropdown. This behaviour is causing performance issues and unnecessary API calls.
Reproduction
Steps to reproduce:
Implement a custom value editor for the React Query Builder.
Use a select dropdown as part of the custom value editor.
Pass the props.handleOnChange function to the dropdown's onChange handler.
Change the dropdown's selected option.
Expected behavior
The dropdown should update its value without re-rendering the entire custom value editor.
The parent component should not trigger unnecessary API calls or state updates unless the value has genuinely changed.
Additional information
The issue is likely caused by the props.handleOnChange function triggering a state update in the parent component, which propagates back to the custom value editor.
The dropdown options are dynamically generated, and the value is passed as a prop to the dropdown.
For one, version 7 introduced a ton of performance improvements mainly related to memoization, so upgrading to the latest (currently v8.5.0) may resolve any perf issues you're encountering with v6.5.5.
Secondly, you say "The dropdown should update its value without re-rendering the entire custom value editor." I may be wrong, but I'm pretty sure that can only be the case with an uncontrolled component (and maybe not even then, at least it's not guaranteed). All sub-components (custom or not) are controlled components within QueyrBuilder, so a value change will necessarily cause a re-render. With v7/v8, the re-renders are granular to the rule level, but they still happen.
But I'm curious why it matters. Are you seeing issues due to too many re-renders of the value editor specifically? Now that I'm typing this out, I'm getting the feeling you're talking about re-renders of the entire query builder component and not just the value editor. If that's the case, then upgrading to the latest version should resolve the problem.
Re-renders occur in the custom value editor due to API calls with no-cache, explicitly displaying the component in a loading state. To address this, we implemented cache logic to prevent redundant API calls.
I understand that handleOnChange is necessary to update the state of the rules, which triggers re-renders. However, the issue has been resolved through an alternative approach.
React Query Builder version
6.5.5
Platform
Chrome on macOS 15.4.1
Description
Hi,
When using a custom value editor with a select dropdown in the React Query Builder, the entire custom value editor re-renders whenever the props.handleOnChange function is triggered by selecting an option in the dropdown. This behaviour is causing performance issues and unnecessary API calls.
Reproduction
Steps to reproduce:
Expected behavior
The dropdown should update its value without re-rendering the entire custom value editor.
The parent component should not trigger unnecessary API calls or state updates unless the value has genuinely changed.
Additional information
The issue is likely caused by the props.handleOnChange function triggering a state update in the parent component, which propagates back to the custom value editor.
The dropdown options are dynamically generated, and the value is passed as a prop to the dropdown.
Sample code:
The text was updated successfully, but these errors were encountered: