Skip to content

Commit b99d57c

Browse files
authored
fix(modern-js-plugin): export kit namespace to prevent import react directly (#3731)
1 parent 129dac6 commit b99d57c

File tree

17 files changed

+59
-38
lines changed

17 files changed

+59
-38
lines changed

.changeset/many-emus-shave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/modern-js': patch
3+
---
4+
5+
fix(modern-js-plugin): export kit namespace to prevent import react directly

apps/modernjs-ssr/dynamic-nested-remote/src/components/Content.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import Button from 'antd/lib/button';
33
import {
44
registerRemotes,
55
loadRemote,
6-
createRemoteSSRComponent,
7-
} from '@modern-js/runtime/mf';
6+
kit,
7+
} from '@module-federation/modern-js/runtime';
88
import stuff from './stuff.module.css';
99

10+
const { createRemoteSSRComponent } = kit;
11+
1012
registerRemotes([
1113
{
1214
name: 'dynamic_remote',

apps/modernjs-ssr/host/src/routes/all/page.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import React, { Suspense } from 'react';
2-
import { loadRemote, registerRemotes } from '@modern-js/runtime/mf';
2+
import {
3+
loadRemote,
4+
registerRemotes,
5+
} from '@module-federation/modern-js/runtime';
36

47
registerRemotes([
58
{

apps/modernjs-ssr/host/src/routes/dynamic-nested-remote/page.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import React from 'react';
2-
import { loadRemote, registerRemotes } from '@modern-js/runtime/mf';
2+
import {
3+
loadRemote,
4+
registerRemotes,
5+
} from '@module-federation/modern-js/runtime';
36

47
registerRemotes([
58
{

apps/modernjs-ssr/host/src/routes/dynamic-remote/page.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import React, { useState, Suspense } from 'react';
22
import {
33
loadRemote,
44
registerRemotes,
5-
createRemoteSSRComponent,
6-
} from '@modern-js/runtime/mf';
5+
kit,
6+
} from '@module-federation/modern-js/runtime';
7+
8+
const { createRemoteSSRComponent } = kit;
79

810
registerRemotes([
911
{

apps/modernjs-ssr/host/src/routes/remote/page.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import React, { useState, Suspense } from 'react';
22
import Comp from 'remote/Image';
3-
import { registerRemotes, loadRemote } from '@modern-js/runtime/mf';
3+
import {
4+
registerRemotes,
5+
loadRemote,
6+
} from '@module-federation/modern-js/runtime';
47

58
const NewRemoteCom = React.lazy(() =>
69
loadRemote('remote/Image').then((m) => {

apps/modernjs-ssr/nested-remote/src/routes/page.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { createRemoteSSRComponent } from '@modern-js/runtime/mf';
1+
import { kit } from '@module-federation/modern-js/runtime';
22

33
import Content from '../components/Content';
44
import './index.css';
55

6+
const { createRemoteSSRComponent } = kit;
7+
68
const RemoteSSRComponent = createRemoteSSRComponent({
79
loader: () => import('remote/Button'),
810
loading: 'loading...',

apps/website-new/docs/en/guide/framework/modernjs.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ This function will also help inject the corresponding style tag/script while loa
112112

113113
```tsx
114114
import React, { FC, memo, useEffect } from 'react';
115-
import { registerRemotes, createRemoteSSRComponent } from '@modern-js/runtime/mf';
115+
import { registerRemotes, kit } from '@module-federation/modern-js/runtime';
116116
// The remote declared in the build plug-in can be imported directly at the top level
117117
import RemoteComp from 'remote/Image';
118118

119+
const { createRemoteSSRComponent } = kit;
119120

120121
const RemoteSSRComponent = createRemoteSSRComponent({
121122
// The remote declared in the build plug-in can also be loaded using this function: loader: () => import('remote/Image'),

apps/website-new/docs/en/practice/frameworks/modern/dynamic-remote.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,15 @@ export const loader = async ({ request }: LoaderFunctionArgs): Promise<DataLoade
147147
Consume loader data and dynamically load the corresponding producer:
148148

149149
```tsx
150-
import { createRemoteSSRComponent, loadRemote, registerRemotes } from '@modern-js/runtime/mf';
150+
import { kit, loadRemote, registerRemotes } from '@module-federation/modern-js/runtime';
151151
// Use import type to get data loader types
152152
import type { DataLoaderRes } from './page.data';
153153
import { useLoaderData } from '@modern-js/runtime/router';
154154

155155
import './index.css';
156156

157+
const { createRemoteSSRComponent } = kit;
158+
157159
const RemoteSSRComponent = createRemoteSSRComponent({
158160
loader: () => import('remote/Image'),
159161
loading: 'loading...',

apps/website-new/docs/en/practice/frameworks/modern/index.mdx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,6 @@ export default defineConfig({
217217
```
218218
#### 3. Type hint
219219

220-
Add `/// <reference types='@module-federation/modern-js/types' />` to the `modern-app-env.d.ts` file to get the runtime `@modern-js/runtime/mf` type support.
221-
222-
```diff title='modern-app-env.d.ts'
223-
+ /// <reference types='@module-federation/modern-js/types' />
224-
```
225-
226220
Add `paths` in `tsconfig.json` to get the producer's type:
227221

228222
```json
@@ -260,9 +254,11 @@ This is because the producer's style files cannot be injected into the correspon
260254
This issue can be solved by using the [createremotessrcomponent](../../../guide/framework/modernjs#createremotessrcomponent) provided by `@module-federation/modern-js`.
261255

262256
```tsx title='page.tsx'
263-
import { createRemoteSSRComponent } from '@modern-js/runtime/mf'
257+
import { kit } from '@module-federation/modern-js/runtime'
264258
import './index.css';
265259

260+
const { createRemoteSSRComponent } = kit;
261+
266262
const RemoteSSRComponent = createRemoteSSRComponent({
267263
loader: () => import('remote/Image'),
268264
loading: 'loading...',

0 commit comments

Comments
 (0)