Skip to content

Polyfill not working when integrating a web component in Vue or React framework #1635

@stephanschroeter

Description

@stephanschroeter

Stencil version:

 @stencil/core@1.0.3

I'm submitting a:
[x] bug report
[ ] feature request
[ ] support request

Current behavior:
When integrating a web component generated by Stencil JS into Vue or React framework according to Stencil JS docs then the web component polyfill is not working at all.

Expected behavior:
Stencil Web Component polyfill should work correctly when integrating in e.g. Vue or React framework.

Steps to reproduce:

Create project setup

mkdir test
cd test

Add a package.json file:

{
  "name": "test",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "private": true,
  "workspaces": ["test-components", "test-app"]
}

Setup Stencil JS

Make sure to execute the following command within the previously generated folder test.

npm init stencil

Selected options:

  • component
  • Project name: test-components
cd test-components
npm install @stencil/core@1.0.3

Edit following file:
src/components/my-component/my-component.css

div {
  background: deeppink;
}

Create a build

yarn build

Setup Vue JS

Using Vue cli (version: 3.8.2) to create a dummy Vue project.
Make sure to execute the following command within the previously generated folder test.

vue create test-app

Selected options:

  • Babel
  • TypeScript
  • Linter / Formatter
  • class-style component syntax
  • Use Babel alongside TypeScript
  • TSLint

Adapt test-app/src/main.ts

import Vue from 'vue';
import App from './App.vue';
import { defineCustomElements } from 'test-components/loader';

Vue.config.productionTip = false;
Vue.config.ignoredElements = [/my-\w*/];

defineCustomElements(window);

new Vue({
  render: (h) => h(App),
}).$mount('#app');

Adapt template section in test-app/src/App.vue

<template>
  <div id="app">
    <img alt="Vue logo" src="./assets/logo.png">
    <my-component first="Stencil" last="'Don't call me a framework' JS"></my-component>
    <HelloWorld msg="Welcome to Your Vue.js + TypeScript App"/>
  </div>
</template>

Start application

cd test-app
yarn serve

Web component is working fine in e.g. latest version of Chrome but component is not shown in e.g. IE11.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions