fix(components): [cascader] prevent duplicate root lazy-load calls#24269
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughCascaderPanel's lazy root node loading function now includes an additional guard to exit early when the initial load is not yet complete, preventing concurrent invocations. A test case validates this behavior by confirming that toggling the popper during a pending load does not re-trigger the lazy load callback. ChangesLazy Load Race Condition Fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
|
Size Change: +16 B (0%) Total Size: 1.44 MB 📦 View Changed
ℹ️ View Unchanged
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/components/cascader-panel/__tests__/cascader-panel.test.tsx (1)
602-631: ⚡ Quick winWell-written test that correctly validates the lazy-load race condition fix.
The test properly verifies that
loadLazyRootNodes()prevents duplicatelazyLoadinvocations both during the pending state and after completion. The use of fake timers and clear assertions makes the test easy to understand and maintain.Optional enhancement: Verify loaded state after timer completion
Consider adding an assertion after line 627 to verify that the nodes were actually loaded before the final reload attempt. This would make the test more robust:
vi.runAllTimers() await nextTick() +const nodes = wrapper.findAll(NODE) +expect(nodes.length).toBe(1) vm.loadLazyRootNodes() expect(lazyLoad).toHaveBeenCalledTimes(1)This ensures the component reached the expected "loaded" state before testing the post-load behavior.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/components/cascader-panel/__tests__/cascader-panel.test.tsx` around lines 602 - 631, Add a post-timer assertion to confirm the lazy nodes were actually loaded before the final reload attempt: after vi.runAllTimers() and await nextTick(), assert the component state (e.g., check vm.rootNodes or wrapper.findComponent(CascaderPanel).vm data that stores loaded nodes, or verify the rendered node with value 'loaded') to ensure the lazyLoad resolution took effect prior to calling vm.loadLazyRootNodes() and the final expect(lazyLoad).toHaveBeenCalledTimes(1).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/components/cascader-panel/__tests__/cascader-panel.test.tsx`:
- Around line 602-631: Add a post-timer assertion to confirm the lazy nodes were
actually loaded before the final reload attempt: after vi.runAllTimers() and
await nextTick(), assert the component state (e.g., check vm.rootNodes or
wrapper.findComponent(CascaderPanel).vm data that stores loaded nodes, or verify
the rendered node with value 'loaded') to ensure the lazyLoad resolution took
effect prior to calling vm.loadLazyRootNodes() and the final
expect(lazyLoad).toHaveBeenCalledTimes(1).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f093b720-ef5b-4598-b0d7-82404ef17b6f
📒 Files selected for processing (2)
packages/components/cascader-panel/__tests__/cascader-panel.test.tsxpackages/components/cascader-panel/src/index.vue
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||
|
🧪 Playground Preview: https://element-plus.run/?pr=24269 |
|
@rzzf Thanks for your contribution! ❤️ |

Please make sure these boxes are checked before submitting your PR, thank you!
devbranch.When
lazyLoadis first triggered by theconfigwatcher and has not yet been resolved, opening the panel will triggerlazyLoadagain.repro
Summary by CodeRabbit
Bug Fixes
Tests