bito-code-review[bot] commented on code in PR #40292:
URL: https://github.com/apache/superset/pull/40292#discussion_r4151871630
##########
superset-frontend/src/components/ErrorMessage/OAuth2RedirectMessage.tsx:
##########
@@ -106,21 +106,60 @@ export function OAuth2RedirectMessage({
const dispatch = useDispatch();
const lastHandledTabIdRef = useRef<string>();
+ // `chartList` is rebuilt from `Object.keys` on every store update; keeping
+ // the listener state in a ref avoids tearing down/recreating the
+ // BroadcastChannel on each render and the race window that comes with it.
+ const latestStateRef = useRef({
+ source,
+ query,
+ chartId,
+ chartList,
+ dashboardId,
+ errorMitigationFunction,
+ });
+ latestStateRef.current = {
+ source,
+ query,
+ chartId,
+ chartList,
+ dashboardId,
+ errorMitigationFunction,
+ };
Review Comment:
<!-- Bito Reply -->
The reviewer's concern regarding stale state is addressed by the fact that
`latestStateRef.current` is updated on every render, ensuring that
`handleOAuthComplete` always accesses the most recent values. Since the ref is
updated outside the effect, the effect does not need to re-subscribe to
maintain access to the latest state. This pattern is a standard approach for
avoiding unnecessary effect re-runs while maintaining access to current
component state.
**superset-frontend/src/components/ErrorMessage/OAuth2RedirectMessage.tsx**
```
latestStateRef.current = {
source,
query,
chartId,
chartList,
dashboardId,
errorMitigationFunction,
};
```
--
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]