EnxDev commented on code in PR #45541:
URL: https://github.com/apache/superset/pull/45541#discussion_r4353595309


##########
superset-frontend/src/components/Chart/Chart.tsx:
##########
@@ -221,6 +221,29 @@ function Chart({
   // Update on each render to accurately track render duration
   renderStartTimeRef.current = Logger.getTimestamp();
 
+  // The form data the response in the store was queried with. A filter change
+  // updates formData as soon as the new query starts, so a chart kept on 
screen
+  // draws the previous response with its own form data until the new one
+  // lands. This lives here rather than in ChartRenderer, which unmounts while 
a
+  // virtualized chart is out of view. A chart mounted while its query is
+  // already in flight can't tell which form data that response belongs to.
+  // A response that failed to render keeps no form data either: drawn again
+  // while the retry is in flight, it would fail the same way.
+  const responseFormDataRef = useRef<{
+    queriesResponse: typeof queriesResponse;
+    formData: QueryFormData | undefined;
+  }>({
+    queriesResponse,
+    formData: chartStatus === 'loading' ? undefined : formData,
+  });
+  if (responseFormDataRef.current.queriesResponse !== queriesResponse) {
+    responseFormDataRef.current = { queriesResponse, formData };

Review Comment:
   Yes, that happens. The dashboard merges its colour settings into each 
chart's form data, and a scheme change doesn't run a query, so the snapshot 
still had the old scheme. The snapshot can't just follow `formData` while the 
chart isn't loading: a filter change updates `formData` one render before 
`Dashboard` triggers the query, and that would pair the old rows with the new 
filters again. So `ChartRenderer` keeps the retained form data for the query 
and takes the dashboard colour keys (`color_scheme`, `own_color_scheme`, 
`label_colors`, `shared_label_colors`, `map_label_colors`) from the current 
form data. The test is `draws the previous data with the current dashboard 
colour scheme` in `ChartRenderer.refresh.test.tsx`. It changes the scheme 
without querying and then refreshes. Fixed in d907074.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to