Skip to content

fix(runtime): nativeGlobal is undefined #2058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fresh-baboons-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/runtime': patch
---

fix(runtime): nativeGlobal is undefined
28 changes: 11 additions & 17 deletions packages/runtime/__tests__/preload-remote.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ describe('preload-remote inBrowser', () => {
beforeEach(() => {
document.head.innerHTML = '';
document.body.innerHTML = '';
globalThis.__FEDERATION__.__PRELOADED_MAP__.clear();
Global.__FEDERATION__.__PRELOADED_MAP__.clear();
});

const FMInstance = init({
Expand Down Expand Up @@ -284,14 +284,12 @@ describe('preload-remote inBrowser', () => {
]);

expect(getPreloadElInfos()).toMatchSnapshot();
expect(globalThis.__FEDERATION__.__PRELOADED_MAP__.size).toBe(2);
expect(Global.__FEDERATION__.__PRELOADED_MAP__.size).toBe(2);
expect(
globalThis.__FEDERATION__.__PRELOADED_MAP__.get(
'@federation/sub1/button',
),
Global.__FEDERATION__.__PRELOADED_MAP__.get('@federation/sub1/button'),
).toBe(true);
expect(
globalThis.__FEDERATION__.__PRELOADED_MAP__.get(
Global.__FEDERATION__.__PRELOADED_MAP__.get(
'@federation/sub1-button/button',
),
).toBe(true);
Expand All @@ -309,29 +307,25 @@ describe('preload-remote inBrowser', () => {
]);

expect(getPreloadElInfos()).toMatchSnapshot();
expect(globalThis.__FEDERATION__.__PRELOADED_MAP__.size).toBe(3);
expect(Global.__FEDERATION__.__PRELOADED_MAP__.size).toBe(3);
expect(
globalThis.__FEDERATION__.__PRELOADED_MAP__.get(
'@federation/sub2/button',
),
Global.__FEDERATION__.__PRELOADED_MAP__.get('@federation/sub2/button'),
).toBe(true);
expect(
globalThis.__FEDERATION__.__PRELOADED_MAP__.get(
Global.__FEDERATION__.__PRELOADED_MAP__.get(
'@federation/sub2-button/button',
),
).toBe(true);
expect(
globalThis.__FEDERATION__.__PRELOADED_MAP__.get(
'@federation/sub2-add/add',
),
Global.__FEDERATION__.__PRELOADED_MAP__.get('@federation/sub2-add/add'),
).toBe(true);
reset();
});

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

expect(globalThis.__FEDERATION__.__PRELOADED_MAP__.size).toBe(0);
expect(Global.__FEDERATION__.__PRELOADED_MAP__.size).toBe(0);
await FMInstance.preloadRemote([
{
nameOrAlias: '@federation/sub3',
Expand All @@ -341,9 +335,9 @@ describe('preload-remote inBrowser', () => {
]);
expect(getPreloadElInfos()).toMatchSnapshot();

expect(globalThis.__FEDERATION__.__PRELOADED_MAP__.size).toBe(1);
expect(Global.__FEDERATION__.__PRELOADED_MAP__.size).toBe(1);
expect(
globalThis.__FEDERATION__.__PRELOADED_MAP__.get('@federation/sub3/add'),
Global.__FEDERATION__.__PRELOADED_MAP__.get('@federation/sub3/add'),
).toBe(true);

await FMInstance.preloadRemote([
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface Federation {

export const nativeGlobal: typeof global = (() => {
try {
return new Function('return this');
return new Function('return this')();
} catch {
return globalThis;
}
Expand Down