1- import type { ComponentProps , ComponentType , FunctionComponent } from 'react' ;
1+ import { ComponentProps , ComponentType , FunctionComponent } from 'react' ;
22
33import { PHASE } from '../constants' ;
44import { hash , displayNameFromId , isNodeEnvironment } from '../utils' ;
5- import type { Asset , Manifest } from '../webpack' ;
5+ import { Asset , Manifest } from '../webpack' ;
66
77import { createComponentClient } from './components/client' ;
88import { createComponentServer } from './components/server' ;
99import { createDeferred } from './deferred' ;
1010import { ClientLoader , Loader , ServerLoader } from './loader' ;
11+ import { LazyOptions , LazyComponent } from './types' ;
1112
12- export type { Asset , Manifest } ;
13-
14- export type Options = {
15- /**
16- * Whenever it should be required and rendered in SSR
17- * If false it will just render the provided fallback
18- */
19- ssr ?: boolean ;
20- /**
21- * Id of `PHASE` responsible for start loading
22- */
23- defer ?: number ;
24- /**
25- * Id of the module being imported (normally its path).
26- * It's calculated and provided by babel plugin
27- */
28- moduleId ?: string ;
29- } ;
30-
31- export type LazyComponent < C extends ComponentType < any > > = FunctionComponent <
32- ComponentProps < C >
33- > & {
34- preload : ( ) => void ;
35- getAssetUrls : ( manifest : Manifest ) => string [ ] | undefined ;
36- } ;
13+ export { Asset , Manifest , LazyOptions , LazyComponent } ;
3714
3815function lazyProxy < C extends ComponentType < any > > (
3916 loader : Loader < C > ,
40- { defer = PHASE . PAINT , moduleId = '' , ssr = true } : Options = { }
17+ { defer = PHASE . PAINT , moduleId = '' , ssr = true } : LazyOptions = { }
4118) : LazyComponent < C > {
4219 const isServer = isNodeEnvironment ( ) ;
4320 const dataLazyId = hash ( moduleId ) ;
4421
45- const LazyComponent : FunctionComponent < ComponentProps < C > > = isServer
22+ const LazyInternal : FunctionComponent < ComponentProps < C > > = isServer
4623 ? createComponentServer ( {
4724 dataLazyId,
4825 loader : loader as ServerLoader < C > ,
@@ -57,7 +34,7 @@ function lazyProxy<C extends ComponentType<any>>(
5734 ssr,
5835 } ) ;
5936
60- LazyComponent . displayName = `Lazy(${ displayNameFromId ( moduleId ) } )` ;
37+ LazyInternal . displayName = `Lazy(${ displayNameFromId ( moduleId ) } )` ;
6138
6239 const getAssetUrls = ( manifest : Manifest ) => {
6340 if ( ! manifest [ moduleId ] ) {
@@ -87,7 +64,7 @@ function lazyProxy<C extends ComponentType<any>>(
8764 head . appendChild ( link ) ;
8865 } ;
8966
90- return Object . assign ( LazyComponent , {
67+ return Object . assign ( LazyInternal , {
9168 getAssetUrls,
9269 preload,
9370 } ) ;
@@ -103,7 +80,7 @@ export const DEFAULT_OPTIONS: {
10380
10481export function lazyForPaint < C extends ComponentType < any > > (
10582 loader : Loader < C > ,
106- opts ?: Options
83+ opts ?: LazyOptions
10784) {
10885 return lazyProxy < C > ( loader , {
10986 ...DEFAULT_OPTIONS . lazyForPaint ,
@@ -113,7 +90,7 @@ export function lazyForPaint<C extends ComponentType<any>>(
11390
11491export function lazyAfterPaint < C extends ComponentType < any > > (
11592 loader : Loader < C > ,
116- opts ?: Options
93+ opts ?: LazyOptions
11794) {
11895 return lazyProxy < C > ( loader , {
11996 ...DEFAULT_OPTIONS . lazyAfterPaint ,
@@ -123,13 +100,13 @@ export function lazyAfterPaint<C extends ComponentType<any>>(
123100
124101export function lazy < C extends ComponentType < any > > (
125102 loader : Loader < C > ,
126- opts ?: Options
103+ opts ?: LazyOptions
127104) {
128105 return lazyProxy < C > ( loader , {
129106 ...DEFAULT_OPTIONS . lazy ,
130107 ...( opts || { } ) ,
131108 } ) ;
132109}
133110
134- export type { ClientLoader , Loader , ServerLoader } ;
111+ export { ClientLoader , Loader , ServerLoader } ;
135112export { LoaderError , isLoaderError } from './errors/loader-error' ;
0 commit comments