Skip to content

fix(custom-element) Assign custom element properties on prototype #13716

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mattheww-skyward
Copy link

@mattheww-skyward mattheww-skyward commented Jul 28, 2025

Fixes #13706

Fixing the tests raised a few questions I'm not sure of the answers to.

  • How much effort should we put into detecting pre-existing properties when calling expose()? Should we go all the way up the prototype chain to VueElement?
  • How much effort should we put into detecting+handling the case when an async component definition returns something different on subsequent invocations? It should never reasonably happen, but it could, and it would mean the prototype is invalid.
    If we don't care at all we could overwrite VueCustomElement.def with the resolved definition instead of setting VueCustomElement.asyncDef. But we could have done that before - I'm not sure what Vue's stance on this sort of caching is.
  • How should we handle values set before connectedCallback? My reflection call preserves the old behavior but it strikes me as kind of hacky.
    I added this check to fix the "handling properties set before upgrading" test failing, due to setting the corresponding attribute, and then, when mounted, assigning the property off of the (now stringified) attribute value. Maybe it should set the attribute plus a flag for backflow prevention? As a developer I found it somewhat surprising that properties and attributes behave differently before and after connection. But I don't know what is normal for custom elements.

Summary by CodeRabbit

  • New Features

    • Improved support for custom elements by centralizing property accessors on the prototype, ensuring consistent behavior and easier subclassing.
    • Enhanced handling of asynchronous component definitions for custom elements, including caching and warning on mismatches.
  • Bug Fixes

    • Addressed issues where property shadowing could occur, ensuring correct property access and updates in custom elements.
  • Tests

    • Added a new test case to verify that property setters can be overridden in subclasses of custom elements and affect the rendered output as expected.

Copy link

coderabbitai bot commented Jul 28, 2025

Walkthrough

The changes introduce a new helper function to centralize prop accessor definitions on custom element prototypes, add a static property for async component definition tracking, and refine async resolution and prop handling logic. A new test verifies that subclassed custom elements can override property setters and affect the rendered output as expected.

Changes

Cohort / File(s) Change Summary
Custom Element Prop Accessor Refactor & Async Handling
packages/runtime-dom/src/apiCustomElement.ts
Introduces _defineProps to define prop accessors on prototypes, adds asyncDef static property, updates async resolution logic, removes redundant inline prop accessor code, and improves property exposure and cleanup.
Custom Element Prop Override Test
packages/runtime-dom/__tests__/customElement.spec.ts
Adds a test case verifying that subclassed custom elements can override property setters and that the overridden logic affects rendering.

Sequence Diagram(s)

sequenceDiagram
    participant User as User
    participant CustomElement as SubclassedCustomElement
    participant BaseElement as BaseCustomElement

    User->>CustomElement: Set value = 999
    CustomElement->>CustomElement: Overridden setter increments (999 → 1000)
    CustomElement->>BaseElement: Call base setter with 1000
    BaseElement->>CustomElement: Render with value 1000
Loading
sequenceDiagram
    participant Browser as Browser
    participant VueCustomElement as VueCustomElement
    participant AsyncComponent as AsyncComponent

    Browser->>VueCustomElement: Instantiate custom element
    VueCustomElement->>AsyncComponent: Resolve async component
    AsyncComponent-->>VueCustomElement: Return resolved definition
    VueCustomElement->>VueCustomElement: Check and set asyncDef/static cache
    VueCustomElement->>VueCustomElement: Call _defineProps on prototype (if needed)
    VueCustomElement->>VueCustomElement: Delete instance prop shadows
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Assessment against linked issues

Objective Addressed Explanation
Allow subclassed custom elements to override property setters and have those overrides called (#13706)
Define property accessors on prototypes to enable overriding and avoid instance redefinition (#13706)
Cache async component definitions to avoid redundant prop accessor redefinitions (#13706)
Emit warning if async component definitions differ between instances (#13706)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes detected.

Suggested labels

ready to merge, :hammer: p3-minor-bug, scope: custom elements

Poem

🐇 In code fields where the carrots grow,
Props leap on prototypes, swift and slow.
Async waits, then joins the dance,
Subclass setters get their chance.
Rendered numbers jump and shine,
Custom elements now align!
Hop along, the tests all pass — hooray, all’s fine! 🥕✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cbfd888 and 8a0b714.

📒 Files selected for processing (2)
  • packages/runtime-dom/__tests__/customElement.spec.ts (1 hunks)
  • packages/runtime-dom/src/apiCustomElement.ts (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/runtime-dom/tests/customElement.spec.ts
  • packages/runtime-dom/src/apiCustomElement.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Redirect rules
  • GitHub Check: Header rules
  • GitHub Check: Pages changed
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • 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
🪧 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 generate unit tests to generate unit tests for 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.

@mattheww-skyward mattheww-skyward changed the title Assign custom element properties on prototype (fix #13706) Assign custom element properties on prototype Jul 28, 2025
@mattheww-skyward mattheww-skyward changed the title Assign custom element properties on prototype fix(custom-element) Assign custom element properties on prototype Jul 28, 2025
@mattheww-skyward mattheww-skyward force-pushed the custom-element-properties branch from cbfd888 to 8a0b714 Compare July 28, 2025 20:06
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.

Custom element properties cannot be overridden
1 participant