Skip to content

Commit b2ead7a

Browse files
authored
fix(runtime): nativeGlobal is undefined (#2058)
1 parent 5c17bc4 commit b2ead7a

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

.changeset/fresh-baboons-train.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/runtime': patch
3+
---
4+
5+
fix(runtime): nativeGlobal is undefined

packages/runtime/__tests__/preload-remote.spec.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ describe('preload-remote inBrowser', () => {
237237
beforeEach(() => {
238238
document.head.innerHTML = '';
239239
document.body.innerHTML = '';
240-
globalThis.__FEDERATION__.__PRELOADED_MAP__.clear();
240+
Global.__FEDERATION__.__PRELOADED_MAP__.clear();
241241
});
242242

243243
const FMInstance = init({
@@ -284,14 +284,12 @@ describe('preload-remote inBrowser', () => {
284284
]);
285285

286286
expect(getPreloadElInfos()).toMatchSnapshot();
287-
expect(globalThis.__FEDERATION__.__PRELOADED_MAP__.size).toBe(2);
287+
expect(Global.__FEDERATION__.__PRELOADED_MAP__.size).toBe(2);
288288
expect(
289-
globalThis.__FEDERATION__.__PRELOADED_MAP__.get(
290-
'@federation/sub1/button',
291-
),
289+
Global.__FEDERATION__.__PRELOADED_MAP__.get('@federation/sub1/button'),
292290
).toBe(true);
293291
expect(
294-
globalThis.__FEDERATION__.__PRELOADED_MAP__.get(
292+
Global.__FEDERATION__.__PRELOADED_MAP__.get(
295293
'@federation/sub1-button/button',
296294
),
297295
).toBe(true);
@@ -309,29 +307,25 @@ describe('preload-remote inBrowser', () => {
309307
]);
310308

311309
expect(getPreloadElInfos()).toMatchSnapshot();
312-
expect(globalThis.__FEDERATION__.__PRELOADED_MAP__.size).toBe(3);
310+
expect(Global.__FEDERATION__.__PRELOADED_MAP__.size).toBe(3);
313311
expect(
314-
globalThis.__FEDERATION__.__PRELOADED_MAP__.get(
315-
'@federation/sub2/button',
316-
),
312+
Global.__FEDERATION__.__PRELOADED_MAP__.get('@federation/sub2/button'),
317313
).toBe(true);
318314
expect(
319-
globalThis.__FEDERATION__.__PRELOADED_MAP__.get(
315+
Global.__FEDERATION__.__PRELOADED_MAP__.get(
320316
'@federation/sub2-button/button',
321317
),
322318
).toBe(true);
323319
expect(
324-
globalThis.__FEDERATION__.__PRELOADED_MAP__.get(
325-
'@federation/sub2-add/add',
326-
),
320+
Global.__FEDERATION__.__PRELOADED_MAP__.get('@federation/sub2-add/add'),
327321
).toBe(true);
328322
reset();
329323
});
330324

331325
it('3 preload with expose config ', async () => {
332326
const reset = addGlobalSnapshot(mockSnapshot);
333327

334-
expect(globalThis.__FEDERATION__.__PRELOADED_MAP__.size).toBe(0);
328+
expect(Global.__FEDERATION__.__PRELOADED_MAP__.size).toBe(0);
335329
await FMInstance.preloadRemote([
336330
{
337331
nameOrAlias: '@federation/sub3',
@@ -341,9 +335,9 @@ describe('preload-remote inBrowser', () => {
341335
]);
342336
expect(getPreloadElInfos()).toMatchSnapshot();
343337

344-
expect(globalThis.__FEDERATION__.__PRELOADED_MAP__.size).toBe(1);
338+
expect(Global.__FEDERATION__.__PRELOADED_MAP__.size).toBe(1);
345339
expect(
346-
globalThis.__FEDERATION__.__PRELOADED_MAP__.get('@federation/sub3/add'),
340+
Global.__FEDERATION__.__PRELOADED_MAP__.get('@federation/sub3/add'),
347341
).toBe(true);
348342

349343
await FMInstance.preloadRemote([

packages/runtime/src/global.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface Federation {
2424

2525
export const nativeGlobal: typeof global = (() => {
2626
try {
27-
return new Function('return this');
27+
return new Function('return this')();
2828
} catch {
2929
return globalThis;
3030
}

0 commit comments

Comments
 (0)