Skip to content

Commit 6a8a764

Browse files
committed
feat(polyfills-loader): add support for Scoped CustomElementRegistry polyfill
1 parent 945f013 commit 6a8a764

File tree

8 files changed

+33
-0
lines changed

8 files changed

+33
-0
lines changed

.changeset/neat-toes-nail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@web/polyfills-loader': minor
3+
---
4+
5+
add support for the Scoped CustomElementRegistry polyfill (this is a prototype polyfill)

docs/docs/building/polyfills-loader.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ The polyfills config controls which polyills are injected onto the page. These a
154154
- [dynamicImport](https://github.com/GoogleChromeLabs/dynamic-import-polyfill)
155155
- [esModuleShims](https://github.com/guybedford/es-module-shims)
156156
- [shadyCssCustomStyle](https://github.com/webcomponents/polyfills/blob/master/packages/shadycss/custom-style-interface.html) (you must also include webcomponents)
157+
- [scopedCustomElementRegistry](https://github.com/webcomponents/polyfills/tree/master/packages/scoped-custom-element-registry)
157158

158159
They can be turned on using booleans. When using the polyfills loader directly, these are default false. Other tools may turn on different defaults.
159160

packages/polyfills-loader/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ const config = {
8080
constructibleStylesheets: true,
8181
URLPattern: true,
8282
resizeObserver: true,
83+
scopedCustomElementRegistry: true,
8384
},
8485
minify: true,
8586
};
@@ -157,6 +158,7 @@ The polyfills config controls which polyills are injected onto the page. These a
157158
- [constructibleStylesheets](https://github.com/calebdwilliams/construct-style-sheets)
158159
- [URLPattern](https://github.com/kenchris/urlpattern-polyfill)
159160
- [shadyCssCustomStyle](https://github.com/webcomponents/polyfills/blob/master/packages/shadycss/custom-style-interface.html) (you must also include webcomponents)
161+
- [scopedCustomElementRegistry](https://github.com/webcomponents/polyfills/tree/master/packages/scoped-custom-element-registry)
160162

161163
They can be turned on using booleans. When using the polyfills loader directly, these are default false. Other tools may turn on different defaults.
162164

packages/polyfills-loader/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"dependencies": {
4848
"@babel/core": "^7.12.10",
4949
"@web/parse5-utils": "^2.0.0",
50+
"@webcomponents/scoped-custom-element-registry": "^0.0.9",
5051
"@webcomponents/shadycss": "^1.11.0",
5152
"@webcomponents/webcomponentsjs": "^2.5.0",
5253
"abortcontroller-polyfill": "^1.5.0",

packages/polyfills-loader/src/createPolyfillsData.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@ export async function createPolyfillsData(cfg: PolyfillsLoaderConfig): Promise<P
153153
});
154154
}
155155

156+
if (polyfills.scopedCustomElementRegistry) {
157+
addPolyfillConfig({
158+
name: 'scoped-custom-element-registry',
159+
test: "!('createElement' in ShadowRoot.prototype)",
160+
path: require.resolve(
161+
'@webcomponents/scoped-custom-element-registry/scoped-custom-element-registry.min.js',
162+
),
163+
});
164+
}
165+
156166
if (polyfills.webcomponents && !polyfills.shadyCssCustomStyle) {
157167
addPolyfillConfig({
158168
name: 'webcomponents',

packages/polyfills-loader/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export interface PolyfillsConfig {
5252
constructibleStylesheets?: boolean;
5353
// shady-css-custom-style and shady-css-scoped-element
5454
shadyCssCustomStyle?: boolean;
55+
scopedCustomElementRegistry?: boolean;
5556
}
5657

5758
export interface PolyfillConfig {

packages/polyfills-loader/test/createPolyfillsData.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ describe('polyfills', () => {
3434
esModuleShims: true,
3535
constructibleStylesheets: true,
3636
URLPattern: true,
37+
scopedCustomElementRegistry: true,
3738
},
3839
};
3940

@@ -102,6 +103,13 @@ describe('polyfills', () => {
102103
content: '',
103104
type: 'script',
104105
},
106+
{
107+
name: 'scoped-custom-element-registry',
108+
path: 'polyfills/scoped-custom-element-registry.js',
109+
test: "!('createElement' in ShadowRoot.prototype)",
110+
content: '',
111+
type: 'script',
112+
},
105113
{
106114
name: 'webcomponents',
107115
path: 'polyfills/webcomponents.js',

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3083,6 +3083,11 @@
30833083
resolved "https://registry.yarnpkg.com/@web/storybook-prebuilt/-/storybook-prebuilt-0.1.34.tgz#993ee48a287f10e98adac55a6bab8e596a1ba228"
30843084
integrity sha512-03IvmZNfWK1FO9WQn71uCmzbLorNpzqJNV3L2bx85ND8Gg7CqnFxBKOhEeh5JAbqU2j+JGRgTvsZPusGjng38g==
30853085

3086+
"@webcomponents/scoped-custom-element-registry@^0.0.9":
3087+
version "0.0.9"
3088+
resolved "https://registry.yarnpkg.com/@webcomponents/scoped-custom-element-registry/-/scoped-custom-element-registry-0.0.9.tgz#dd6ea3378bfeaea64d0c7542120e0ffd17b48b0e"
3089+
integrity sha512-4RVHwN9oIp23mhrxeDbP9/0wvdcrB0d/MFMqIStShIgfzsqXZXf1OdU5kvqjgdMYavQ5Zm8C6BuBcAjzNwAetQ==
3090+
30863091
"@webcomponents/shadycss@^1.11.0":
30873092
version "1.11.2"
30883093
resolved "https://registry.yarnpkg.com/@webcomponents/shadycss/-/shadycss-1.11.2.tgz#7539b0ad29598aa2eafee8b341059e20ac9e1006"

0 commit comments

Comments
 (0)