Skip to content

Commit 7f67062

Browse files
committed
chore: pass instance instead of runtime
1 parent 52781fc commit 7f67062

File tree

15 files changed

+52
-56
lines changed

15 files changed

+52
-56
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import { getInstance } from '@module-federation/modern-js/runtime';
12
import {
23
createLazyComponent,
34
ERROR_TYPE,
45
} from '@module-federation/modern-js/react';
56

67
const Basic = createLazyComponent({
8+
instance: getInstance(),
79
loader: () => {
810
return import('remote/BasicComponent');
911
},

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

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

34
const ClientDowngrade = createLazyComponent({
5+
instance: getInstance(),
46
loader: () => {
57
return import('remote/ClientDowngrade');
68
},

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import { getInstance } from '@module-federation/modern-js/runtime';
12
import {
23
createLazyComponent,
34
wrapNoSSR,
45
} from '@module-federation/modern-js/react';
56

67
const CsrWithFetchDataFromServerComponent = wrapNoSSR(createLazyComponent)({
8+
instance: getInstance(),
79
loader: () => {
810
return import('provider-csr');
911
},

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

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

34
const ServerDowngrade = createLazyComponent({
5+
instance: getInstance(),
46
loader: () => {
57
return import('remote/ServerDowngrade');
68
},

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import Button from 'antd/lib/button';
33
import {
4+
getInstance,
45
registerRemotes,
56
loadRemote,
67
} from '@module-federation/modern-js/runtime';
@@ -15,6 +16,7 @@ registerRemotes([
1516
]);
1617

1718
const RemoteSSRComponent = createLazyComponent({
19+
instance: getInstance(),
1820
loader: () => loadRemote('dynamic_remote'),
1921
loading: 'loading...',
2022
fallback: ({ error }) => {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useState, Suspense } from 'react';
22
import {
3+
getInstance,
34
loadRemote,
45
registerRemotes,
56
} from '@module-federation/modern-js/runtime';
@@ -13,6 +14,7 @@ registerRemotes([
1314
]);
1415

1516
const RemoteSSRComponent = createLazyComponent({
17+
instance: getInstance(),
1618
loader: () => loadRemote('dynamic_remote'),
1719
loading: 'loading...',
1820
fallback: ({ error }) => {

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

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

34
import Content from '../components/Content';
45
import './index.css';
56

67
const RemoteSSRComponent = createLazyComponent({
8+
instance: getInstance(),
79
loader: () => import('remote/Button'),
810
loading: 'loading...',
911
export: 'Button',

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,11 @@ export default Index;
194194
In the consumer, we need to use `createLazyComponent` to load the remote component and fetch data.
195195

196196
```tsx
197+
import { getInstance } from '@module-federation/modern-js/runtime';
197198
import { createLazyComponent, ERROR_TYPE } from '@module-federation/modern-js/react';
198199

199200
const List = createLazyComponent({
201+
instance: getInstance(),
200202
loader: () => {
201203
return import('remote/List');
202204
},
@@ -302,7 +304,7 @@ In addition to exporting [MF Runtime](../basic/runtime), `@module-federation/mod
302304
To prevent conflicts with Shared modules, you need to import them as follows:
303305

304306
```ts
305-
import { loadRemote } from '@module-federation/modern-js/runtime';
307+
import { loadRemote, getInstance } from '@module-federation/modern-js/runtime';
306308
import { createLazyComponent, wrapNoSSR } from '@module-federation/modern-js/react';
307309
```
308310

@@ -317,6 +319,7 @@ declare function createLazyComponent(
317319
): (props: ComponentType) => React.JSX.Element;
318320

319321
type CreateLazyComponentOptions<T, E extends keyof T> = {
322+
instance: ReturnType<typeof getInstance>;
320323
loader: () => Promise<T>;
321324
loading: React.ReactNode;
322325
fallback: ReactNode | ((errorInfo: ErrorInfo) => ReactNode);
@@ -351,9 +354,11 @@ This function supports loading components and also provides the following capabi
351354

352355
```tsx
353356
import React, { FC, memo, useEffect } from 'react';
357+
import { getInstance } from '@module-federation/modern-js/runtime';
354358
import { createLazyComponent, ERROR_TYPE } from '@module-federation/modern-js/react';
355359

356360
const LazyComponent = createLazyComponent({
361+
instance: getInstance(),
357362
loader: () => import('remote/Image'),
358363
loading: <div>loading...</div>,
359364
fallback: ({error,errorType,dataFetchMapKey}) => {
@@ -431,9 +436,11 @@ Wraps a component so that it does not render in SSR scenarios.
431436
Usage example:
432437

433438
```tsx
439+
import { getInstance } from '@module-federation/modern-js/runtime';
434440
import { createLazyComponent, wrapNoSSR } from '@module-federation/modern-js/react';
435441
436442
const LazyComponent = wrapNoSSR(createLazyComponent)({
443+
instance: getInstance(),
437444
loader: () => {
438445
return import('remote/Content');
439446
},

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,7 +147,7 @@ export const loader = async ({ request }: LoaderFunctionArgs): Promise<DataLoade
147147
Consume loader data and dynamically load the corresponding producer:
148148

149149
```tsx
150-
import { loadRemote, registerRemotes } from '@module-federation/modern-js/runtime';
150+
import { loadRemote, registerRemotes, getInstance } from '@module-federation/modern-js/runtime';
151151
import { createLazyComponent } from '@module-federation/modern-js/react';
152152
// Use import type to get data loader types
153153
import type { DataLoaderRes } from './page.data';
@@ -156,6 +156,7 @@ import { useLoaderData } from '@modern-js/runtime/router';
156156
import './index.css';
157157

158158
const RemoteSSRComponent = createLazyComponent({
159+
instance: getInstance(),
159160
loader: () => import('remote/Image'),
160161
loading: 'loading...',
161162
export: 'default',
@@ -176,6 +177,7 @@ const Index = () => {
176177
const DynamicRemoteSSRComponents = dataLoader.providerList.map(item => {
177178
const { id } = item;
178179
const Com = createLazyComponent({
180+
instance: getInstance(),
179181
loader: () => loadRemote(id),
180182
loading: 'loading...',
181183
fallback: ({ error }) => {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,12 @@ This is because the producer's style files cannot be injected into the correspon
254254
This issue can be solved by using the [createremotessrcomponent](../../../guide/framework/modernjs#createremotessrcomponent) provided by `@module-federation/modern-js`.
255255

256256
```tsx title='page.tsx'
257+
import { getInstance } from '@module-federation/modern-js/runtime';
257258
import { createLazyComponent } from '@module-federation/modern-js/react'
258259
import './index.css';
259260

260261
const RemoteSSRComponent = createLazyComponent({
262+
instance: getInstance(),
261263
loader: () => import('remote/Image'),
262264
loading: 'loading...',
263265
export: 'default',

0 commit comments

Comments
 (0)