-
Notifications
You must be signed in to change notification settings - Fork 419
fix(clerk-react): Resolve dynamic menu items losing icons #6443
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
Conversation
🦋 Changeset detectedLatest commit: 4c77325 The changes in this PR will be included in the next version bump. This PR includes changesets to release 8 packages
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 |
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
📝 Walkthrough""" WalkthroughThis change set introduces a patch update to the "@clerk/clerk-react" package that fixes an issue where dynamic menu items lost their icons. A new React component ( Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15–20 minutes
Assessment against linked issues
Assessment against linked issues: Out-of-scope changesNo out-of-scope changes found. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/elements
@clerk/clerk-expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/clerk-react
@clerk/react-router
@clerk/remix
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/themes
@clerk/types
@clerk/upgrade
@clerk/vue
commit: |
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
.changeset/soft-jeans-pretend.md(1 hunks)integration/templates/react-vite/src/custom-user-button/with-dynamic-items.tsx(1 hunks)integration/templates/react-vite/src/main.tsx(2 hunks)integration/tests/custom-pages.test.ts(2 hunks)packages/react/src/utils/useCustomElementPortal.tsx(1 hunks)
🧰 Additional context used
📓 Path-based instructions (13)
.changeset/**
📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)
Automated releases must use Changesets.
Files:
.changeset/soft-jeans-pretend.md
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
integration/templates/react-vite/src/custom-user-button/with-dynamic-items.tsxpackages/react/src/utils/useCustomElementPortal.tsxintegration/templates/react-vite/src/main.tsxintegration/tests/custom-pages.test.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
integration/templates/react-vite/src/custom-user-button/with-dynamic-items.tsxpackages/react/src/utils/useCustomElementPortal.tsxintegration/templates/react-vite/src/main.tsxintegration/tests/custom-pages.test.ts
**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Preferreadonlyfor properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertionsfor literal types:as const
Usesatisfiesoperator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noanytypes without justification
Proper error handling with typed errors
Consistent use ofreadonlyfor immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
integration/templates/react-vite/src/custom-user-button/with-dynamic-items.tsxpackages/react/src/utils/useCustomElementPortal.tsxintegration/templates/react-vite/src/main.tsxintegration/tests/custom-pages.test.ts
**/*.{jsx,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
**/*.{jsx,tsx}: Use error boundaries in React components
Minimize re-renders in React components
**/*.{jsx,tsx}: Always use functional components with hooks instead of class components
Follow PascalCase naming for components:UserProfile,NavigationMenu
Keep components focused on a single responsibility - split large components
Limit component size to 150-200 lines; extract logic into custom hooks
Use composition over inheritance - prefer smaller, composable components
Export components as named exports for better tree-shaking
One component per file with matching filename and component name
Use useState for simple state management
Use useReducer for complex state logic
Implement proper state initialization
Use proper state updates with callbacks
Implement proper state cleanup
Use Context API for theme/authentication
Implement proper state selectors
Use proper state normalization
Implement proper state persistence
Use React.memo for expensive components
Implement proper useCallback for handlers
Use proper useMemo for expensive computations
Implement proper virtualization for lists
Use proper code splitting with React.lazy
Implement proper cleanup in useEffect
Use proper refs for DOM access
Implement proper event listener cleanup
Use proper abort controllers for fetch
Implement proper subscription cleanup
Use proper HTML elements
Implement proper ARIA attributes
Use proper heading hierarchy
Implement proper form labels
Use proper button types
Implement proper focus management
Use proper keyboard shortcuts
Implement proper tab order
Use proper skip links
Implement proper focus traps
Implement proper error boundaries
Use proper error logging
Implement proper error recovery
Use proper error messages
Implement proper error fallbacks
Use proper form validation
Implement proper error states
Use proper error messages
Implement proper form submission
Use proper form reset
Use proper component naming
Implement proper file naming
Use proper prop naming
Implement proper...
Files:
integration/templates/react-vite/src/custom-user-button/with-dynamic-items.tsxpackages/react/src/utils/useCustomElementPortal.tsxintegration/templates/react-vite/src/main.tsx
integration/**
📄 CodeRabbit Inference Engine (.cursor/rules/global.mdc)
Framework integration templates and E2E tests should be placed under the integration/ directory
Files:
integration/templates/react-vite/src/custom-user-button/with-dynamic-items.tsxintegration/templates/react-vite/src/main.tsxintegration/tests/custom-pages.test.ts
integration/**/*
📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)
End-to-end tests and integration templates must be located in the 'integration/' directory.
Files:
integration/templates/react-vite/src/custom-user-button/with-dynamic-items.tsxintegration/templates/react-vite/src/main.tsxintegration/tests/custom-pages.test.ts
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)
Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.
Files:
integration/templates/react-vite/src/custom-user-button/with-dynamic-items.tsxpackages/react/src/utils/useCustomElementPortal.tsxintegration/templates/react-vite/src/main.tsxintegration/tests/custom-pages.test.ts
**/*.tsx
📄 CodeRabbit Inference Engine (.cursor/rules/react.mdc)
**/*.tsx: Use proper type definitions for props and state
Leverage TypeScript's type inference where possible
Use proper event types for handlers
Implement proper generic types for reusable components
Use proper type guards for conditional rendering
Files:
integration/templates/react-vite/src/custom-user-button/with-dynamic-items.tsxpackages/react/src/utils/useCustomElementPortal.tsxintegration/templates/react-vite/src/main.tsx
**/*
⚙️ CodeRabbit Configuration File
**/*: If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.Whenever reviewing a pull request, if there are any changes that could impact security, always tag
@clerk/securityin the PR.Security-impacting changes include, but are not limited to:
- Changes to authentication logic or mechanisms (e.g. login, session handling, token issuance)
- Any modification to access control, authorization checks, or role-based permissions
- Introduction or modification of hashing algorithms, signature verification, or cryptographic primitives
- Handling of sensitive data (e.g. passwords, tokens, secrets, PII)
- Integration with external identity providers (e.g. SSO, OAuth, OpenID Connect)
- Modifications to security headers, cookie flags, CORS policies, or CSRF protections
- Bypass mechanisms (e.g. feature flags, testing overrides) that could weaken protections
- Changes to rate limiting, abuse prevention, or input validation
If you're unsure whether a change is security-relevant, err on the side of caution and tag
@clerk/security.Any time that you tag
@clerk/security, please do so explicitly in a code comment, rather than within a collapsed section in a coderabbit comment, such as the "recent review details" section. If you do use the team name in any thinking or non-direct-code-comment content, it can be referred to as "clerk security team" to avoid accidentally printing the tag which sends a notification to the team.
Files:
integration/templates/react-vite/src/custom-user-button/with-dynamic-items.tsxpackages/react/src/utils/useCustomElementPortal.tsxintegration/templates/react-vite/src/main.tsxintegration/tests/custom-pages.test.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/react/src/utils/useCustomElementPortal.tsx
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/react/src/utils/useCustomElementPortal.tsx
integration/**/*.{test,spec}.{js,ts}
📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)
Integration tests should use Playwright.
Files:
integration/tests/custom-pages.test.ts
🧬 Code Graph Analysis (2)
integration/templates/react-vite/src/custom-user-button/with-dynamic-items.tsx (1)
integration/templates/react-vite/src/custom-user-button/with-dynamic-label-and-custom-pages.tsx (1)
Page(5-68)
integration/tests/custom-pages.test.ts (1)
integration/testUtils/index.ts (1)
createTestUtils(24-86)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
- GitHub Check: Integration Tests (billing, chrome)
- GitHub Check: Integration Tests (nextjs, chrome, 15)
- GitHub Check: Integration Tests (express, chrome)
- GitHub Check: Integration Tests (expo-web, chrome)
- GitHub Check: Integration Tests (vue, chrome)
- GitHub Check: Integration Tests (react-router, chrome)
- GitHub Check: Integration Tests (nextjs, chrome, 14)
- GitHub Check: Integration Tests (localhost, chrome)
- GitHub Check: Integration Tests (nuxt, chrome)
- GitHub Check: Integration Tests (tanstack-react-router, chrome)
- GitHub Check: Integration Tests (sessions, chrome)
- GitHub Check: Integration Tests (quickstart, chrome)
- GitHub Check: Integration Tests (tanstack-react-start, chrome)
- GitHub Check: Integration Tests (elements, chrome)
- GitHub Check: Integration Tests (astro, chrome)
- GitHub Check: Integration Tests (ap-flows, chrome)
- GitHub Check: Integration Tests (generic, chrome)
- GitHub Check: Static analysis
- GitHub Check: Publish with pkg-pr-new
- GitHub Check: Unit Tests (22, **)
🔇 Additional comments (10)
.changeset/soft-jeans-pretend.md (1)
1-6: LGTM! Well-formatted changeset for the bug fix.The changeset properly documents the patch update to
@clerk/clerk-reactwith a clear description of the fix for dynamic menu items losing icons.integration/templates/react-vite/src/main.tsx (2)
16-16: LGTM! Proper import for the new dynamic items component.The import statement follows the established pattern and correctly imports the component that demonstrates dynamic menu item functionality.
87-90: LGTM! Route properly configured for the dynamic items demo.The new route follows the established pattern and provides access to the component that demonstrates the dynamic menu items fix.
packages/react/src/utils/useCustomElementPortal.tsx (3)
19-19: LGTM! Dynamic array initialization improves flexibility.Changing from a fixed-size array to an empty array that grows dynamically is a good improvement that supports variable numbers of portal elements.
23-33: LGTM! Safe dynamic array growth in mount function.The implementation properly ensures the array is large enough for the target index using a while loop, and uses immutable updates with the spread operator. This safely handles dynamic menu items that may be added at runtime.
34-42: LGTM! Bounds checking in unmount function.The unmount function correctly checks array bounds before accessing elements, preventing potential runtime errors when dealing with dynamically sized arrays.
integration/templates/react-vite/src/custom-user-button/with-dynamic-items.tsx (3)
1-4: LGTM! Proper imports following established patterns.The imports are correctly structured and follow the same pattern as other custom user button components in the codebase.
5-7: LGTM! Clean component declaration and state management.The component uses proper functional component syntax with React hooks for state management, following React best practices.
8-36: LGTM! Well-structured demonstration of dynamic menu items.The component effectively demonstrates the fix for dynamic menu items losing icons:
- Static menu item always rendered with icon (🌐)
- Dynamic items conditionally rendered with icons (🌍, 🌐)
- Toggle button allows testing the dynamic behavior
- Follows established patterns from other custom user button components
This serves as both a test case and demonstration of the resolved issue.
integration/tests/custom-pages.test.ts (1)
448-500: LGTM! Comprehensive test for dynamic menu items with icons.The test thoroughly validates the fix for dynamic menu items losing icons:
- Verifies initial state with only static item and its icon
- Tests toggling dynamic items on/off
- Confirms all items (static and dynamic) maintain their icons after toggling
- Uses proper Playwright testing patterns and assertions
- Follows established testing structure from other tests in the file
This provides excellent coverage for the bug fix, ensuring dynamic menu items preserve their icons correctly.
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.
Before this update, the useCustomElementPortal function initialized its internal nodes array with a fixed length based on the initial elements.length. When new elements were added dynamically, the array didn't expand, causing portal creation to fail for the new elements.
|
!snapshot |
|
Hey @alexcarpenter - the snapshot version command generated the following package versions:
Tip: Use the snippet copy button below to quickly install the required packages. npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact
npm i @clerk/[email protected] --save-exact |
Description
Fixes
useCustomElementPortalto handle portaled icons in dynamically added menu itemsResolves USER-2492
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Refactor