Skip to content

Commit f5565c7

Browse files
committed
fix: use the same loader
1 parent eb0d1dc commit f5565c7

File tree

1 file changed

+12
-63
lines changed

1 file changed

+12
-63
lines changed

packages/bridge/bridge-react/src/lazy/createLazyComponent.tsx

Lines changed: 12 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React, { ReactNode, useEffect, useState } from 'react';
1+
import React, { ReactNode } from 'react';
22
import logger from './logger';
3-
import { AwaitDataFetch, transformError } from './AwaitDataFetch';
3+
import { AwaitDataFetch } from './AwaitDataFetch';
44
import {
55
fetchData,
66
getDataFetchItem,
@@ -324,67 +324,16 @@ export function createLazyComponent<T, E extends keyof T>(
324324

325325
return (props: ComponentType) => {
326326
const { key, ...args } = props;
327-
if (globalThis.FEDERATION_SSR && !options.noSSR) {
328-
const { key, ...args } = props;
329327

330-
return (
331-
<AwaitDataFetch
332-
resolve={getData(options.noSSR)}
333-
loading={options.loading}
334-
errorElement={options.fallback}
335-
>
336-
{/* @ts-ignore */}
337-
{(data) => <LazyComponent {...args} mfData={data} />}
338-
</AwaitDataFetch>
339-
);
340-
} else {
341-
// Client-side rendering logic
342-
const [data, setData] = useState<unknown>(null);
343-
const [loading, setLoading] = useState<boolean>(true);
344-
const [error, setError] = useState<ErrorInfo | null>(null);
345-
346-
useEffect(() => {
347-
let isMounted = true;
348-
const fetchDataAsync = async () => {
349-
try {
350-
setLoading(true);
351-
const result = await getData(options.noSSR);
352-
if (isMounted) {
353-
setData(result);
354-
}
355-
} catch (e: any) {
356-
if (isMounted) {
357-
setError(transformError(e));
358-
}
359-
} finally {
360-
if (isMounted) {
361-
setLoading(false);
362-
}
363-
}
364-
};
365-
366-
fetchDataAsync();
367-
368-
return () => {
369-
isMounted = false;
370-
};
371-
}, []);
372-
373-
if (loading) {
374-
return <>{options.loading}</>;
375-
}
376-
377-
if (error) {
378-
return (
379-
<>
380-
{typeof options.fallback === 'function'
381-
? options.fallback(error)
382-
: options.fallback}
383-
</>
384-
);
385-
}
386-
// @ts-ignore
387-
return <LazyComponent {...args} mfData={data} />;
388-
}
328+
return (
329+
<AwaitDataFetch
330+
resolve={getData(options.noSSR)}
331+
loading={options.loading}
332+
errorElement={options.fallback}
333+
>
334+
{/* @ts-ignore */}
335+
{(data) => <LazyComponent {...args} mfData={data} />}
336+
</AwaitDataFetch>
337+
);
389338
};
390339
}

0 commit comments

Comments
 (0)