Skip to content

refactor(components): [table] remove unnecessary reactivity#23254

Merged
btea merged 6 commits into
element-plus:devfrom
vueWorker-x:table/useKeyRender
Dec 31, 2025
Merged

refactor(components): [table] remove unnecessary reactivity#23254
btea merged 6 commits into
element-plus:devfrom
vueWorker-x:table/useKeyRender

Conversation

@vueWorker-x
Copy link
Copy Markdown
Contributor

@vueWorker-x vueWorker-x commented Dec 30, 2025

Please make sure these boxes are checked before submitting your PR, thank you!

  • Make sure you follow contributing guide English | (中文 | Español | Français).
  • Make sure you are merging your commits to dev branch.
  • Add some descriptions and refer to relative issues for your PR.

If the MutationObserver class contains private properties marked with '#', using 'ref' will cause an error. Replace it with 'shallowRef' to avoid this error.

Summary by CodeRabbit

  • Chores
    • Simplified the table component’s DOM-observation logic to remove unnecessary reactivity, improving initialization and cleanup reliability and reducing lifecycle overhead.

✏️ Tip: You can customize this high-level summary in your review settings.

@pull-request-triage
Copy link
Copy Markdown

👋 @web3Worker-x, seems like this is your first time contribution to element-plus.
Please make sure that you have read our guidelines and code of conduct before making a contribution.

@pull-request-triage pull-request-triage Bot added 1st contribution Their very first contribution Needs Review labels Dec 30, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Dec 30, 2025

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 30, 2025

📝 Walkthrough

Walkthrough

Replaced a Vue ref-backed MutationObserver holder with a plain MutationObserver variable; removed the ref import. onMounted/onUnmounted usage remains; initialization, observe, and disconnect calls now use the direct variable. No public APIs changed.

Changes

Cohort / File(s) Summary
MutationObserver usage
packages/components/table/src/table/key-render-helper.ts
Removed ref import and reactive ref wrapper; declared `observer: MutationObserver

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I watch the branches, light and hale,

One quiet eye, no heavy tail,
Streamlined hops through tidy code,
A gentle fix along the road 🌿

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed The description follows the template structure with all checkboxes marked complete, but provides minimal detail about the actual implementation changes made.
Title check ✅ Passed The title accurately describes the main change: removing unnecessary reactivity (ref) from MutationObserver management in the table component's key-render helper.
✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Dec 31, 2025

Open in StackBlitz

pnpm add https://pkg.pr.new/element-plus/element-plus@23254
npm i https://pkg.pr.new/element-plus/element-plus@23254
yarn add https://pkg.pr.new/element-plus/[email protected]

commit: 9e557cb

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Dec 31, 2025

🧪 Playground Preview: https://element-plus.run/?pr=23254
Please comment the example via this playground if needed.

@rzzf
Copy link
Copy Markdown
Member

rzzf commented Dec 31, 2025

I’m not entirely clear about the scenario where this error occurs. Could you provide a simple reproducible example?

Also, I think @webfanzc solution looks good #23257 (comment), What do you think?

@vueWorker-x
Copy link
Copy Markdown
Contributor Author

I’m not entirely clear about the scenario where this error occurs. Could you provide a simple reproducible example?

Also, I think @webfanzc solution looks good #23257 (comment), What do you think?

Yes, we don't need to use reactive programming here; using regular variables will work better. I'll adjust it to regular variable mode.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a 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: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 415fb14 and cd61f85.

📒 Files selected for processing (1)
  • packages/components/table/src/table/key-render-helper.ts
🔇 Additional comments (3)
packages/components/table/src/table/key-render-helper.ts (3)

1-1: LGTM: Removed unnecessary ref import.

The removal of ref is appropriate since the observer is now managed as a plain variable, avoiding reactivity overhead and issues with MutationObserver's private properties.


8-18: LGTM: Observer initialization and usage pattern is correct.

The direct initialization and usage of the plain variable properly avoids Vue's reactivity system, which resolves the issue with MutationObserver's private properties. The observer is created and immediately used within the same function scope, ensuring safe access.


25-27: LGTM: Proper cleanup with optional chaining.

The cleanup logic correctly uses optional chaining to safely disconnect the observer, handling cases where the observer might not be initialized.

Comment thread packages/components/table/src/table/key-render-helper.ts Outdated
@rzzf
Copy link
Copy Markdown
Member

rzzf commented Dec 31, 2025

Could you provide a simple reproducible example?

@vueWorker-x
Copy link
Copy Markdown
Contributor Author

For example, if the class contains #msg, using ref will result in an error.

example link

@rzzf rzzf changed the title fix: table/useKeyRender Replace ref with shallowRef refactor(components): [table] remove unnecessary reactivity Dec 31, 2025
Copy link
Copy Markdown
Member

@rzzf rzzf left a comment

Choose a reason for hiding this comment

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

looks good to me! thank you!

@btea
Copy link
Copy Markdown
Member

btea commented Dec 31, 2025

It seems this problem still exists. 🤔

screenshot 截屏2025-12-31 17 15 36

@vueWorker-x
Copy link
Copy Markdown
Contributor Author

It seems this problem still exists. 🤔

screenshot

Uncomment below and it will work normally without using ref.

@webfanzc
Copy link
Copy Markdown

It seems this problem still exists. 🤔

screenshot
Please refer to the description of the PR I submitted: PR #23257 in element-plus/element-plus. This is the root cause of the commit.

@btea btea merged commit c40a2c1 into element-plus:dev Dec 31, 2025
17 of 18 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

@web3Worker-x Thanks for your contribution! ❤️

@element-bot element-bot mentioned this pull request Jan 9, 2026
3 tasks
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.

4 participants