|
1 |
| -import React, { ReactNode, useEffect, useState } from 'react'; |
| 1 | +import React, { ReactNode } from 'react'; |
2 | 2 | import logger from './logger';
|
3 |
| -import { AwaitDataFetch, transformError } from './AwaitDataFetch'; |
| 3 | +import { AwaitDataFetch } from './AwaitDataFetch'; |
4 | 4 | import {
|
5 | 5 | fetchData,
|
6 | 6 | getDataFetchItem,
|
@@ -324,67 +324,16 @@ export function createLazyComponent<T, E extends keyof T>(
|
324 | 324 |
|
325 | 325 | return (props: ComponentType) => {
|
326 | 326 | const { key, ...args } = props;
|
327 |
| - if (globalThis.FEDERATION_SSR && !options.noSSR) { |
328 |
| - const { key, ...args } = props; |
329 | 327 |
|
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 | + ); |
389 | 338 | };
|
390 | 339 | }
|
0 commit comments