Skip to content

Commit be577f7

Browse files
committed
chore: merge main branch
2 parents 3aa965b + a50b000 commit be577f7

4 files changed

Lines changed: 482 additions & 1497 deletions

File tree

.changeset/tender-insects-agree.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): prevent components render multiple times if props change

package.json

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,23 @@
106106
"@commitlint/cz-commitlint": "19.5.0",
107107
"@fontsource/roboto": "5.1.0",
108108
"@fontsource/roboto-mono": "5.1.0",
109-
"@nx/cypress": "20.1.0",
110-
"@nx/devkit": "20.1.0",
111-
"@nx/esbuild": "20.1.0",
112-
"@nx/eslint": "20.1.0",
113-
"@nx/eslint-plugin": "20.1.0",
114-
"@nx/express": "20.1.0",
115-
"@nx/jest": "20.1.0",
116-
"@nx/js": "20.1.0",
117-
"@nx/next": "20.1.0",
118-
"@nx/node": "20.1.0",
119-
"@nx/react": "20.1.0",
120-
"@nx/rollup": "20.1.0",
121-
"@nx/rspack": "20.1.0",
122-
"@nx/storybook": "20.1.0",
123-
"@nx/vite": "20.1.0",
124-
"@nx/web": "20.1.0",
125-
"@nx/webpack": "20.1.0",
109+
"@nx/cypress": "20.1.1",
110+
"@nx/devkit": "20.1.1",
111+
"@nx/esbuild": "20.1.1",
112+
"@nx/eslint": "20.1.1",
113+
"@nx/eslint-plugin": "20.1.1",
114+
"@nx/express": "20.1.1",
115+
"@nx/jest": "20.1.1",
116+
"@nx/js": "20.1.1",
117+
"@nx/next": "20.1.1",
118+
"@nx/node": "20.1.1",
119+
"@nx/react": "20.1.1",
120+
"@nx/rollup": "20.1.1",
121+
"@nx/rspack": "20.1.1",
122+
"@nx/storybook": "20.1.1",
123+
"@nx/vite": "20.1.1",
124+
"@nx/web": "20.1.1",
125+
"@nx/webpack": "20.1.1",
126126
"@pmmmwh/react-refresh-webpack-plugin": "0.5.15",
127127
"@rollup/plugin-alias": "5.1.1",
128128
"@rollup/plugin-replace": "6.0.1",
@@ -200,7 +200,7 @@
200200
"mime-types": "2.1.35",
201201
"msw": "^1.2.1",
202202
"node-fetch": "~3.3.2",
203-
"nx": "20.1.0",
203+
"nx": "20.1.1",
204204
"open": "^10.1.0",
205205
"postcss-calc": "9.0.1",
206206
"postcss-custom-properties": "13.3.12",

packages/modernjs/src/runtime/createRemoteSSRComponent.tsx

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -143,62 +143,63 @@ export function createRemoteSSRComponent<T, E extends keyof T>(info: {
143143
? ReactKey
144144
: Parameters<T[E]>[0] & ReactKey
145145
: ReactKey;
146+
const exportName = info?.export || 'default';
146147

147-
return (props: ComponentType) => {
148-
const exportName = info?.export || 'default';
149-
const LazyComponent = React.lazy(async () => {
150-
try {
151-
const m = (await info.loader()) as Record<string, React.FC> &
152-
Record<symbol, string>;
153-
if (!m) {
154-
throw new Error('load remote failed');
155-
}
156-
const moduleId = m && m[Symbol.for('mf_module_id')];
148+
const LazyComponent = React.lazy(async () => {
149+
try {
150+
const m = (await info.loader()) as Record<string, React.FC> &
151+
Record<symbol, string>;
152+
if (!m) {
153+
throw new Error('load remote failed');
154+
}
155+
const moduleId = m && m[Symbol.for('mf_module_id')];
157156

158-
const assets = collectSSRAssets({
159-
id: moduleId,
160-
});
157+
const assets = collectSSRAssets({
158+
id: moduleId,
159+
});
161160

162-
const Com = m[exportName] as React.FC;
163-
if (exportName in m && typeof Com === 'function') {
164-
return {
165-
default: () => (
166-
<>
167-
{assets}
168-
<Com {...props} />
169-
</>
170-
),
171-
};
172-
} else {
173-
throw Error(
174-
`Make sure that ${moduleId} has the correct export when export is ${String(
175-
exportName,
176-
)}`,
177-
);
178-
}
179-
} catch (err) {
180-
if (!info.fallback) {
181-
throw err;
182-
}
183-
const FallbackFunctionComponent = info.fallback;
184-
const FallbackNode = (
185-
<FallbackFunctionComponent
186-
error={err}
187-
resetErrorBoundary={() => {
188-
console.log('SSR mode not support "resetErrorBoundary" !');
189-
}}
190-
/>
191-
);
161+
const Com = m[exportName] as React.FC;
162+
if (exportName in m && typeof Com === 'function') {
192163
return {
193-
default: () => FallbackNode,
164+
default: (props: Omit<ComponentType, 'key'>) => (
165+
<>
166+
{assets}
167+
<Com {...props} />
168+
</>
169+
),
194170
};
171+
} else {
172+
throw Error(
173+
`Make sure that ${moduleId} has the correct export when export is ${String(
174+
exportName,
175+
)}`,
176+
);
195177
}
196-
});
197-
178+
} catch (err) {
179+
if (!info.fallback) {
180+
throw err;
181+
}
182+
const FallbackFunctionComponent = info.fallback;
183+
const FallbackNode = (
184+
<FallbackFunctionComponent
185+
error={err}
186+
resetErrorBoundary={() => {
187+
console.log('SSR mode not support "resetErrorBoundary" !');
188+
}}
189+
/>
190+
);
191+
return {
192+
default: () => FallbackNode,
193+
};
194+
}
195+
});
196+
return (props: ComponentType) => {
197+
const { key, ...args } = props;
198198
return (
199199
<ErrorBoundary FallbackComponent={info.fallback}>
200200
<React.Suspense fallback={info.loading}>
201-
<LazyComponent />
201+
{/* @ts-ignore */}
202+
<LazyComponent {...args} />
202203
</React.Suspense>
203204
</ErrorBoundary>
204205
);

0 commit comments

Comments
 (0)