inocan-group / vue3-google-map

A set of composable components for easy use of Google Maps in your Vue 3 projects.
https://vue3-google-map.com
MIT License
280 stars 57 forks source link

GoogleMap doesn't render when embedded in custom element #58

Open kerekes opened 2 years ago

kerekes commented 2 years ago

I'm turning a Vue component into a custom element (tag). The GoogleMap component stops working when I embed I use it inside a custom element. Why is that?

mount Version (works)

When App users GoogleMap, this works:

main.js

import SiteMap from "@/elements/App";
import {createApp} from "vue";
createApp(App).mount('#app');

index.html

...
<div id="app"></div>
...

custom'Element Version (breaks) But when embedding it as a custom element, the map doesn't render:

main.js

import App from "@/elements/App";
import {defineCustomElement} from "vue";
customElements.define('my-map-component', defineCustomElement(App));

index.html

...
<my-map-component/>
...
HusamElbashir commented 2 years ago

Hi @kerekes

Can you please share a reproduction? You can use https://vite.new/vue

kerekes commented 2 years ago

@HusamIbrahim here's you are: https://stackblitz.com/edit/vitejs-vite-a12ajq?file=src/components/MapComponent.vue

I left my development API key in so it's more convenient for you. Will deactivate it sometime in the future.

HusamElbashir commented 2 years ago

It appears that the styles of the GoogleMap component aren't being injected in the custom element and the map has 0 height. I'm not too familiar with web components/custom elements but will treat this as a potential bug for now.

You can work around the issue by explicitly defining the map styles:

customElements.define(
  'map-tag',
  defineCustomElement({
    ...MapComponent,
    styles: ['.mapdiv { width: 100%; height: 100% }'],
  })
);

https://stackblitz.com/edit/vitejs-vite-u9fjpv?file=src%2Fmain.js

HusamElbashir commented 2 years ago

So this seems to be an upstream issue https://github.com/vuejs/core/issues/4662