Skip to content

Commit efb2c52

Browse files
refactor: remove globalThis polyfill (#3960)
Fixes #3957 --------- Co-authored-by: Nolan Lawson <[email protected]>
1 parent e0728d0 commit efb2c52

File tree

9 files changed

+19
-38
lines changed

9 files changed

+19
-38
lines changed

packages/@lwc/engine-core/src/framework/runtime-instrumentation.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
66
*/
77
import { noop } from '@lwc/shared';
8-
import { globalThis } from '@lwc/shared';
98

10-
export const instrumentDef = globalThis.__lwc_instrument_cmp_def ?? noop;
11-
export const instrumentInstance = globalThis.__lwc_instrument_cmp_instance ?? noop;
9+
export const instrumentDef = (globalThis as any).__lwc_instrument_cmp_def ?? noop;
10+
export const instrumentInstance = (globalThis as any).__lwc_instrument_cmp_instance ?? noop;

packages/@lwc/engine-core/src/patches/detect-synthetic-cross-root-aria.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
import {
88
assign,
9-
globalThis,
109
isTrue,
1110
KEY__NATIVE_GET_ELEMENT_BY_ID,
1211
KEY__NATIVE_QUERY_SELECTOR_ALL,
@@ -34,16 +33,18 @@ import { logWarnOnce } from '../shared/logger';
3433
//
3534

3635
// Use the unpatched native getElementById/querySelectorAll rather than the synthetic one
37-
const getElementById = globalThis[KEY__NATIVE_GET_ELEMENT_BY_ID] as typeof document.getElementById;
36+
const getElementById = (globalThis as any)[
37+
KEY__NATIVE_GET_ELEMENT_BY_ID
38+
] as typeof document.getElementById;
3839

39-
const querySelectorAll = globalThis[
40+
const querySelectorAll = (globalThis as any)[
4041
KEY__NATIVE_QUERY_SELECTOR_ALL
4142
] as typeof document.querySelectorAll;
4243

4344
// This is a "handoff" from synthetic-shadow to engine-core – we want to clean up after ourselves
4445
// so nobody else can misuse these global APIs.
45-
delete globalThis[KEY__NATIVE_GET_ELEMENT_BY_ID];
46-
delete globalThis[KEY__NATIVE_QUERY_SELECTOR_ALL];
46+
delete (globalThis as any)[KEY__NATIVE_GET_ELEMENT_BY_ID];
47+
delete (globalThis as any)[KEY__NATIVE_QUERY_SELECTOR_ALL];
4748

4849
function isSyntheticShadowRootInstance(rootNode: Node): rootNode is ShadowRoot {
4950
return rootNode !== document && isTrue((rootNode as any).synthetic);

packages/@lwc/engine-dom/src/formatters/__tests__/component.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import {
1111
registerTemplate,
1212
registerDecorators,
1313
} from '@lwc/engine-dom';
14-
import { globalThis, LOWEST_API_VERSION } from '@lwc/shared';
14+
import { LOWEST_API_VERSION } from '@lwc/shared';
1515

1616
// it needs to be imported from the window, otherwise the checks for associated vms is done against "@lwc/engine-core"
17-
const LightningElementFormatter = globalThis['devtoolsFormatters'].find((f: any) => {
17+
const LightningElementFormatter = (globalThis as any)['devtoolsFormatters'].find((f: any) => {
1818
return f.name === 'LightningElementFormatter';
1919
});
2020

packages/@lwc/engine-dom/src/formatters/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
66
*/
77

8-
import { globalThis, ArrayPush } from '@lwc/shared';
8+
import { ArrayPush } from '@lwc/shared';
99
import { LightningElementFormatter } from './component';
1010

1111
function init() {
12-
const devtoolsFormatters = globalThis.devtoolsFormatters || [];
12+
const devtoolsFormatters = (globalThis as any).devtoolsFormatters || [];
1313
ArrayPush.call(devtoolsFormatters, LightningElementFormatter);
14-
globalThis.devtoolsFormatters = devtoolsFormatters;
14+
(globalThis as any).devtoolsFormatters = devtoolsFormatters;
1515
}
1616

1717
if (process.env.NODE_ENV !== 'production') {

packages/@lwc/engine-server/src/polyfills.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
66
*/
77

8-
import { defineProperty, globalThis } from '@lwc/shared';
8+
import { defineProperty } from '@lwc/shared';
99

1010
/**
1111
* The following constructor might be used in either the constructor or the connectedCallback. In

packages/@lwc/features/src/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: MIT
55
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
66
*/
7-
import { create, defineProperty, isUndefined, isBoolean, globalThis } from '@lwc/shared';
7+
import { create, defineProperty, isUndefined, isBoolean } from '@lwc/shared';
88
import { FeatureFlagMap, FeatureFlagName, FeatureFlagValue } from './types';
99

1010
// When deprecating a feature flag, ensure that it is also no longer set in the application. For
@@ -20,13 +20,11 @@ const features: FeatureFlagMap = {
2020
ENABLE_FORCE_SHADOW_MIGRATE_MODE: null,
2121
};
2222

23-
// eslint-disable-next-line no-restricted-properties
24-
if (!globalThis.lwcRuntimeFlags) {
23+
if (!(globalThis as any).lwcRuntimeFlags) {
2524
Object.defineProperty(globalThis, 'lwcRuntimeFlags', { value: create(null) });
2625
}
2726

28-
// eslint-disable-next-line no-restricted-properties
29-
const flags: Partial<FeatureFlagMap> = globalThis.lwcRuntimeFlags;
27+
const flags: Partial<FeatureFlagMap> = (globalThis as any).lwcRuntimeFlags;
3028

3129
/**
3230
* Set the value at runtime of a given feature flag. This method only be invoked once per feature

packages/@lwc/shared/src/global-this.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/@lwc/shared/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import * as assert from './assert';
99
export * from './api-version';
1010
export * from './aria';
1111
export * from './language';
12-
export * from './global-this';
1312
export * from './keys';
1413
export * from './void-elements';
1514
export * from './html-attributes';

packages/@lwc/synthetic-shadow/src/faux-shadow/shadow-root.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
assign,
1010
create,
1111
defineProperty,
12-
globalThis,
1312
isNull,
1413
isTrue,
1514
isUndefined,
@@ -98,15 +97,15 @@ defineProperty(Node.prototype, KEY__SHADOW_RESOLVER, {
9897

9998
// The isUndefined check is because two copies of synthetic shadow may be loaded on the same page, and this
10099
// would throw an error if we tried to redefine it. Plus the whole point is to expose the native method.
101-
if (isUndefined(globalThis[KEY__NATIVE_GET_ELEMENT_BY_ID])) {
100+
if (isUndefined((globalThis as any)[KEY__NATIVE_GET_ELEMENT_BY_ID])) {
102101
defineProperty(globalThis, KEY__NATIVE_GET_ELEMENT_BY_ID, {
103102
value: getElementById,
104103
configurable: true,
105104
});
106105
}
107106

108107
// See note above.
109-
if (isUndefined(globalThis[KEY__NATIVE_QUERY_SELECTOR_ALL])) {
108+
if (isUndefined((globalThis as any)[KEY__NATIVE_QUERY_SELECTOR_ALL])) {
110109
defineProperty(globalThis, KEY__NATIVE_QUERY_SELECTOR_ALL, {
111110
value: querySelectorAll,
112111
configurable: true,

0 commit comments

Comments
 (0)