Skip to content

Commit 92b6fec

Browse files
Make the Next.js plugin work with strict CSP settings (#3067)
Co-authored-by: Zack Jackson <[email protected]>
1 parent ca546d8 commit 92b6fec

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

.changeset/hip-pandas-care.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@module-federation/nextjs-mf": patch
3+
---
4+
5+
Make the Next.js plugin work with strict CSP settings

packages/nextjs-mf/src/plugins/container/runtimePlugin.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ export default function (): FederationRuntimePlugin {
7272

7373
var moduleCache = args.origin.moduleCache;
7474
var name = args.origin.name;
75-
var gs = new Function('return globalThis')();
75+
var gs;
76+
try {
77+
gs = new Function('return globalThis')();
78+
} catch (e) {
79+
gs = globalThis; // fallback for browsers without 'unsafe-eval' CSP policy enabled
80+
}
7681
var attachedRemote = gs[name];
7782
if (attachedRemote) {
7883
moduleCache.set(name, attachedRemote);

0 commit comments

Comments
 (0)