Skip to content

Commit 047857b

Browse files
jbromaScriptedAlchemy
andauthoredMar 25, 2025··
fix: snapshot handling in react-native (#3605)
Co-authored-by: Zack Jackson <25274700+ScriptedAlchemy@users.noreply.github.com>
1 parent 2bdf3ae commit 047857b

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed
 

‎.changeset/mighty-spiders-repeat.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/runtime-core': patch
3+
---
4+
5+
fix(runtime-core): check for `remoteEntry` in snapshot outside browser env

‎.changeset/silver-keys-rule.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/sdk': patch
3+
---
4+
5+
fix(sdk): stricter browser env check

‎packages/runtime-core/src/utils/tool.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
ModuleInfo,
44
RemoteEntryType,
55
isBrowserEnv,
6+
isReactNativeEnv,
67
} from '@module-federation/sdk';
78
import { Remote, RemoteInfoOptionalVersion } from '../type';
89
import { warn } from './logger';
@@ -88,7 +89,7 @@ export function getRemoteEntryInfoFromSnapshot(snapshot: ModuleInfo): {
8889
type: 'global',
8990
globalName: '',
9091
};
91-
if (isBrowserEnv()) {
92+
if (isBrowserEnv() || isReactNativeEnv()) {
9293
return 'remoteEntry' in snapshot
9394
? {
9495
url: snapshot.remoteEntry,

‎packages/sdk/src/env.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,17 @@ declare global {
66
}
77

88
function isBrowserEnv(): boolean {
9-
return typeof window !== 'undefined';
9+
return (
10+
typeof window !== 'undefined' && typeof window.document !== 'undefined'
11+
);
1012
}
13+
14+
function isReactNativeEnv(): boolean {
15+
return (
16+
typeof navigator !== 'undefined' && navigator?.product === 'ReactNative'
17+
);
18+
}
19+
1120
function isBrowserDebug() {
1221
try {
1322
if (isBrowserEnv() && window.localStorage) {
@@ -39,4 +48,4 @@ const getProcessEnv = function (): Record<string, string | undefined> {
3948
return typeof process !== 'undefined' && process.env ? process.env : {};
4049
};
4150

42-
export { isBrowserEnv, isDebugMode, getProcessEnv };
51+
export { isBrowserEnv, isReactNativeEnv, isDebugMode, getProcessEnv };

‎packages/sdk/src/generateSnapshotFromManifest.ts

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
ManifestProvider,
88
} from './types';
99
import { MANIFEST_EXT } from './constant';
10-
import { isBrowserEnv } from './env';
1110

1211
interface IOptions {
1312
remotes?: Record<string, string>;

0 commit comments

Comments
 (0)
Please sign in to comment.