-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
refactor: migrate Ant Design notifications to use App.useApp() cont…
#20549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
08a6fe2
eee37c5
a48a8ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| "use client"; | ||
|
|
||
| import React, { useEffect } from "react"; | ||
| import { App } from "antd"; | ||
| import { setNotificationInstance } from "@/components/molecules/notifications_manager"; | ||
|
|
||
| // Inner component to use the hook | ||
| const AntdAppInit = () => { | ||
| const { notification } = App.useApp(); | ||
|
|
||
| useEffect(() => { | ||
| setNotificationInstance(notification); | ||
| }, [notification]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Effect runs every render
Prompt To Fix With AIThis is a comment left during a code review.
Path: ui/litellm-dashboard/src/contexts/AntdGlobalProvider.tsx
Line: 8:13
Comment:
**Effect runs every render**
`useEffect(() => setNotificationInstance(notification), [notification])` will re-run whenever `App.useApp()` returns a new `notification` object reference. If the hook returns a new object each render (implementation-dependent), this can cause repeated global writes and potential notification instance churn. Consider ensuring the instance is stable (e.g., only set once on mount) or guard against redundant sets.
How can I resolve this? If you propose a fix, please make it concise. |
||
|
|
||
| return null; | ||
| }; | ||
|
|
||
| export default function AntdGlobalProvider({ children }: { children: React.ReactNode }) { | ||
| return ( | ||
| <App> | ||
| <AntdAppInit /> | ||
| {children} | ||
| </App> | ||
| ); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Global mutable instance
notificationInstanceis a module-level mutable singleton that gets set bysetNotificationInstance()and then used bygetNotification(). In Next.js/React this can lead to cross-request/user bleed in SSR/hydration scenarios (the module is shared), and also makes notification behavior depend on mount order (calls beforeAntdAppInitruns will silently use the static API). A safer pattern is to keep notifications entirely context-driven (or pass the instance explicitly) rather than storing it in a global variable.Prompt To Fix With AI