Skip to content

Commit bd4550a

Browse files
authored
chore: remove legacy globalThis polyfill (#7481)
# Pull Request ## 📖 Description - Remove the legacy `globalThis` polyfill from `@microsoft/fast-element` while keeping the `requestIdleCallback` / `cancelIdleCallback` fallback. - Document the new v3 runtime expectation in `README.md`, `DESIGN.md`, `MIGRATION.md`, and the 3.x browser support page. - Regenerate the fast-element size docs to capture the smaller bundle output. ### 🎫 Issues - Closes #7289 ## 👩‍💻 Reviewer Notes - The only runtime code change is in `packages/fast-element/src/polyfills.ts`; the remaining edits are documentation, migration guidance, the change file, and generated size docs. - `npm run test` still hits an existing `@microsoft/fast-html` `nested-elements` failure on this branch, and `npm run test -w @microsoft/fast-element` still sees existing Playwright connection-refused / flaky failures unrelated to this polyfill removal. ## 📑 Test Plan - `npm run build` - `npm run biome:check` - `npm run checkchange` - `node --input-type=module -e "delete globalThis.requestIdleCallback; delete globalThis.cancelIdleCallback; await import('./packages/fast-element/dist/esm/polyfills.js'); console.log(typeof globalThis.requestIdleCallback, typeof globalThis.cancelIdleCallback);"` - `npm run test` *(currently fails in pre-existing `packages/fast-html/test/fixtures/scenarios/nested-elements/nested-elements.spec.ts`)* - `npm run test -w @microsoft/fast-element` *(currently fails in existing Playwright instability / `ERR_CONNECTION_REFUSED` cases on this branch)* ## ✅ Checklist ### General - [x] I have included a change request file using `$ npm run change` - [ ] I have added tests for my changes. - [ ] I have tested my changes. - [x] I have updated the project documentation to reflect my changes. - [x] I have read the [CONTRIBUTING](https://github.com/microsoft/fast/blob/main/CONTRIBUTING.md) documentation and followed the [standards](https://github.com/microsoft/fast/blob/main/CODE_OF_CONDUCT.md#our-standards) for this project.
1 parent 569bb86 commit bd4550a

8 files changed

Lines changed: 76 additions & 64 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "major",
3+
"comment": "Remove the built-in globalThis polyfill; fast-element v3 now requires native globalThis",
4+
"packageName": "@microsoft/fast-element",
5+
"email": "7559015+janechu@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}

packages/fast-element/DESIGN.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ For deep dives into specific areas, see the linked detailed documents.
5050

5151
The library's kernel (the `FAST` global, the `Updates` queue, and the `Observable` system) is stored on `globalThis.FAST`.
5252

53+
The v3 runtime assumes native `globalThis`. `src/polyfills.ts` only backfills
54+
`requestIdleCallback` / `cancelIdleCallback`, so applications targeting older
55+
engines must install their own `globalThis` polyfill before FAST loads.
56+
5357
---
5458

5559
## Core Concepts

packages/fast-element/MIGRATION.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,22 @@
1313
1. Remove any runtime checks that read `FAST.versions`.
1414
2. Fix duplicate FAST installs in your bundler or dependency graph instead of relying on version tracking at runtime.
1515

16+
## Native `globalThis` requirement (v2 → v3)
17+
18+
### Changed behavior
19+
20+
- **Native `globalThis` required**: `@microsoft/fast-element` no longer installs
21+
a `globalThis` polyfill as a side effect. The package only keeps the
22+
`requestIdleCallback` / `cancelIdleCallback` fallback for environments that
23+
still lack those APIs.
24+
25+
### Migration steps
26+
27+
1. Verify that the browsers and JS runtimes you support provide native
28+
`globalThis`.
29+
2. If you still target an older runtime without `globalThis`, load that
30+
polyfill before importing `@microsoft/fast-element`.
31+
1632
## Prerendered Content Optimization (v2 → v3)
1733

1834
### Removed exports

packages/fast-element/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ For simplicity, examples throughout the documentation will assume the library ha
5353
Looking for a quick guide on building components? Check out [our Cheat Sheet](../resources/cheat-sheet.md#building-components).
5454
:::
5555

56+
## Browser Requirements
57+
58+
FAST Element v3 assumes a modern runtime with native `globalThis`. The package
59+
still installs its `requestIdleCallback` / `cancelIdleCallback` fallback
60+
internally, but it no longer patches `globalThis` for older engines. If you
61+
need to support an environment without `globalThis`, load that polyfill before
62+
importing `@microsoft/fast-element`.
63+
5664
## Export Sizes
5765

5866
Bundle sizes for each tree-shakeable export are tracked in [`SIZES.md`](./SIZES.md) and regenerated on every build. See the [Export Sizes](https://www.fast.design/docs/3.x/resources/export-sizes/) documentation page for the latest numbers.
@@ -104,4 +112,3 @@ FASTElement.define(MyComponent, { name: "my-component" }, [logger()]);
104112
```
105113

106114
Each extension receives the full `FASTElementDefinition`, which includes the resolved element name, type, template, styles, and attribute metadata. Extensions run before `customElements.define()`, so any setup they perform is available when existing DOM elements are upgraded.
107-

packages/fast-element/SIZES.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ Bundle sizes for `@microsoft/fast-element` exports.
44

55
| Export | Minified | Gzip | Brotli |
66
|--------|----------|------|--------|
7-
| CDN Rollup Bundle | 65.03 KB | 19.31 KB | 17.30 KB |
8-
| FASTElement | 23.92 KB | 7.48 KB | 6.76 KB |
9-
| Updates | 3.69 KB | 1.51 KB | 1.28 KB |
10-
| Observable | 8.20 KB | 3.01 KB | 2.68 KB |
11-
| observable | 8.24 KB | 3.02 KB | 2.69 KB |
12-
| attr | 3.63 KB | 1.44 KB | 1.21 KB |
13-
| children | 6.22 KB | 2.37 KB | 2.08 KB |
14-
| css | 11.40 KB | 4.10 KB | 3.69 KB |
15-
| ref | 5.20 KB | 2.04 KB | 1.78 KB |
16-
| slotted | 6.01 KB | 2.30 KB | 2.02 KB |
17-
| volatile | 8.29 KB | 3.04 KB | 2.71 KB |
7+
| CDN Rollup Bundle | 64.76 KB | 19.24 KB | 17.23 KB |
8+
| FASTElement | 23.69 KB | 7.41 KB | 6.68 KB |
9+
| Updates | 3.45 KB | 1.43 KB | 1.21 KB |
10+
| Observable | 7.96 KB | 2.94 KB | 2.61 KB |
11+
| observable | 8.00 KB | 2.95 KB | 2.63 KB |
12+
| attr | 3.39 KB | 1.37 KB | 1.13 KB |
13+
| children | 5.99 KB | 2.29 KB | 2.01 KB |
14+
| css | 11.16 KB | 4.03 KB | 3.61 KB |
15+
| ref | 4.96 KB | 1.96 KB | 1.71 KB |
16+
| slotted | 5.78 KB | 2.23 KB | 1.95 KB |
17+
| volatile | 8.05 KB | 2.97 KB | 2.64 KB |
1818
| when | 2.40 KB | 978 B | 786 B |
19-
| html | 27.37 KB | 8.95 KB | 8.02 KB |
20-
| repeat | 31.03 KB | 9.88 KB | 8.88 KB |
19+
| html | 27.13 KB | 8.88 KB | 7.96 KB |
20+
| repeat | 30.79 KB | 9.81 KB | 8.82 KB |

packages/fast-element/src/polyfills.ts

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,3 @@
1-
/* eslint-disable @typescript-eslint/ban-ts-comment */
2-
(function ensureGlobalThis() {
3-
if (typeof globalThis !== "undefined") {
4-
// We're running in a modern environment.
5-
return;
6-
}
7-
8-
// @ts-ignore
9-
if (typeof global !== "undefined") {
10-
// We're running in NodeJS
11-
// @ts-ignore
12-
global.globalThis = global;
13-
} else if (typeof self !== "undefined") {
14-
(self as any).globalThis = self;
15-
} else if (typeof window !== "undefined") {
16-
// We're running in the browser's main thread.
17-
(window as any).globalThis = window;
18-
} else {
19-
// Hopefully we never get here...
20-
// Not all environments allow eval and Function. Use only as a last resort:
21-
// eslint-disable-next-line no-new-func
22-
const result = new Function("return this")();
23-
result.globalThis = result;
24-
}
25-
})();
26-
271
(function requestIdleCallbackPolyfill() {
282
if ("requestIdleCallback" in globalThis) {
293
return;
@@ -39,7 +13,7 @@
3913
*/
4014
globalThis.requestIdleCallback = function requestIdleCallback(
4115
callback: (deadline: IdleDeadline) => void,
42-
options?: { timeout: number }
16+
options?: { timeout: number },
4317
): number {
4418
const start = Date.now();
4519
return setTimeout(() => {
@@ -59,7 +33,7 @@
5933
* @public
6034
*/
6135
globalThis.cancelIdleCallback = function cancelIdleCallback(
62-
id: ReturnType<typeof globalThis.requestIdleCallback | typeof setTimeout>
36+
id: ReturnType<typeof globalThis.requestIdleCallback | typeof setTimeout>,
6337
): void {
6438
clearTimeout(id);
6539
};

sites/website/src/docs/3.x/resources/browser-support.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,25 @@ eleventyNavigation:
88
title: Browser Support
99
navigationOptions:
1010
activeKey: browser-support3x
11-
description: View the list of browsers that have native support for the Web Components features used by fast-element.
11+
description: View the list of browsers that have native support for the Web Components features and native globalThis required by fast-element v3.
1212
keywords:
1313
- browser support
1414
---
1515

16-
The following browsers have native support for the Web Components features used by `@microsoft/fast-element`:
16+
The following browsers have native support for the Web Components features used by `@microsoft/fast-element`, including the native `globalThis` required by v3:
1717

1818
* Microsoft Edge 79+
19-
* Mozilla Firefox 63+
20-
* Google Chrome 67+
21-
* Apple Safari 10.1+
22-
* Opera 41+
23-
* iOS Safari 10.3+
19+
* Mozilla Firefox 65+
20+
* Google Chrome 71+
21+
* Apple Safari 12.1+
22+
* Opera 58+
23+
* iOS Safari 12.2+
2424
* Android Browser 81+
25-
* Opera Mobile 46+
25+
* Opera Mobile 54+
2626
* Chrome for Android 81+
2727
* Firefox for Android 68+
28-
* Samsung Internet 6.2+x
28+
* Samsung Internet 10.0+
29+
30+
FAST Element v3 no longer polyfills `globalThis` for older engines. If you need
31+
to support an environment below these minimums, load a `globalThis` polyfill
32+
before importing FAST.

sites/website/src/docs/3.x/resources/export-sizes.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ Bundle sizes for `@microsoft/fast-element` exports.
1919

2020
| Export | Minified | Gzip | Brotli |
2121
|--------|----------|------|--------|
22-
| CDN Rollup Bundle | 65.03 KB | 19.31 KB | 17.30 KB |
23-
| FASTElement | 23.92 KB | 7.48 KB | 6.76 KB |
24-
| Updates | 3.69 KB | 1.51 KB | 1.28 KB |
25-
| Observable | 8.20 KB | 3.01 KB | 2.68 KB |
26-
| observable | 8.24 KB | 3.02 KB | 2.69 KB |
27-
| attr | 3.63 KB | 1.44 KB | 1.21 KB |
28-
| children | 6.22 KB | 2.37 KB | 2.08 KB |
29-
| css | 11.40 KB | 4.10 KB | 3.69 KB |
30-
| ref | 5.20 KB | 2.04 KB | 1.78 KB |
31-
| slotted | 6.01 KB | 2.30 KB | 2.02 KB |
32-
| volatile | 8.29 KB | 3.04 KB | 2.71 KB |
22+
| CDN Rollup Bundle | 64.76 KB | 19.24 KB | 17.23 KB |
23+
| FASTElement | 23.69 KB | 7.41 KB | 6.68 KB |
24+
| Updates | 3.45 KB | 1.43 KB | 1.21 KB |
25+
| Observable | 7.96 KB | 2.94 KB | 2.61 KB |
26+
| observable | 8.00 KB | 2.95 KB | 2.63 KB |
27+
| attr | 3.39 KB | 1.37 KB | 1.13 KB |
28+
| children | 5.99 KB | 2.29 KB | 2.01 KB |
29+
| css | 11.16 KB | 4.03 KB | 3.61 KB |
30+
| ref | 4.96 KB | 1.96 KB | 1.71 KB |
31+
| slotted | 5.78 KB | 2.23 KB | 1.95 KB |
32+
| volatile | 8.05 KB | 2.97 KB | 2.64 KB |
3333
| when | 2.40 KB | 978 B | 786 B |
34-
| html | 27.37 KB | 8.95 KB | 8.02 KB |
35-
| repeat | 31.03 KB | 9.88 KB | 8.88 KB |
34+
| html | 27.13 KB | 8.88 KB | 7.96 KB |
35+
| repeat | 30.79 KB | 9.81 KB | 8.82 KB |

0 commit comments

Comments
 (0)