Data: Remove unused forceRender argument #19206
Merged
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.
This pull request seeks to remove an unused argument in the implementation of
useSelect
. When a change is detected in the result of amapSelect
callback, the hook will force a render using its internalforceRender
reducer. SinceforceRender
is implemented using auseReducer
which will always yield a new value and never considers the incoming argument, the empty object we currently pass is unused.gutenberg/packages/data/src/components/use-select/index.js
Line 82 in 7a337cf
In theory, the previous implementation could cause memory accumulation and/or extra load on garbage collection due to the initialization and subsequent destruction of the unused object references. The expected impact of this is not significant, but since this is a hot code path, it is worth the extra attention.
I expect this could have been lingering code from an earlier iteration of the hook, considering that this pattern is often used when forcing a render using the
setState
callback of auseState
hook (wheresetState( {} )
is equally as effective at forcing a render).Testing Instructions:
Ensure unit tests pass: