[Lens] Embeddable entering loading state when component re-renders #203020
Labels
bug
Fixes for quality problems that affect the customer experience
Feature:Lens
project:embeddableRebuild
regression
Team:Visualizations
Visualization editors, elastic-charts and infrastructure
Describe the bug:
The Lens embeddable is unnecessarily entering a loading state via calling the
update
method on the expression loader via theuseUpdateEffect
hook in src/plugins/expressions/public/react_expression_renderer/use_expression_renderer.ts - this is because theexpressionParams
object is not being memoized properly before sending it in as a prop toExpressionWrapper
. Using an object as a dependancy to a hook strikes again! I think this is also being caused by the fact thatexpressionParams
isn't serializable - i.e. it contains functions, which don't have an easy comparison even viauseShallowMemo
.Steps to reproduce:
LensEmbeddableComponent
src/plugins/expressions/public/react_expression_renderer/use_expression_renderer.ts
) despite not loading anything 🔥Screen.Recording.2024-12-04.at.2.17.46.PM.mov
Expected behavior:
We should only enter a loading state when we actually have to refetch data.
Any additional context:
I found a hacky workaround via the following:
I created a hacky memoize that compares only the keys of two objects:
I used this hacked memoize for
expressionParams
in theLensEmbeddableComponent
:Which removes the loading state on view mode change because the keys of
expressionParams
being consistent stopsmemoizedExpressionParams
from referencing a new object every timeuseBatchedPublishingSubjects
updates:Screen.Recording.2024-12-04.at.2.29.34.PM.mov
The text was updated successfully, but these errors were encountered: