-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
fix(js): inbox notifications component gets remounting when render notification prop changes #6429
fix(js): inbox notifications component gets remounting when render notification prop changes #6429
Conversation
@@ -75,13 +79,14 @@ export const Renderer = (props: RendererProps) => { | |||
<FocusManagerProvider> | |||
<InboxProvider tabs={props.tabs}> | |||
<CountProvider> | |||
<For each={[...props.nodes]}> | |||
{([node, component]) => { | |||
<For each={nodes()}> |
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.
The nodes aka DOM element refs don't change on re-render, so it's "safe" to use them in the For
component each
prop as the Solid is doing comparison based on refs when rendering DOM elements. This code will make sure that the corresponding Solid components won't remount on props change.
{([node, component]) => { | ||
<For each={nodes()}> | ||
{(node) => { | ||
const novuComponent = createMemo(() => props.nodes.get(node)!); |
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.
However, the Solid component props might change, which is why we should memoize it and update the signal when it has been changed.
|
||
export default function Home() { | ||
const [count, setCount] = useState(0); |
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.
This is the playground code to verify that the state changes are propagated but the Notifications
component doesn't get remounted.
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.
💯
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.
Looks good! Let's replace the memo in JSX with just an arrow function!
What changed? Why was the change needed?
Fixed the issue described in this ticket: https://linear.app/novu/issue/COM-199/the-inbox-notifications-component-gets-remounted-when
Screenshots
Screen.Recording.2024-09-02.at.18.45.44.mov