Skip to content
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

Custom Elements Interop Improvements #149

Merged
merged 5 commits into from
Apr 9, 2020
Merged

Conversation

yyx990803
Copy link
Member

@yyx990803 yyx990803 commented Mar 25, 2020

  • Breaking: Custom Elements whitelisting is now performed during template compilation, and should be configured via compiler options instead of runtime config.
    • This removes the runtime overhead for custom elements support.
  • Breaking: Restrict the special is prop usage to the reserved <component> tag only.
  • New: Introduce a new v-is directive to support 2.x use cases where is was used on native elements to work around native HTML parsing restrictions.

Full Rendered Proposal

@yyx990803 yyx990803 added breaking change This RFC contains breaking changes or deprecations of old API. core 3.x This RFC only targets 3.0 and above labels Mar 25, 2020
@backbone87
Copy link

backbone87 commented Mar 25, 2020

just some thoughts:

  • builtin/custom element: <my-element>
  • dynamic builtin/custom element: <[myElementName]>
  • component: <!my-component> - registered globally/locally
  • dynamic component: <![MyComponent]> - returned by setup/instance prop

(the ! meta char is up to debate)

pros:

  • no more is
  • clear distinction between components and elements directly inside the template
  • removes the need to declare locally registered components when using setup functions
  • consistent and aligned syntax for dynamic artifacts (square brackets)

con:

  • builtin browser html parser may not be able to parse this
    edit:
    can be worked around by defining expanded forms in case the browser parser is used:
    • <[myElementName]> -> <vue v-element="myElementName">
    • <!my-component> -> <vue v-component="'my-component'">
    • <![MyComponent]> -> <vue v-component="MyComponent">

@yyx990803
Copy link
Member Author

@backbone87 we are not considering any drastic template syntax change at this point.

@jods4
Copy link

jods4 commented Mar 25, 2020

The idea of <[comp]> as an additional syntax meant to replace <component :is=comp> feels very natural, though, considering the existing dynamic syntaxes.
Could be an idea for 3.1! 💭

@yyx990803
Copy link
Member Author

<[comp]> is not valid HTML (it would be interpreted as plain text by native parsers) so that would not work for in-DOM templates. I'm afraid it's not an option.

@jods4
Copy link

jods4 commented Mar 25, 2020

so are self-closing tags? They are really handy, I love them.

@yyx990803
Copy link
Member Author

@jods4 yeah, that's an exception for string-only templates (so are CamelCase components). We already have these special cases and it would be wise to avoid adding more, especially when you are not adding new capabilities.

@backbone87
Copy link

I provided an expanded form, which the browser should be able to parse

@leopiccionia
Copy link

Would the following pattern be removed (guide)?

<table>
  <!-- CustomRow resolves to a function or object, not a string -->
  <tr :is="CustomRow">
    <td>1</td>
  </tr>
</table>

As of today, my evergreen browser still parses:

<table>
  <custom-row>
    <td>1</td>
  </custom-row>
</table>

Like the following:

<custom-row></custom-row>
<table>
  <tr>
    <td>1</td>
  </tr>
</table>

@yyx990803
Copy link
Member Author

yyx990803 commented Mar 27, 2020

@leopiccionia that's a good point. We should still support this case when is binding value is not a string. <- I think different behavior based on binding value can be confusing, especially when this means you have to expose the component directly to the render context instead of normally registering it.

Maybe we need to introduce a separate v-is directive for the in-DOM use cases:

<table>
  <tr v-is="CustomRow">
    <td>1</td>
  </tr>
</table>

And if the user registered CustomRow via the components option:

<table>
  <tr v-is="'CustomRow'">
    <td>1</td>
  </tr>
</table>

yyx990803 added a commit to vuejs/core that referenced this pull request Mar 27, 2020
@@ -28,8 +31,8 @@ The default generated render function code is (pseudo code):

```js
function render() {
const component_plastic_button = resolveComponent('plastic-button')
return createVNode(component_plastic_button)
const component_plastic_button = resolveComponent("plastic-button");
Copy link
Member

Choose a reason for hiding this comment

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

Code style seems inconsistent with the later part of the RFC, maybe something wrong with the formatter?

Copy link
Member

Choose a reason for hiding this comment

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

We could add a .prettierrc file to make it automatic for people using a plugin with their IDE

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@yyx990803
Copy link
Member Author

This RFC is now in final comments stage. An RFC in final comments stage means that:

The core team has reviewed the feedback and reached consensus about the general direction of the RFC and believe that this RFC is a worthwhile addition to the framework.
Final comments stage does not mean the RFC's design details are final - we may still tweak the details as we implement it and discover new technical insights or constraints. It may even be further adjusted based on user feedback after it lands in an alpha/beta release.
If no major objections with solid supporting arguments have been presented after a week, the RFC will be merged and become an active RFC.

@yyx990803 yyx990803 added the final comments This RFC is in final comments period label Mar 31, 2020
@yyx990803 yyx990803 merged commit 99d18dc into master Apr 9, 2020
@yyx990803 yyx990803 added feat: template syntax Changes related to template syntax and removed final comments This RFC is in final comments period labels Jul 1, 2020
@bencodezen bencodezen mentioned this pull request Jul 6, 2020
25 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x This RFC only targets 3.0 and above breaking change This RFC contains breaking changes or deprecations of old API. core feat: template syntax Changes related to template syntax
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants