Skip to content

Commit d3d8003

Browse files
fix(nextjs-mf): deprecate utils use (#2234)
Co-authored-by: ScriptedAlchemy <[email protected]>
1 parent 3029365 commit d3d8003

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

.changeset/great-radios-check.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+
deprecate injectScript and module-federation/utilities usage

packages/nextjs-mf/README.md

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,12 @@ new NextFederationPlugin({
165165
extraOptions: {
166166
debug: boolean, // `false` by default
167167
exposePages: boolean, // `false` by default
168-
enableImageLoaderFix: boolean, // `false` by default
169-
enableUrlLoaderFix: boolean, // `false` by default
170-
skipSharingNextInternals: boolean, // `false` by default
171168
},
172169
});
173170
```
174171

175172
- `debug` – enables debug mode. It will print additional information about what is going on under the hood.
176173
- `exposePages` – exposes automatically all nextjs pages for you and theirs `./pages-map`.
177-
- `enableImageLoaderFix` – adds public hostname to all assets bundled by `nextjs-image-loader`. So if you serve remoteEntry from `http://example.com` then all bundled assets will get this hostname in runtime. It's something like Base URL in HTML but for federated modules.
178-
- `enableUrlLoaderFix` – adds public hostname to all assets bundled by `url-loader`.
179-
- `skipSharingNextInternals` – disables sharing of next internals. You can use it if you want to share next internals yourself or want to use this plugin on non next applications
180174

181175
## Demo
182176

@@ -273,22 +267,23 @@ new NextFederationPlugin({
273267

274268
Ive added a util for dynamic chunk loading, in the event you need to load remote containers dynamically.
275269

276-
**InjectScript**
277270

278271
```js
279-
import { injectScript } from '@module-federation/nextjs-mf/utils';
272+
import { loadRemote, init } from '@module-federation/runtime';
280273
// if i have remotes in my federation plugin, i can pass the name of the remote
281-
injectScript('home').then((remoteContainer) => {
282-
remoteContainer.get('./exposedModule');
283-
});
274+
loadRemote('home/exposedModule')
284275
// if i want to load a custom remote not known at build time.
285-
286-
injectScript({
287-
global: 'home',
288-
url: 'http://somthing.com/remoteEntry.js',
289-
}).then((remoteContainer) => {
290-
remoteContainer.get('./exposedModule');
291-
});
276+
init({
277+
name: 'hostname',
278+
remotes: [
279+
{
280+
name: 'home',
281+
entry: 'http://somthing.com/remoteEntry.js'
282+
}
283+
],
284+
force: true // may be needed to sideload remotes after the fact.
285+
})
286+
loadRemote('home/exposedModule')
292287
```
293288

294289
**revalidate**
@@ -305,14 +300,10 @@ import { revalidate } from '@module-federation/nextjs-mf/utils';
305300
import Document, { Html, Head, Main, NextScript } from 'next/document';
306301
class MyDocument extends Document {
307302
static async getInitialProps(ctx) {
308-
const initialProps = await Document.getInitialProps(ctx);
309-
310-
// can be any lifecycle or implementation you want
311-
ctx?.res?.on('finish', () => {
312-
revalidate().then((shouldUpdate) => {
313-
console.log('finished sending response', shouldUpdate);
314-
});
303+
await revalidate().then((shouldUpdate) => {
304+
console.log('finished sending response', shouldUpdate);
315305
});
306+
const initialProps = await Document.getInitialProps(ctx);
316307

317308
return initialProps;
318309
}

packages/nextjs-mf/utils/index.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
import * as deadUtils from '@module-federation/utilities';
2+
13
/**
24
* Extracts the URL and global from the module federation utilities.
35
* @module @module-federation/utilities/src/utils/pure
46
*/
57
export { extractUrlAndGlobal } from '@module-federation/utilities';
68

7-
/**
8-
* Injects a script from the module federation utilities.
9-
* @module @module-federation/utilities/src/utils/common
10-
*/
11-
export { injectScript } from '@module-federation/utilities';
9+
//@ts-ignore
10+
export const injectScript = (args) => {
11+
console.warn(
12+
'injectScript is deprecated, use module-federation/runtime and loadRemote',
13+
);
14+
return deadUtils.injectScript(args);
15+
};
1216

1317
/**
1418
* Flushes chunks from the module federation node utilities.

0 commit comments

Comments
 (0)