Skip to content

Conversation

@stanca-pop-lgp
Copy link
Contributor

@stanca-pop-lgp stanca-pop-lgp commented May 17, 2022

Enact-DCO-1.0-Signed-off-by: Stanca Pop [email protected]

Checklist

  • I have read and understand the contribution guide
  • A CHANGELOG entry is included
  • At least one test case is included for this feature or bug fix
  • Documentation was added or is not needed
  • This is an API breaking change

Issue Resolved / Feature Added

There are many local functions in custom Hooks of VirtualList and Scroller. When calling those custom Hooks, the functions are re-defined if those functions are not wrapped with useCallback. That would make JavaScript performance lower. By wrapping those functions with useCallback, we could prevent redefining them again if those functions's dependencies are not changed.

Resolution

Wrapped the local functions in useScroll with "useCallback" and reordered them to be called after being defined.

Additional Considerations

Links

WRO-582

Comments

@codecov
Copy link

codecov bot commented May 17, 2022

Codecov Report

Merging #1247 (dffe1a5) into develop (f7d8f06) will decrease coverage by 0.42%.
The diff coverage is 93.75%.

@@             Coverage Diff             @@
##           develop    #1247      +/-   ##
===========================================
- Coverage    54.42%   54.00%   -0.43%     
===========================================
  Files          136      136              
  Lines         6539     6653     +114     
  Branches      1915     1969      +54     
===========================================
+ Hits          3559     3593      +34     
- Misses        2328     2367      +39     
- Partials       652      693      +41     
Impacted Files Coverage Δ
useScroll/useScroll.js 76.87% <93.75%> (+2.72%) ⬆️
Input/InputFieldSpotlightDecorator.js 77.43% <0.00%> (-1.42%) ⬇️
Scroller/EditableWrapper.js 2.52% <0.00%> (+0.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 650ef5c...dffe1a5. Read the comment docs.

Copy link
Contributor

@alexandrumorariu alexandrumorariu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

contextSharedState.set(`${id}.scrollPosition`, {x, y});
}
}
}, [contextSharedState, props]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

props is always a new object, so props.id would be the right dep. It looks missing by accident. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, true. But if I add props.id I get this warning:
226:5 warning React Hook useCallback has a missing dependency: 'props'. Either include it or remove the dependency array react-hooks/exhaustive-deps

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. It could be okay in this line if we define id as destructed variable from props, but it looks unclear what impact this way may have. I'll look into this.

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.

4 participants