Skip to content

Commit 07388ce

Browse files
committed
refactor: adjust extend api
1 parent b1743a8 commit 07388ce

File tree

28 files changed

+334
-269
lines changed

28 files changed

+334
-269
lines changed

apps/modern-component-data-fetch/host/src/routes/basic/page.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import { getInstance } from '@module-federation/modern-js/runtime';
2-
import {
3-
createLazyComponent,
4-
ERROR_TYPE,
5-
} from '@module-federation/modern-js/react';
2+
import { ERROR_TYPE } from '@module-federation/modern-js/react';
63

7-
const Basic = createLazyComponent({
8-
instance: getInstance(),
4+
const Basic = getInstance()!.createLazyComponent({
95
loader: () => {
106
return import('remote/BasicComponent');
117
},

apps/modern-component-data-fetch/host/src/routes/client-downgrade/page.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { getInstance } from '@module-federation/modern-js/runtime';
2-
import { createLazyComponent } from '@module-federation/modern-js/react';
32

4-
const ClientDowngrade = createLazyComponent({
5-
instance: getInstance(),
3+
const ClientDowngrade = getInstance()!.createLazyComponent({
64
loader: () => {
75
return import('remote/ClientDowngrade');
86
},

apps/modern-component-data-fetch/host/src/routes/csr/page.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import { getInstance } from '@module-federation/modern-js/runtime';
2-
import {
3-
createLazyComponent,
4-
wrapNoSSR,
5-
} from '@module-federation/modern-js/react';
2+
import { NoSSR } from '@modern-js/runtime/ssr';
63

7-
const CsrWithFetchDataFromServerComponent = wrapNoSSR(createLazyComponent)({
8-
instance: getInstance(),
4+
const CsrWithFetchDataFromServerComponent = getInstance()!.createLazyComponent({
95
loader: () => {
106
return import('provider-csr');
117
},
@@ -26,7 +22,9 @@ const Index = (): JSX.Element => {
2622
<h1>
2723
The component will be render in csr but <i>fetch data from server</i>
2824
</h1>
29-
<CsrWithFetchDataFromServerComponent />
25+
<NoSSR>
26+
<CsrWithFetchDataFromServerComponent />
27+
</NoSSR>
3028
</div>
3129
);
3230
};

apps/modern-component-data-fetch/host/src/routes/layout.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@ import React from 'react';
22
import { Outlet, useNavigate, useLocation } from '@modern-js/runtime/router';
33
import { Layout, Menu } from 'antd';
44
import { getInstance } from '@module-federation/modern-js/runtime';
5-
import { prefetch } from '@module-federation/modern-js/react';
5+
import { lazyLoadComponentPlugin } from '@module-federation/modern-js/react';
66

7+
getInstance()!.registerPlugins([lazyLoadComponentPlugin()]);
78
console.log('layout');
8-
prefetch({
9+
getInstance()!.prefetch({
910
id: 'remote/BasicComponent',
10-
instance: getInstance(),
1111
});
1212

13-
prefetch({
13+
getInstance()!.prefetch({
1414
id: 'provider-csr',
15-
instance: getInstance(),
1615
});
1716

1817
const { Header, Content } = Layout;

apps/modern-component-data-fetch/host/src/routes/server-downgrade/page.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { getInstance } from '@module-federation/modern-js/runtime';
2-
import { createLazyComponent } from '@module-federation/modern-js/react';
32

4-
const ServerDowngrade = createLazyComponent({
5-
instance: getInstance(),
3+
const ServerDowngrade = getInstance()!.createLazyComponent({
64
loader: () => {
75
return import('remote/ServerDowngrade');
86
},

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@ import {
55
registerRemotes,
66
loadRemote,
77
} from '@module-federation/modern-js/runtime';
8-
import { createLazyComponent } from '@module-federation/modern-js/react';
8+
import { lazyLoadComponentPlugin } from '@module-federation/modern-js/react';
99
import stuff from './stuff.module.css';
1010

11+
getInstance()!.registerPlugins([lazyLoadComponentPlugin()]);
12+
1113
registerRemotes([
1214
{
1315
name: 'dynamic_remote',
1416
entry: 'http://localhost:3053/mf-manifest.json',
1517
},
1618
]);
1719

18-
const RemoteSSRComponent = createLazyComponent({
19-
instance: getInstance(),
20+
const RemoteSSRComponent = getInstance()!.createLazyComponent({
2021
loader: () => loadRemote('dynamic_remote'),
2122
loading: 'loading...',
2223
fallback: ({ error }) => {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
loadRemote,
55
registerRemotes,
66
} from '@module-federation/modern-js/runtime';
7-
import { createLazyComponent } from '@module-federation/modern-js/react';
87

98
registerRemotes([
109
{
@@ -13,8 +12,7 @@ registerRemotes([
1312
},
1413
]);
1514

16-
const RemoteSSRComponent = createLazyComponent({
17-
instance: getInstance(),
15+
const RemoteSSRComponent = getInstance()!.createLazyComponent({
1816
loader: () => loadRemote('dynamic_remote'),
1917
loading: 'loading...',
2018
fallback: ({ error }) => {

apps/modernjs-ssr/host/src/routes/layout.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import React from 'react';
22
import { Outlet, useNavigate } from '@modern-js/runtime/router';
33
import { Layout, Menu } from 'antd';
4-
4+
import { lazyLoadComponentPlugin } from '@module-federation/modern-js/react';
5+
import { getInstance } from '@module-federation/modern-js/runtime';
56
const { Header, Content } = Layout;
67

8+
getInstance()!.registerPlugins([lazyLoadComponentPlugin()]);
79
const App: React.FC = () => {
810
const navi = useNavigate();
911

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { getInstance } from '@module-federation/modern-js/runtime';
2-
import { createLazyComponent } from '@module-federation/modern-js/react';
2+
import { lazyLoadComponentPlugin } from '@module-federation/modern-js/react';
33

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

7-
const RemoteSSRComponent = createLazyComponent({
8-
instance: getInstance(),
7+
getInstance()!.registerPlugins([lazyLoadComponentPlugin()]);
8+
9+
const RemoteSSRComponent = getInstance()!.createLazyComponent({
910
loader: () => import('remote/Button'),
1011
loading: 'loading...',
1112
export: 'Button',

packages/bridge/bridge-react/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@
5050
"import": "./dist/router-v6.es.js",
5151
"require": "./dist/router-v6.cjs.js"
5252
},
53-
"./data-fetch-runtime-plugin": {
54-
"types": "./dist/data-fetch-runtime-plugin.d.ts",
55-
"import": "./dist/data-fetch-runtime-plugin.es.js",
56-
"require": "./dist/data-fetch-runtime-plugin.cjs.js"
57-
},
5853
"./lazy-utils": {
5954
"types": "./dist/lazy-utils.d.ts",
6055
"import": "./dist/lazy-utils.es.js",
@@ -70,15 +65,20 @@
7065
"import": "./dist/data-fetch-server-middleware.es.js",
7166
"require": "./dist/data-fetch-server-middleware.cjs.js"
7267
},
68+
"./lazy-load-component-plugin": {
69+
"types": "./dist/lazy-load-component-plugin.d.ts",
70+
"import": "./dist/lazy-load-component-plugin.es.js",
71+
"require": "./dist/lazy-load-component-plugin.cjs.js"
72+
},
7373
"./*": "./*"
7474
},
7575
"typesVersions": {
7676
"*": {
7777
".": [
7878
"./dist/types/index.d.ts"
7979
],
80-
"data-fetch-runtime-plugin": [
81-
"./dist/lazy-utils.d.ts"
80+
"lazy-load-component-plugin": [
81+
"./dist/lazy-load-component-plugin.d.ts"
8282
],
8383
"lazy-utils": [
8484
"./dist/lazy-utils.d.ts"

0 commit comments

Comments
 (0)