Skip to content

refactor(runtime-core): replace VueElement import with ComponentCustomElementInterface - #14348

Merged
edison1105 merged 2 commits into
mainfrom
edison/refactor/VueElement
Jan 22, 2026
Merged

edison1105 merged 2 commits into
mainfrom
edison/refactor/VueElement

Conversation

@edison1105

@edison1105 edison1105 commented Jan 22, 2026 •

Copy link
Copy Markdown
Member

Remove direct import of VueElement from @vue/runtime-dom in runtime-core
to avoid improper cross-package dependency (runtime-core should not
depend on runtime-dom).

Summary by CodeRabbit

  • Refactor
    • Improved internal custom element handling and interface to provide more reliable shadow-root detection and integration across rendering and DOM APIs. These infrastructure changes stabilize custom element behavior without altering public APIs or visible behavior.

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

…mElementInterface

Remove direct import of VueElement from @vue/runtime-dom in runtime-core
to avoid improper cross-package dependency (runtime-core should not
depend on runtime-dom).
@coderabbitai

coderabbitai Bot commented Jan 22, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adds _isVueCE boolean and _hasShadowRoot(): boolean to the core custom-element interface, updates the renderer to use that interface for custom element detection and shadow-root checks, and implements _hasShadowRoot() on the VueElement class.

Changes

Cohort / File(s) Summary
Component Interface
packages/runtime-core/src/component.ts
Added _isVueCE: boolean and _hasShadowRoot(): boolean to ComponentCustomElementInterface.
Renderer updates
packages/runtime-core/src/renderer.ts
Replaced VueElement usages with ComponentCustomElementInterface; updated custom element detection and shadow-root check to use _isVueCE and _hasShadowRoot().
VueElement implementation
packages/runtime-dom/src/apiCustomElement.ts
Implemented _hasShadowRoot(): boolean on VueElement, returning true unless the component def sets shadowRoot: false.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

ready to merge, scope: custom elements

Suggested reviewers

  • baiwusanyu-c

Poem

🐰 I hopped through code to leave a clue,
A tiny flag and method new,
Shadow roots I sniff and see,
Whispering "is this a Vue CE?" 🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main refactoring objective: replacing a VueElement import from runtime-dom with ComponentCustomElementInterface in the runtime-core package.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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

@github-actions

Copy link
Copy Markdown

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 103 kB (+45 B) 39.1 kB (+15 B) 35.2 kB (-5 B)
vue.global.prod.js 161 kB (+45 B) 59.1 kB (+17 B) 52.6 kB (+12 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 47 kB (-4 B) 18.4 kB (-3 B) 16.8 kB (-4 B)
createApp 55.1 kB (-4 B) 21.4 kB (-3 B) 19.6 kB (-15 B)
createSSRApp 59.4 kB (-4 B) 23.2 kB (-4 B) 21.1 kB (-1 B)
defineCustomElement 60.8 kB (+45 B) 23.1 kB (+11 B) 21.1 kB (+18 B)
overall 69.5 kB (-4 B) 26.7 kB (-1 B) 24.3 kB (+4 B)

@pkg-pr-new

pkg-pr-new Bot commented Jan 22, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@14348
npm i https://pkg.pr.new/@vue/compiler-core@14348
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@14348
npm i https://pkg.pr.new/@vue/compiler-dom@14348
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@14348
npm i https://pkg.pr.new/@vue/compiler-sfc@14348
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@14348
npm i https://pkg.pr.new/@vue/compiler-ssr@14348
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@14348
npm i https://pkg.pr.new/@vue/reactivity@14348
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@14348
npm i https://pkg.pr.new/@vue/runtime-core@14348
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@14348
npm i https://pkg.pr.new/@vue/runtime-dom@14348
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@14348
npm i https://pkg.pr.new/@vue/server-renderer@14348
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@14348
npm i https://pkg.pr.new/@vue/shared@14348
yarn add https://pkg.pr.new/@vue/[email protected]

vue

pnpm add https://pkg.pr.new/vue@14348
npm i https://pkg.pr.new/vue@14348
yarn add https://pkg.pr.new/[email protected]

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@14348
npm i https://pkg.pr.new/@vue/compat@14348
yarn add https://pkg.pr.new/@vue/[email protected]

commit: 157b334

@edison1105
edison1105 marked this pull request as ready for review January 22, 2026 02:55

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/runtime-core/src/component.ts (1)

1259-1296: Public interface expansion may be breaking for downstream implementations.

ComponentCustomElementInterface is exported and used structurally. Making _isVueCE and _hasShadowRoot() required can break downstream custom-element adapters or module augmentations that implement this interface. Consider keeping the public surface stable by making these members optional or by introducing an internal extension used only by the renderer.

💡 Minimal compatibility-preserving tweak (make members optional)
 export interface ComponentCustomElementInterface {
   /**
    * `@internal`
    */
-  _isVueCE: boolean
+  _isVueCE?: boolean
@@
   /**
    * `@internal` check if shadow root is enabled
    */
-  _hasShadowRoot(): boolean
+  _hasShadowRoot?: () => boolean
 }

If you go this route, update call sites to use optional chaining or a type guard.

🧹 Nitpick comments (1)
packages/runtime-core/src/renderer.ts (1)

644-647: Prefer casting customElement to the interface for stronger typing.

Right now customElement is inferred as RendererElement | null, which relies on the index signature for _beginPatch/_endPatch. Casting to ComponentCustomElementInterface preserves type safety and intent.

♻️ Suggested tweak
-      const customElement =
-        n1.el && (n1.el as ComponentCustomElementInterface)._isVueCE
-          ? n1.el
-          : null
+      const customElement =
+        n1.el && (n1.el as ComponentCustomElementInterface)._isVueCE
+          ? (n1.el as ComponentCustomElementInterface)
+          : null

@edison1105

Copy link
Copy Markdown
Member Author

/ecosystem-ci run

@vuejs vuejs deleted a comment from edison1105 Jan 22, 2026
@vue-bot

vue-bot commented Jan 22, 2026

Copy link
Copy Markdown
Contributor

📝 Ran ecosystem CI: Open

suite result latest scheduled
nuxt ✅ success ✅ success
vue-simple-compiler ✅ success ✅ success
vue-i18n ✅ success ❌ failure
radix-vue ✅ success ✅ success
test-utils ✅ success ✅ success
vitepress ✅ success ✅ success
quasar ✅ success ✅ success
router ❌ failure ❌ failure
vant ✅ success ✅ success
language-tools ✅ success ✅ success
primevue ✅ success ❌ failure
vueuse ✅ success ❌ failure
vue-macros ✅ success ❌ failure
vite-plugin-vue ✅ success ✅ success
vuetify ✅ success ❌ failure
pinia ✅ success ✅ success

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants