Skip to content

Commit 94fcc72

Browse files
janechuCopilot
andcommitted
chore: remove legacy globalThis polyfill
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 23ca1fa commit 94fcc72

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` and can be shared across multiple versions of the library loaded on the same page.
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
@@ -1,5 +1,21 @@
11
# Migrating from previous versions
22

3+
## Native `globalThis` requirement (v2 → v3)
4+
5+
### Changed behavior
6+
7+
- **Native `globalThis` required**: `@microsoft/fast-element` no longer installs
8+
a `globalThis` polyfill as a side effect. The package only keeps the
9+
`requestIdleCallback` / `cancelIdleCallback` fallback for environments that
10+
still lack those APIs.
11+
12+
### Migration steps
13+
14+
1. Verify that the browsers and JS runtimes you support provide native
15+
`globalThis`.
16+
2. If you still target an older runtime without `globalThis`, load that
17+
polyfill before importing `@microsoft/fast-element`.
18+
319
## Prerendered Content Optimization (v2 → v3)
420

521
### 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.92 KB | 19.57 KB | 17.56 KB |
8-
| FASTElement | 25.29 KB | 7.94 KB | 7.17 KB |
9-
| Updates | 3.61 KB | 1.48 KB | 1.26 KB |
10-
| Observable | 8.12 KB | 2.99 KB | 2.66 KB |
11-
| observable | 8.16 KB | 3.00 KB | 2.68 KB |
12-
| attr | 3.55 KB | 1.42 KB | 1.19 KB |
13-
| children | 6.15 KB | 2.34 KB | 2.06 KB |
14-
| css | 11.32 KB | 4.08 KB | 3.67 KB |
15-
| ref | 5.12 KB | 2.02 KB | 1.76 KB |
16-
| slotted | 5.94 KB | 2.28 KB | 2.00 KB |
17-
| volatile | 8.22 KB | 3.02 KB | 2.69 KB |
7+
| CDN Rollup Bundle | 65.65 KB | 19.50 KB | 17.51 KB |
8+
| FASTElement | 25.05 KB | 7.87 KB | 7.10 KB |
9+
| Updates | 3.37 KB | 1.41 KB | 1.18 KB |
10+
| Observable | 7.89 KB | 2.92 KB | 2.59 KB |
11+
| observable | 7.92 KB | 2.93 KB | 2.60 KB |
12+
| attr | 3.32 KB | 1.34 KB | 1.11 KB |
13+
| children | 5.91 KB | 2.27 KB | 2.00 KB |
14+
| css | 11.08 KB | 4.01 KB | 3.59 KB |
15+
| ref | 4.88 KB | 1.94 KB | 1.69 KB |
16+
| slotted | 5.70 KB | 2.20 KB | 1.93 KB |
17+
| volatile | 7.98 KB | 2.95 KB | 2.62 KB |
1818
| when | 2.33 KB | 956 B | 771 B |
19-
| html | 28.18 KB | 9.29 KB | 8.35 KB |
20-
| repeat | 31.97 KB | 10.19 KB | 9.19 KB |
19+
| html | 27.95 KB | 9.22 KB | 8.28 KB |
20+
| repeat | 31.73 KB | 10.13 KB | 9.12 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.92 KB | 19.57 KB | 17.56 KB |
23-
| FASTElement | 25.29 KB | 7.94 KB | 7.17 KB |
24-
| Updates | 3.61 KB | 1.48 KB | 1.26 KB |
25-
| Observable | 8.12 KB | 2.99 KB | 2.66 KB |
26-
| observable | 8.16 KB | 3.00 KB | 2.68 KB |
27-
| attr | 3.55 KB | 1.42 KB | 1.19 KB |
28-
| children | 6.15 KB | 2.34 KB | 2.06 KB |
29-
| css | 11.32 KB | 4.08 KB | 3.67 KB |
30-
| ref | 5.12 KB | 2.02 KB | 1.76 KB |
31-
| slotted | 5.94 KB | 2.28 KB | 2.00 KB |
32-
| volatile | 8.22 KB | 3.02 KB | 2.69 KB |
22+
| CDN Rollup Bundle | 65.65 KB | 19.50 KB | 17.51 KB |
23+
| FASTElement | 25.05 KB | 7.87 KB | 7.10 KB |
24+
| Updates | 3.37 KB | 1.41 KB | 1.18 KB |
25+
| Observable | 7.89 KB | 2.92 KB | 2.59 KB |
26+
| observable | 7.92 KB | 2.93 KB | 2.60 KB |
27+
| attr | 3.32 KB | 1.34 KB | 1.11 KB |
28+
| children | 5.91 KB | 2.27 KB | 2.00 KB |
29+
| css | 11.08 KB | 4.01 KB | 3.59 KB |
30+
| ref | 4.88 KB | 1.94 KB | 1.69 KB |
31+
| slotted | 5.70 KB | 2.20 KB | 1.93 KB |
32+
| volatile | 7.98 KB | 2.95 KB | 2.62 KB |
3333
| when | 2.33 KB | 956 B | 771 B |
34-
| html | 28.18 KB | 9.29 KB | 8.35 KB |
35-
| repeat | 31.97 KB | 10.19 KB | 9.19 KB |
34+
| html | 27.95 KB | 9.22 KB | 8.28 KB |
35+
| repeat | 31.73 KB | 10.13 KB | 9.12 KB |

0 commit comments

Comments
 (0)