Fix es_ui_shared eslint violations for useRequest hook#59626
Fix es_ui_shared eslint violations for useRequest hook#59626cjcenizal wants to merge 5 commits intoelastic:masterfrom
Conversation
|
Pinging @elastic/es-ui (Team:Elasticsearch UI) |
2fd8696 to
29ba8b5
Compare
5af8709 to
9914f70
Compare
walterra
left a comment
There was a problem hiding this comment.
Code LGTM, also tested a checkout, thanks for the update!
9914f70 to
1a58bc1
Compare
There was a problem hiding this comment.
I added this to handle the case when the owner component unmounts before a request has resolved.
|
@sebelga Could you please test Index Management, Watcher, and Snapshot Restore and see if you spot any bugs regarding requests? |
|
@elastic/ingest-management Could someone from your team please test the Ingest Manager and make sure I haven't introduced any buggy behavior on your end? |
jen-huang
left a comment
There was a problem hiding this comment.
Ran a smoke test of Ingest Manager locally and things are working as expected 👍
sebelga
left a comment
There was a problem hiding this comment.
LGTM! Tested locally watcher, IM, and S & R and did not spot any regression.
There was a problem hiding this comment.
Nit: isn't it the same as
pollIntervalIdRef.current = setTimeout(
sendRequestRef.current!,
pollIntervalMsRef.current
);There was a problem hiding this comment.
Can you explain why you created a ref here? I would have used useCallback for this purpose. Was it necessary to add the ref?
I see that sendRequestRef is also a ref. I think useCallback is better for this purpose. Maybe I'm missing something?
There was a problem hiding this comment.
I think switching to useCallback is an interesting idea and could yield optimization benefits by returning a memoized reference to sendRequest. It would look something like this, though I'm not sure about the implications of mutating a ref you're dependent upon (any risk of infinite loop?):
const scheduleRequest = useCallback(
() => {
// Clear current interval
if (pollIntervalIdRef.current) {
clearTimeout(pollIntervalIdRef.current);
}
// Set new interval
if (pollIntervalMsRef.current && isMounted.current) {
pollIntervalIdRef.current = setTimeout(
() => sendRequestRef.current!(),
pollIntervalMsRef.current
);
}
},
[pollIntervalIdRef.current, pollIntervalMsRef.current, isMounted.current, pollIntervalIdRef.current, sendRequestRef.current],
);However, the original NP-ready code uses refs and I find them easier to reason about than the useCallback example above, so I think I'll leave optimization to another day.
There was a problem hiding this comment.
Yeah, it would imply a bigger refactor (e.g. why do we have a ref for pollInterval?), but I agree we can leave that to another day. 👍
- Add clearer cleanup logic for unmounted components. - Align logic and comments in np_ready_request.ts and original request.ts.
2a52625 to
b0c309a
Compare
…o false during cleanups unrelated to unmounting.
b0c309a to
616d4a6
Compare
|
I just noticed a subtle change in the way return {
data: null,
error: e.response ? e.response : e,
};To this: return {
data: null,
error: e.response && e.response.data ? e.response.data : e.body,
};To find and fix any bugs means we'll need to look through the plugins which depend upon the old behavior (Snapshot Restore and Ingest Manager). @jen-huang Can you or someone from the Ingest team please audit Ingest Manager and make sure errors returned by |
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
|
This branch is too stale to continue on. Closing in favor of #72947 |
Partially addresses #49554
Closes #49572 (originally fixed as part of the NP migration)
Closes #49562 (originally fixed as part of the NP migration)
This PR:
request.tshelper and replaces it with the NP-ready versionAdds clean-up logic for when the component using this helper is unmounted(This was reverted)To test: