Skip to content

fix(custom-element): properly locate parent when slotted in shadow dom#12480

Merged
edison1105 merged 2 commits intovuejs:mainfrom
lejunyang:parent-resolving-fix
Mar 9, 2026
Merged

fix(custom-element): properly locate parent when slotted in shadow dom#12480
edison1105 merged 2 commits intovuejs:mainfrom
lejunyang:parent-resolving-fix

Conversation

@lejunyang
Copy link
Copy Markdown
Contributor

@lejunyang lejunyang commented Nov 27, 2024

close #12479

Summary by CodeRabbit

  • Bug Fixes

    • Fixed parent resolution for custom elements when slotted within shadow DOM boundaries, ensuring they correctly inherit provide/inject values from ancestor components as expected.
  • Tests

    • Added comprehensive test coverage for custom element parent resolution in shadow DOM slot scenarios to verify correct context inheritance and prevent regressions.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Nov 27, 2024

Open in StackBlitz

@vue/compiler-core

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

@vue/compiler-dom

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

@vue/compiler-sfc

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

@vue/compiler-ssr

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

@vue/reactivity

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

@vue/runtime-core

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

@vue/runtime-dom

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

@vue/server-renderer

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

@vue/shared

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

vue

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

@vue/compat

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

commit: ef6ade5

@github-actions
Copy link
Copy Markdown

github-actions bot commented Nov 27, 2024

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 104 kB (+16 B) 39.3 kB (+8 B) 35.4 kB (-27 B)
vue.global.prod.js 162 kB (+16 B) 59.4 kB (+9 B) 52.8 kB (-44 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 47.8 kB 18.6 kB 17.1 kB
createApp 56 kB 21.7 kB 19.8 kB
createSSRApp 60.2 kB 23.4 kB 21.4 kB
defineCustomElement 61.6 kB (+16 B) 23.4 kB (+10 B) 21.4 kB (+8 B)
overall 70.4 kB 27 kB 24.6 kB

@lejunyang lejunyang force-pushed the parent-resolving-fix branch from 0ced694 to fce4707 Compare November 27, 2024 13:19
@edison1105 edison1105 added ready to merge The PR is ready to be merged. 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. scope: custom elements labels Nov 27, 2024
@edison1105
Copy link
Copy Markdown
Member

Great work.

@edison1105 edison1105 requested a review from Copilot November 27, 2024 13:28
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no suggestions.

@edison1105 edison1105 changed the title fix(custom-element): fix parent resolving issue when slotted in shadow dom fix(custom-element): properly locate parent when slotted in shadow dom Jun 4, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 58ad9994-b36f-46ec-a3d3-889a7574a3bd

📥 Commits

Reviewing files that changed from the base of the PR and between cea3cf7 and e7f1584.

📒 Files selected for processing (2)
  • packages/runtime-dom/__tests__/customElement.spec.ts
  • packages/runtime-dom/src/apiCustomElement.ts

📝 Walkthrough

Walkthrough

This PR adds a test validating custom element parent resolution in slotted scenarios and modifies the connectedCallback logic in apiCustomElement.ts to check assignedSlot before falling back to parentNode or ShadowRoot.host, ensuring correct parent detection in shadow DOM environments.

Changes

Cohort / File(s) Summary
Custom Element Parent Resolution
packages/runtime-dom/src/apiCustomElement.ts
Modified the parent walk-up logic in connectedCallback to prioritize checking assignedSlot on the current parent before falling back to parentNode or ShadowRoot.host, ensuring correct parent resolution in slotted custom element scenarios.
Provide/Inject Slotted Custom Element Test
packages/runtime-dom/__tests__/customElement.spec.ts
Added a test case validating correct parent resolution when a custom element is slotted inside a shadow DOM, confirming that provide/inject works correctly across slotted boundaries with the expected parent value.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 A slot becomes clear, no parent astray,
The assignedSlot now lights up the way,
Through shadow and light, we hop to the right,
Parent resolved true—provide/inject delight! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 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 change: fixing parent resolution for custom elements when slotted in shadow DOM, matching the primary objective of the PR.
Linked Issues check ✅ Passed The PR successfully implements the required fix by adding assignedSlot checks to parent resolution logic, matching issue #12479's objective for consistent parent resolution between custom elements and Vue components.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing parent resolution for custom elements in shadow DOM; no unrelated modifications were introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

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

@edison1105
Copy link
Copy Markdown
Member

/ecosystem-ci run

@vue-bot
Copy link
Copy Markdown
Contributor

vue-bot commented Mar 9, 2026

📝 Ran ecosystem CI: Open

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

@edison1105 edison1105 merged commit f06c81a into vuejs:main Mar 9, 2026
17 of 18 checks passed
edison1105 added a commit that referenced this pull request Mar 16, 2026
edison1105 added a commit that referenced this pull request Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. ready to merge The PR is ready to be merged. scope: custom elements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Discrepancy in parent resolving for vue custom element and vue component

4 participants