Skip to content
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

Merged
merged 3 commits into from
Sep 3, 2024

Conversation

LetItRock
Copy link
Contributor

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

@@ -75,13 +79,14 @@ export const Renderer = (props: RendererProps) => {
<FocusManagerProvider>
<InboxProvider tabs={props.tabs}>
<CountProvider>
<For each={[...props.nodes]}>
{([node, component]) => {
<For each={nodes()}>
Copy link
Contributor Author

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)!);
Copy link
Contributor Author

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);
Copy link
Contributor Author

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.

Copy link
Contributor

@SokratisVidros SokratisVidros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

Copy link
Contributor

@desiprisg desiprisg left a 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!

@LetItRock LetItRock merged commit 93e2ff5 into next Sep 3, 2024
21 checks passed
@LetItRock LetItRock deleted the com-199-fix-inbox-notifications-component-remount branch September 3, 2024 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants