remove useEffect from state management in useDraggableTableControlled #3161
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
https://issues.redhat.com/browse/RHOAIENG-12561
Description
useDraggableTableControlled
was usinguseEffect
to keep track of draggable items internally. While this was functional it would also lead to a double render whenever the incoming items array changed. The negative side effect of this is that the first render would supply data to the consumer that was stale until the next render. As a result, components which rely on object identity of the table items would be rendering against stale data until the new state was applied in theuseEffect
.As noted in the linked issue, the connection type field would "blip" render an error icon indicating that the field's env var was a duplicate. The cause of this is because the check for duplicates would filter the given row data from the full set of table row data by object identity. Since the component was using stale data on the first render pass, the object identity check would fail until the 2nd pass.
The fix here is to eliminate the use of
useEffect
for setting state. The internal state is only required when dragging because it's a temporary state held by the hook until the drag completes.How Has This Been Tested?
To ensure the error icon still renders, create two fields with the same env var value.
Test Impact
Tests already exist for testing drag.
Request review criteria:
Self checklist (all need to be checked):
If you have UI changes:
After the PR is posted & before it merges:
main