bito-code-review[bot] commented on code in PR #40915:
URL: https://github.com/apache/superset/pull/40915#discussion_r3383302470
##########
superset-frontend/src/core/menus/index.ts:
##########
@@ -77,6 +92,14 @@ const getMenu: typeof menusApi.getMenu = (
return result;
};
+export const useMenu = (location: string): Menu | undefined =>
+ useSyncExternalStore(subscribe, () => {
+ if (!menuCache.has(location)) {
+ menuCache.set(location, getMenu(location));
+ }
+ return menuCache.get(location);
+ });
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Missing getServerSnapshot for SSR</b></div>
<div id="fix">
The `useSyncExternalStore(subscribe, getSnapshot)` call at line 96 is
missing the required third argument `getServerSnapshot`. React 18's
useSyncExternalStore throws in environments where server and client render
different snapshots (e.g., Next.js, Remix). The hook will also re-run on every
mount in SSR unless a stable server snapshot is provided. Pass `() =>
getMenu(location)` as the third argument to fix SSR hydration safety.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
```
--- superset-frontend/src/core/menus/index.ts
+++ superset-frontend/src/core/menus/index.ts
@@ -93,7 +93,8 @@ export const getMenu: typeof menusApi.getMenu = (
};
export const useMenu = (location: string): Menu | undefined =>
useSyncExternalStore(subscribe, () => {
if (!menuCache.has(location)) {
menuCache.set(location, getMenu(location));
}
return menuCache.get(location);
- });
+ }, () => getMenu(location));
```
</div>
</details>
</div>
<small><i>Code Review Run #23a437</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]