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(clerk-react): Re-render <UserButton /> when <UserButton /> props change #5069

Conversation

nikospapcom
Copy link
Member

Description

In this pr we re-render the <UserButton /> component when the props are changing
e.g.
Before this change the following example didn't work, the label was always Chat is OFF

 <UserButton>
    <UserButton.MenuItems>
      <UserButton.Action
        label={`Chat is ${open ? 'ON' : 'OFF'}`}
        labelIcon={<DotIcon />}
        onClick={() => setIsOpen(!open)}
      />
    </UserButton.MenuItems>
  </UserButton>

Now the <UserButton /> appropriate

Screen.Recording.2025-02-03.at.11.54.28.AM.mov

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

@nikospapcom nikospapcom self-assigned this Feb 3, 2025
Copy link

vercel bot commented Feb 3, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 5, 2025 0:59am

Copy link

changeset-bot bot commented Feb 3, 2025

🦋 Changeset detected

Latest commit: 530c4c6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@clerk/clerk-react Patch
@clerk/chrome-extension Patch
@clerk/elements Patch
@clerk/clerk-expo Patch
@clerk/nextjs Patch
@clerk/react-router Patch
@clerk/remix Patch
@clerk/tanstack-start Patch
@clerk/ui Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@nikospapcom nikospapcom changed the title chore: Re-render <UserButton /> when <UserButton /> props change chore(clerk-react): Re-render <UserButton /> when <UserButton /> props change Feb 3, 2025
@clerk clerk deleted a comment from clerk-cookie Feb 3, 2025
@nikospapcom nikospapcom force-pushed the nikospap/user-1160-userbutton-dont-re-render-when-a-state-out-of-it-change branch from e49d43c to b415b79 Compare February 3, 2025 11:06
@clerk clerk deleted a comment from clerk-cookie Feb 3, 2025
@nikospapcom
Copy link
Member Author

!snapshot

@clerk-cookie
Copy link
Collaborator

Hey @nikospapcom - the snapshot version command generated the following package versions:

Package Version
@clerk/astro 2.1.18-snapshot.v20250203110826
@clerk/backend 1.23.10-snapshot.v20250203110826
@clerk/chrome-extension 2.2.4-snapshot.v20250203110826
@clerk/clerk-js 5.50.2-snapshot.v20250203110826
@clerk/elements 0.22.18-snapshot.v20250203110826
@clerk/clerk-expo 2.7.2-snapshot.v20250203110826
@clerk/expo-passkeys 0.1.17-snapshot.v20250203110826
@clerk/express 1.3.45-snapshot.v20250203110826
@clerk/fastify 2.1.18-snapshot.v20250203110826
@clerk/nextjs 6.10.5-snapshot.v20250203110826
@clerk/nuxt 1.0.14-snapshot.v20250203110826
@clerk/clerk-react 5.22.9-snapshot.v20250203110826
@clerk/react-router 1.0.4-snapshot.v20250203110826
@clerk/remix 4.4.20-snapshot.v20250203110826
@clerk/shared 2.20.17-snapshot.v20250203110826
@clerk/tanstack-start 0.9.1-snapshot.v20250203110826
@clerk/testing 1.4.18-snapshot.v20250203110826
@clerk/ui 0.3.19-snapshot.v20250203110826
@clerk/vue 1.1.9-snapshot.v20250203110826

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/astro

npm i @clerk/astro@2.1.18-snapshot.v20250203110826 --save-exact

@clerk/backend

npm i @clerk/backend@1.23.10-snapshot.v20250203110826 --save-exact

@clerk/chrome-extension

npm i @clerk/chrome-extension@2.2.4-snapshot.v20250203110826 --save-exact

@clerk/clerk-js

npm i @clerk/clerk-js@5.50.2-snapshot.v20250203110826 --save-exact

@clerk/elements

npm i @clerk/elements@0.22.18-snapshot.v20250203110826 --save-exact

@clerk/clerk-expo

npm i @clerk/clerk-expo@2.7.2-snapshot.v20250203110826 --save-exact

@clerk/expo-passkeys

npm i @clerk/expo-passkeys@0.1.17-snapshot.v20250203110826 --save-exact

@clerk/express

npm i @clerk/express@1.3.45-snapshot.v20250203110826 --save-exact

@clerk/fastify

npm i @clerk/fastify@2.1.18-snapshot.v20250203110826 --save-exact

@clerk/nextjs

npm i @clerk/nextjs@6.10.5-snapshot.v20250203110826 --save-exact

@clerk/nuxt

npm i @clerk/nuxt@1.0.14-snapshot.v20250203110826 --save-exact

@clerk/clerk-react

npm i @clerk/clerk-react@5.22.9-snapshot.v20250203110826 --save-exact

@clerk/react-router

npm i @clerk/react-router@1.0.4-snapshot.v20250203110826 --save-exact

@clerk/remix

npm i @clerk/remix@4.4.20-snapshot.v20250203110826 --save-exact

@clerk/shared

npm i @clerk/shared@2.20.17-snapshot.v20250203110826 --save-exact

@clerk/tanstack-start

npm i @clerk/tanstack-start@0.9.1-snapshot.v20250203110826 --save-exact

@clerk/testing

npm i @clerk/testing@1.4.18-snapshot.v20250203110826 --save-exact

@clerk/ui

npm i @clerk/ui@0.3.19-snapshot.v20250203110826 --save-exact

@clerk/vue

npm i @clerk/vue@1.1.9-snapshot.v20250203110826 --save-exact

@nikospapcom nikospapcom marked this pull request as ready for review February 3, 2025 11:12
@nikospapcom nikospapcom requested a review from brkalow February 3, 2025 11:12
@nikospapcom nikospapcom assigned octoper and anagstef and unassigned octoper and anagstef Feb 3, 2025
@nikospapcom nikospapcom changed the title chore(clerk-react): Re-render <UserButton /> when <UserButton /> props change fix(clerk-react): Re-render <UserButton /> when <UserButton /> props change Feb 3, 2025
@panteliselef
Copy link
Member

@nikospapcom can you add e2e tests that show case the behaviour ?

@alexcarpenter
Copy link
Member

Do you think it'll be confusing that this only works in UserButton and not on our other components.

const prevProps = without(_prevProps.props, 'customPages', 'customMenuItems', 'children');
const newProps = without(this.props.props, 'customPages', 'customMenuItems', 'children');
// and the implementation of customPages relies on props getting new references
const prevProps = without(_prevProps.props, 'customPages', 'children');
Copy link
Member

Choose a reason for hiding this comment

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

❓ Have we checked if this causes infinite re-renders?

Copy link
Member Author

@nikospapcom nikospapcom Feb 5, 2025

Choose a reason for hiding this comment

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

@octoper yes I checked different scenarios and I didn't saw any re-render in <UserButton />, <UserProfile /> or <OrganizationProfile />

@nikospapcom
Copy link
Member Author

Do you think it'll be confusing that this only works in UserButton and not on our other components.

What do you mean this only works in UserButton?

@nikospapcom nikospapcom force-pushed the nikospap/user-1160-userbutton-dont-re-render-when-a-state-out-of-it-change branch from 0120183 to 530c4c6 Compare February 5, 2025 12:57
@nikospapcom nikospapcom merged commit 0fa449c into main Feb 5, 2025
29 checks passed
@nikospapcom nikospapcom deleted the nikospap/user-1160-userbutton-dont-re-render-when-a-state-out-of-it-change branch February 5, 2025 13:41
wobsoriano pushed a commit that referenced this pull request Feb 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants