fix(components): [tree] respect check-strictly on lazy load#24267
Conversation
|
👋 @ruguoba, seems like this is your first time contribution to element-plus. |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughGuards Node's post-lazy-load checked-state actions so both ChangesLazy-loaded node checked-state handling under strict mode
Sequence Diagram(s)sequenceDiagram
participant User
participant Node
participant Store
participant CheckedInit
User->>Node: click parent checkbox
Node->>Store: read checkStrictly
Store-->>Node: return checkStrictly
Node->>Node: mark parent checked
Node->>Node: lazy load children
Node->>Store: on children loaded -> read checkStrictly
alt checkStrictly == false
Node->>CheckedInit: setChecked(true, true) / reInitChecked(this)
else checkStrictly == true
Node-->>CheckedInit: skip setChecked/reInitChecked
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
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 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: |
|
🧪 Playground Preview: https://element-plus.run/?pr=24267 |
There was a problem hiding this comment.
Actionable comments posted: 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.
Inline comments:
In `@packages/components/tree/__tests__/tree.test.ts`:
- Around line 2479-2486: Move the fake-timer setup so timers are controlled
before the async load is scheduled: call vi.useFakeTimers() prior to triggering
the click on nodeContent[0] (which causes the setTimeout in loadNode to be
scheduled), then trigger the click, call vi.runAllTimers(), vi.useRealTimers(),
and await nextTick(); also remove the redundant extra nextTick() to match the
established pattern used elsewhere in the test file.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 5dcd4707-f84e-4013-b694-e5f0fc1bb0f4
📒 Files selected for processing (1)
packages/components/tree/__tests__/tree.test.ts
|
Hi @rzzf, I've added test cases and fixed the timer issue in the test. All CI checks are passing. Could you please review again? Thanks! |
73b3dd0 to
c707da2
Compare
|
The latest requested change has been applied in c707da2. Local tree tests and lint pass on my side. The required workflows are currently awaiting maintainer approval to run. Could you please approve the workflow run when convenient? Thanks! |
|
@ruguoba Thanks for your contribution! ❤️ |

close #24255
What is the bug?
When using
el-treewithlazyloading andcheck-strictly: true, checking a parent node causes subsequently lazy-loaded child nodes to be automatically checked. Withcheck-strictlyenabled, parent and child check states should be independent.Root Cause
In
node.tsexpand()method, after lazy-loading children, the code checkedif (this.checked)and calledthis.setChecked(true, true)withdeep=truebefore checkingcheckStrictly. ThecheckStrictlyguard was only in theelsebranch.Fix
Restructured the conditions so
checkStrictlyis checked first. WhencheckStrictly: true, no check propagation happens after lazy load:All 73 existing tree component tests pass.
Summary by CodeRabbit
Bug Fixes
Tests