-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Lens] Make sure Lens does not reload unnecessarily #86092
Conversation
Pinging @elastic/kibana-app (Team:KibanaApp) |
@elasticmachine merge upstream |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related to this PR, instead of adding more code to the various React hooks in the ReactExpressionRenderer
component, can you debounce expressionLoaderOptions
(if I understand correctly, you want to debounce expressionLoaderOptions
) in an isolated way without integrating with the rest of the hooks? Maybe using a useDebounce
hook:
const expressionLoaderOptionsDebounced = useDebounce(expressionLoaderOptions, 1000);
Not related to this PR, I think the ReactExpressionRenderer
has become an unreadable spaghetti code of React hooks. I don't think we should be adding any more hook logic to that component, but instead think about how to remove all that React hook logic from there.
@streamich I started out with a solution of debouncing the loader options like you suggest, but it became much more complex than the current status of this PR because of the way the expression is used different than other loader options in a bunch of places (like the update api of the loader).
I agree with this - however this PR is meant to go into 7.11 to fix the existing bug, that's why I would like to keep it small. What do you think about going forward with a stopgap approach here to make it work for now and create a tech debt issue to clean up this component? As Lens is the only consumer of this component AFAIK I think it would make sense for the kibana app team to tackle this as part of the next fix-it-week. I would suggest the following structure (in this cleanup PR):
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
App Services change LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested the two behavior changes in Firefox. I am definitely on board with the bugfix to #85815, but I'm not sure that the debounce behavior change is an improvement over what we have on master. I'm approving because I don't feel strongly enough to block it, but here is the scenario I was thinking of:
On a slower cluster, users could be confused if they click a "loading" suggestion and then get a totally different chart than what they clicked on. This is happening on this PR, but not master, because you've removed the loading spinner. The loading spinner can prevent confusion in these cases.
It's up to you- would you like to split the bugfix and the behavior change?
const renderEditor = ( | ||
routeProps: RouteComponentProps<{ id?: string }>, | ||
editByValue?: boolean | ||
// const featureFlagConfig = await getByValueFeatureFlag(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented code
// const featureFlagConfig = await getByValueFeatureFlag(); |
@elasticmachine merge upstream |
@wylieconlon I see your point, but on master this (showing the loading icon instead of the previous chart) happened on time range changes, not on state changes. If the time range changes, I don't think we have a confusion problem on clicking the loading suggestion. I'd say let's restore the previous behavior and revisit this later. |
💚 Build SucceededMetrics [docs]Async chunks
Distributable file count
Page load bundle
History
To update your PR or re-run it, just comment with: |
Fixes #85815
This PR fixes the reload of the editor on URL change caused by changing the time range. This was caused by the
redirectTo
function getting re-created. Here, it is made sure theApp
component is only re-rendered if the saved object id or the initial input changes.This also has the side effect of not triggering the
loaded
event on every time range change (which is what happened before).Additional changes
Bonus fix because I noticed the problem: On time range change, the suggestions would reset to a loading icon instead of showing the current chart during loading and start executing immediately after change. Both of these things are undesirable - the main preview should reload first, only afterwards the suggestions should render and there should be no flickering loading icon.
Both of these things are caused by the
searchContext
changing when the user picks a different time range. This PR fixes it in two places - first in the suggestion panel (x-pack/plugins/lens/public/editor_frame_service/editor_frame/suggestion_panel.tsx
) by using a ref for the current context to make sure no new component is generated and second in the expression renderer component (src/plugins/expressions/public/react_expression_renderer.tsx
) by making sure thedebounce
parameter is respected for other expression loader options besides the expression itself.