Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(custom-element): ensure proper remount and prevent redundant slot parsing with shadowRoot false #13201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
edison1105 merged 3 commits into main from edison/fix/13199
May 22, 2025

Conversation

@edison1105
Copy link
Member

@edison1105 edison1105 commented Apr 15, 2025
edited by coderabbitai bot
Loading

close #13199

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of nested custom elements without shadow DOM to ensure correct mounting, unmounting, and remounting when toggling their visibility.
  • Tests
    • Added a new test to verify the behavior of nested custom elements with shadowRoot set to false during conditional rendering.

rbecheras and moshetanzer reacted with heart emoji
Copy link

github-actions bot commented Apr 15, 2025
edited
Loading

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 101 kB (+4 B) 38.3 kB (+2 B) 34.5 kB (-47 B)
vue.global.prod.js 159 kB (+4 B) 58.5 kB (+3 B) 52.1 kB (+56 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.6 kB 18.2 kB 16.7 kB
createApp 54.5 kB 21.2 kB 19.4 kB
createSSRApp 58.8 kB 23 kB 20.9 kB
defineCustomElement 59.5 kB (+4 B) 22.8 kB (+1 B) 20.8 kB (-4 B)
overall 68.6 kB 26.4 kB 24.1 kB

Copy link

pkg-pr-new bot commented Apr 15, 2025
edited
Loading

Open in StackBlitz

@vue/compiler-core
npm i https://pkg.pr.new/@vue/compiler-core@13201
@vue/compiler-dom
npm i https://pkg.pr.new/@vue/compiler-dom@13201
@vue/compiler-ssr
npm i https://pkg.pr.new/@vue/compiler-ssr@13201
@vue/compiler-sfc
npm i https://pkg.pr.new/@vue/compiler-sfc@13201
@vue/runtime-core
npm i https://pkg.pr.new/@vue/runtime-core@13201
@vue/reactivity
npm i https://pkg.pr.new/@vue/reactivity@13201
@vue/runtime-dom
npm i https://pkg.pr.new/@vue/runtime-dom@13201
@vue/server-renderer
npm i https://pkg.pr.new/@vue/server-renderer@13201
@vue/shared
npm i https://pkg.pr.new/@vue/shared@13201
vue
npm i https://pkg.pr.new/vue@13201
@vue/compat
npm i https://pkg.pr.new/@vue/compat@13201

commit: 5c26522

@edison1105 edison1105 changed the title (削除) fix(custom-element): avoid re-parsing slots if already resolved (削除ここまで) (追記) fix(custom-element): ensure proper remount and prevent redundant slot parsing (追記ここまで) Apr 15, 2025
@edison1105 edison1105 changed the title (削除) fix(custom-element): ensure proper remount and prevent redundant slot parsing (削除ここまで) (追記) fix(custom-element): ensure proper remount and prevent redundant slot parsing with shadowRoot false (追記ここまで) Apr 15, 2025
@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 Apr 15, 2025
Copy link

coderabbitai bot commented May 21, 2025
edited
Loading

Walkthrough

The changes introduce a new test for nested custom elements with shadowRoot: false and update the VueElement class's connectedCallback method to refine slot parsing and instance mounting logic. These modifications aim to ensure correct mounting, unmounting, and remounting of custom elements without shadow DOM, particularly addressing slot resolution and lifecycle handling.

Changes

File(s) Change Summary
packages/runtime-dom/__tests__/customElement.spec.ts Added a test for toggling nested custom elements with shadowRoot: false, verifying mount/unmount.
packages/runtime-dom/src/apiCustomElement.ts Updated connectedCallback to improve slot parsing and mounting logic for non-shadow DOM elements.

Assessment against linked issues

Objective Addressed Explanation
Prevent error when remounting custom elements with { shadowRoot: false } and ensure correct slot/lifecycle handling (#13199)

Poem

A custom element hops in, no shadow to be found,
Nested within its parent, it’s toggled up and down.
No more parent errors, no lifecycle surprise—
The Vue bunny fixes bugs with clever, watchful eyes!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between d53daf1 and 5c26522.

📒 Files selected for processing (2)
  • packages/runtime-dom/__tests__/customElement.spec.ts (1 hunks)
  • packages/runtime-dom/src/apiCustomElement.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Redirect rules
  • GitHub Check: Header rules
  • GitHub Check: Pages changed
  • GitHub Check: test / unit-test-windows
🔇 Additional comments (3)
packages/runtime-dom/src/apiCustomElement.ts (2)

283-284: Optimize slot parsing for custom elements

This condition now correctly prevents redundant parsing of slots when they have already been resolved. Previously, slots would be re-parsed even if they were already resolved, causing unnecessary performance overhead when remounting.


300-303: Improve custom element mounting logic

This change streamlines the mounting process for already resolved components. Instead of separately setting the parent and updating the component, it now directly calls _mount(this._def), which includes both operations. This ensures proper remounting of custom elements, particularly when shadowRoot: false.

packages/runtime-dom/__tests__/customElement.spec.ts (1)

1230-1314: Good test coverage for nested custom elements with shadowRoot: false

This comprehensive test verifies the fix for the issue described in PR #13199. It tests the proper mounting, unmounting, and remounting of nested custom elements with shadowRoot: false when toggling conditional rendering.

The test correctly:

  1. Creates parent and child custom elements with shadowRoot: false
  2. Verifies initial rendering
  3. Tests unmounting by setting isShown to false
  4. Tests remounting by setting isShown back to true
  5. Validates DOM structure at each step

The test passes with the changes made to the connectedCallback method and confirms that slot parsing is not performed redundantly.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Member Author

/ecosystem-ci run

github-actions[bot] reacted with thumbs up emoji

@vuejs vuejs deleted a comment from edison1105 May 21, 2025
Copy link
Contributor

vue-bot commented May 21, 2025

📝 Ran ecosystem CI: Open

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

@edison1105 edison1105 merged commit 1d41d4d into main May 22, 2025
16 checks passed
@edison1105 edison1105 deleted the edison/fix/13199 branch May 22, 2025 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

2 more reviewers

@wolandec wolandec wolandec left review comments

@rbecheras rbecheras rbecheras left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

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

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[custom elements api] Cannot set properties of null (setting 'parent') with { shadowRoot: false }

AltStyle によって変換されたページ (->オリジナル) /