-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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(@vben-core/menu-ui): fix horizontal layout top menu language switching issue(#4724) #4777
Conversation
|
WalkthroughThe changes in the Changes
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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 (
|
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: 0
🧹 Outside diff range and nitpick comments (1)
packages/@core/ui-kit/menu-ui/src/components/menu.vue (1)
75-77
: Translate comment to English for consistency.The Chinese comment "更新插槽内容" should be translated to English.
- // 更新插槽内容 + // Update slot content
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
packages/@core/ui-kit/menu-ui/src/components/menu.vue
(1 hunks)
🔇 Additional comments (2)
packages/@core/ui-kit/menu-ui/src/components/menu.vue (2)
Line range hint 75-91
: Implementation successfully fixes the language switching issue.
The computed property getSlot
correctly handles the menu items by:
- Updating slot content when
sliceIndex
changes - Properly splitting items between default view and more menu
- Maintaining reactivity for language switching
Line range hint 75-91
: Verify slot cleanup and edge cases.
Please ensure:
- Slots are properly cleaned up when components are destroyed
- The solution handles edge cases like:
- Empty slots
- Rapid language switching
- Dynamic content updates
✅ Verification successful
Let me gather more specific information about the menu component's implementation and test coverage.
Let me check the component's implementation for any potential memory leaks or cleanup patterns.
Based on the analysis of the code, I can now provide the final response:
Slot handling implementation is safe and properly managed
The implementation is well-designed and handles cleanup appropriately:
- Slot content is managed through Vue's reactive system using
computed
properties, which automatically handle cleanup - The component properly handles resize cleanup through
resizeStopper?.()
when mode changes - Edge cases are properly handled:
- Empty slots:
slots.default?.() ?? []
- Dynamic updates: Handled through Vue's reactivity
- Content switching: Managed via
sliceIndex
computed value
- Empty slots:
The concerns raised in the review comment are already addressed by the existing implementation.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for memory leak prevention patterns in component lifecycle hooks
ast-grep --pattern 'onBeforeUnmount($$$)' || ast-grep --pattern 'onUnmounted($$$)'
# Look for existing test cases covering edge cases
rg -l "test|spec|describe.*menu.*language" -g "*.{spec,test}.{ts,js,vue}"
Length of output: 2903
Script:
#!/bin/bash
# Check for slot-related cleanup in the menu component
rg -A 5 "slots?.default|originalSlot|slotMore" packages/@core/ui-kit/menu-ui/src/components/menu.vue
# Look for menu component tests
fd -g "*menu*.{spec,test}.{ts,js,vue}" packages/@core/ui-kit/menu-ui/
# Check for watch cleanup patterns
ast-grep --pattern 'watch($$$, {
$$$
immediate: $_
})'
Length of output: 29217
Script:
#!/bin/bash
# Check the menu component's implementation for computed properties and cleanup
rg -A 10 "computed|watch" packages/@core/ui-kit/menu-ui/src/components/menu.vue
# Look for slot handling and cleanup patterns
ast-grep --pattern 'const $_ = computed(() => {
$$$
const $_ = slots.default?.()
$$$
})'
Length of output: 2555
…ching issue(vbenjs#4724) (vbenjs#4777) Co-authored-by: jackhoo_98 <[email protected]>
…ching issue(#4724)
Description
复现步骤:
原因:

sliceIndex.value变化时,defaultSlots未及时更新,拿到的是旧插槽
解决:
因为getSlot计算属性是依赖sliceIndex.value变化时更新,所以在更新getSlot时,重新执行slots.default?.()拿到新插槽内容
Type of change
Please delete options that are not relevant.
pnpm-lock.yaml
unless you introduce a new test example.Checklist
pnpm run docs:dev
command.pnpm test
.feat:
,fix:
,perf:
,docs:
, orchore:
.Summary by CodeRabbit
New Features
Bug Fixes
Documentation