[Security solution] Fix side effects in useRefetchByRestartingSession#148591
[Security solution] Fix side effects in useRefetchByRestartingSession#148591stephmilovic wants to merge 10 commits intoelastic:mainfrom
useRefetchByRestartingSession#148591Conversation
| setSearchSessionId(session.current.start()); | ||
| const currentSession = session.current; | ||
| return () => { | ||
| data.search.session.clear(); |
There was a problem hiding this comment.
I updated this to use the session.current ref since its the only place we're not using the ref. I think it was done like this in the first place because of the following error:
ESLint: The ref value 'session.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy 'session.current' to a variable inside the effect, and use that variable in the cleanup function.(react-hooks/exhaustive-deps)
Thus the variable on L62
| currentSession.clear(); | ||
| }; | ||
| }); | ||
| }, []); |
There was a problem hiding this comment.
react wants empty dependency argument now that we're using a setState call in the effect
|
Pinging @elastic/security-threat-hunting (Team:Threat Hunting) |
|
Pinging @elastic/security-solution (Team: SecuritySolution) |
| indexNames, | ||
| startDate: from, | ||
| skip: querySkip, | ||
| skip: querySkip || isChartEmbeddablesEnabled, |
There was a problem hiding this comment.
I happened to notice this was the only chart embeddables query without this condition, I think this is correct??
There was a problem hiding this comment.
Thanks for adding the check!
|
@elasticmachine merge upstream |
💔 Build FailedFailed CI Steps
Test Failures
Metrics [docs]Async chunks
History
To update your PR or re-run it, just comment with: |
jamster10
left a comment
There was a problem hiding this comment.
Good solution, thank you!
|
closing in favor of #148552 |
Summary
I noticed the below console error on the network page and tracked it down to the
searchSessionIdvariable inuseRefetchByRestartingSessionwhich was previously stored in auseMemo. The hook callsdata.search.session.start()which returns theid. However, this call was running before the component was mounted and react did not like it, resulting in the error. Fixed by storing the id inuseStateand updating the state with thestart()call once the component is mountedI also moved this hook to be in
public/explorein accordance with #147298