-
-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support interface data prefetch (#2543)
- Loading branch information
Showing
68 changed files
with
26,661 additions
and
20,727 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@module-federation/data-prefetch': patch | ||
--- | ||
|
||
feat(@module-federation/data-prefetch): support data prefetch in Module Federation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { defer } from '@modern-js/runtime/router'; | ||
import React from 'react'; | ||
|
||
console.log(React); | ||
const defaultVal = { | ||
data: { | ||
id: 1, | ||
title: 'A Prefetch Title', | ||
}, | ||
}; | ||
|
||
export default (params = defaultVal) => | ||
defer({ | ||
userInfo: new Promise(resolve => { | ||
setTimeout(() => { | ||
resolve(params); | ||
}, 2000); | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Suspense } from 'react'; | ||
import { usePrefetch } from '@module-federation/enhanced/prefetch'; | ||
import { Await } from '@modern-js/runtime/router'; | ||
|
||
interface UserInfo { | ||
id: number; | ||
title: string; | ||
} | ||
const reFetchParams = { | ||
data: { | ||
id: 2, | ||
title: 'Another Prefetch Title', | ||
}, | ||
}; | ||
|
||
const ReactComponent = () => { | ||
const [prefetchResult, reFetchUserInfo] = usePrefetch<UserInfo>({ | ||
id: 'app1/react-component', | ||
// Optional parameters, required after using defer | ||
deferId: 'userInfo', | ||
}); | ||
|
||
return ( | ||
<> | ||
<button onClick={() => reFetchUserInfo(reFetchParams)}> | ||
Resend request with parameters | ||
</button> | ||
<Suspense fallback={<p>Loading...</p>}> | ||
<Await | ||
resolve={prefetchResult} | ||
// eslint-disable-next-line react/no-children-prop | ||
children={userInfo => ( | ||
<div> | ||
<div>{userInfo.data.id}</div> | ||
<div>{userInfo.data.title}</div> | ||
</div> | ||
)} | ||
/> | ||
</Suspense> | ||
</> | ||
); | ||
}; | ||
|
||
export default ReactComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
["prefetch"] |
Oops, something went wrong.