bito-code-review[bot] commented on code in PR #40915:
URL: https://github.com/apache/superset/pull/40915#discussion_r3384345590
##########
superset-frontend/src/core/menus/index.ts:
##########
@@ -77,6 +92,18 @@ 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);
+ },
+ () => undefined,
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>useSyncExternalStore hydration mismatch</b></div>
<div id="fix">
The added `() => undefined` as `getServerSnapshot` causes a hydration
mismatch: server returns `undefined` while the client `getSnapshot` returns a
`Menu` object. Per React docs, omit this argument when no server value is
meaningful, or return the same value as `getSnapshot`.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
```
--- a/superset-frontend/src/core/menus/index.ts
+++ b/superset-frontend/src/core/menus/index.ts
@@ -95,11 +95,10 @@ export const useMenu = (location: string): Menu |
undefined =>
useSyncExternalStore(
subscribe,
() => {
if (!menuCache.has(location)) {
menuCache.set(location, getMenu(location));
}
return menuCache.get(location);
- },
- () => undefined,
- );
+ },
+ );
```
</div>
</details>
</div>
<small><i>Code Review Run #d1e15d</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]