Skip to content

Conversation

steveworkman
Copy link

Resolves #7203 by checking for the presence of a custom element in the custom element registry and allowing that to be hydrated with vue properties.

Ideally, I'd use the isCustomElement compiler option - however, that is not available at runtime. This is the next best thing - however, it could potentially hydrate more components than the user intended if they have not specified all of their custom elements in the isCustomElement function.

This is required for hydration to function correctly in prashantpalikhe/nuxt-ssr-lit#34

@netlify
Copy link

netlify bot commented Dec 8, 2022

Deploy Preview for vuejs-coverage failed.

Name Link
🔨 Latest commit 95d92b3
🔍 Latest deploy log https://app.netlify.com/sites/vuejs-coverage/deploys/63c17ccf6530510009bb0179

(forcePatchValue && key.endsWith('value')) ||
(isOn(key) && !isReservedProp(key))
(isOn(key) && !isReservedProp(key)) ||
customElements.get(el.localName) // If the element is a custom element, apply vue props during hydration - See #7203
Copy link
Member

@LinusBorg LinusBorg Dec 20, 2022

Choose a reason for hiding this comment

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

You should be able to use the app config function like:

parentComponent.appContext.config.isCustomElement?.(el.localName)

That would be more desirable as we don't want to reference any DOM apis in runtime-core.

That check should also be done sooner, outside of the for loop.

This change would then also mean that we would have to append the docs for app.config.isCustomElement and explain that this function is not only useful when using the runtime Compiler, but also when using custom elements in an SSR app.

Copy link
Author

@steveworkman steveworkman Dec 22, 2022

Choose a reason for hiding this comment

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

In the test app we're working with (nuxt 3) the isCustomElement function is always undefined, so we've not been able to use that function. The other functions in the appContext appear to be there. If you're certain that it should be there, I'll dig into where it goes missing some more

Copy link
Member

@LinusBorg LinusBorg Dec 22, 2022

Choose a reason for hiding this comment

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

My apologies, it's:

parentComponent.appContext.config.compilerOptions.isCustomElement?.(el.localName)

See https://vuejs.org/guide/extras/web-components.html#using-custom-elements-in-vue
https://vuejs.org/api/application.html#app-config-compileroptions

And of course, that function has to be added by the developer.

@steveworkman
Copy link
Author

steveworkman commented Dec 22, 2022 via email

@steveworkman
Copy link
Author

@LinusBorg thanks for the guidance, with help from @danielroe I got nuxt to set the isCustomElement function at runtime and confirmed that this works when combined with this patch. Please re-review

yyx990803 and others added 26 commits April 5, 2023 10:20
This is no longer necessary as we no longer recommend type checking generated code
In some cases, the user still needs access to the full props object,
in such cases withDefaults() is still needed.
@steveworkman
Copy link
Author

Superceeded by #8035

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's props are not applied on the client side when they are SSR-ed