Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support interface data prefetch #2543

Merged
merged 65 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
cbcb5ed
feat: support data prefetch
nyqykk May 27, 2024
cf03c2e
chore: remove useless content
nyqykk May 27, 2024
582d81f
chore: merge main branch
nyqykk May 27, 2024
3dc0556
chore: add publish config for pkg
nyqykk Jun 17, 2024
f9faa8e
feat: support enable data prefetch
nyqykk Jun 17, 2024
47bcfec
chore: sync main branch
nyqykk Jun 17, 2024
666e621
feat: support rspack
nyqykk Jun 19, 2024
450f8de
chore: rename variable
nyqykk Jun 19, 2024
72b5502
fix: fix expose collect assets do not filter entry point cause load e…
nyqykk Jun 24, 2024
2f98955
Merge branch 'fix/filter-entry-point' into feat/data-prefetch
nyqykk Jun 24, 2024
1ec8046
refactor: rewrite data prefetch init code
nyqykk Jul 1, 2024
cc025b6
chore: sync main branch
nyqykk Jul 1, 2024
3ddab21
chore: add changeset
nyqykk Jul 1, 2024
96038e6
fix: fix preloadRemote error
nyqykk Jul 2, 2024
7a8d0fe
chore: remove handlePreloadModule hook
nyqykk Jul 2, 2024
426740d
docs: add docs
nyqykk Jul 29, 2024
1082eff
Revert "chore: remove handlePreloadModule hook"
nyqykk Jul 29, 2024
a77a145
chore: sync main branch
nyqykk Aug 6, 2024
4d6b49e
docs: add data prefetch doc
nyqykk Aug 6, 2024
6cf755b
docs: modify docs
nyqykk Aug 6, 2024
92ab94b
chore: update lock file
nyqykk Aug 7, 2024
f05c555
test: fix test error
nyqykk Aug 8, 2024
a8f7462
test: fix element
nyqykk Aug 8, 2024
6e6ffad
chore: update lock
nyqykk Aug 8, 2024
0ff2a8b
chore: revert modern app page.ts
nyqykk Aug 8, 2024
7f323a8
chore: remove useless code
nyqykk Aug 8, 2024
087689c
chore: compat old code
nyqykk Aug 8, 2024
020f33e
chore: sync main branch
nyqykk Sep 9, 2024
931d9c5
fix: fix type error
nyqykk Sep 9, 2024
f49116a
fix: fix afterResolve should re exec prefetch
nyqykk Sep 9, 2024
70ea356
chore: add log
nyqykk Sep 9, 2024
4fdd0e5
fix: fix type error
nyqykk Sep 9, 2024
5cf2460
fix: fix ci error
nyqykk Sep 9, 2024
1b654bd
chore: modify ci
nyqykk Sep 10, 2024
8823886
chore: sync code
nyqykk Sep 10, 2024
78d4e99
test: wait for modern project
nyqykk Sep 10, 2024
0a5cd29
chore: change prefetch runtime into build plugin
nyqykk Sep 11, 2024
cdbc572
Merge branch 'main' into feat/data-prefetch
nyqykk Sep 11, 2024
ed944f8
chore: remove useless content
nyqykk Sep 11, 2024
bd2b252
Merge branch 'feat/data-prefetch' of github.com:module-federation/uni…
nyqykk Sep 11, 2024
33da88a
chore: modify type
nyqykk Sep 11, 2024
540e388
fix: use federation global to remove globalThis
nyqykk Sep 11, 2024
d7551fe
chore: do not repeat add runtime plugin
nyqykk Sep 11, 2024
694f26d
Merge branch 'main' into feat/data-prefetch
nyqykk Sep 11, 2024
575c454
Merge branch 'main' into feat/data-prefetch
nyqykk Sep 11, 2024
b5d033c
Merge branch 'main' into feat/data-prefetch
nyqykk Sep 11, 2024
0c62502
Merge branch 'main' into feat/data-prefetch
nyqykk Sep 12, 2024
319e4c5
test: fix e2e test fail
nyqykk Sep 12, 2024
016cb9b
test: wait for modern project
nyqykk Sep 12, 2024
80f5033
test: wait for main project
nyqykk Sep 12, 2024
cce42a5
test: wait for modernjs project
nyqykk Sep 12, 2024
d5ef7de
chore: modify modernjs project config
nyqykk Sep 12, 2024
aee7330
chore: add log for ci
nyqykk Sep 12, 2024
b890f31
chore: wait for local ip
nyqykk Sep 12, 2024
c1dc6b0
chore: change tcp to http
nyqykk Sep 12, 2024
007b14e
chore: change to localhost
nyqykk Sep 12, 2024
7a3f7a3
chore: change adress
nyqykk Sep 12, 2024
7b43a7a
chore: add kill port
nyqykk Sep 12, 2024
e43936b
chore: use ip to remove localhost
nyqykk Sep 12, 2024
b9c1f85
chore: modify publich path
nyqykk Sep 12, 2024
4e1e3f8
fix: use federation name to remove user input id
nyqykk Sep 18, 2024
cb476f1
Merge branch 'main' into feat/data-prefetch
nyqykk Sep 18, 2024
da7c166
fix: add default function id for universal prefetch
nyqykk Sep 18, 2024
70c7886
test: fix test get instance error
nyqykk Sep 18, 2024
62b029d
chore: remove useless file
nyqykk Sep 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/light-items-battle.md
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
12 changes: 11 additions & 1 deletion apps/manifest-demo/3009-webpack-provider/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
{
"extends": "./tsconfig.json",
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"jsx": "react-jsx",
"allowJs": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"outDir": "../../../dist/out-tsc",
"types": [
"node",
Expand Down
31 changes: 24 additions & 7 deletions apps/manifest-demo/3009-webpack-provider/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,29 @@
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
"noFallthroughCasesInSwitch": true,
"outDir": "../../../dist/out-tsc",
"types": [
"node",
"@nx/react/typings/cssmodule.d.ts",
"@nx/react/typings/image.d.ts"
]
},
"files": [],
"references": [
{
"path": "./tsconfig.app.json"
}
]
"files": [
"../../../node_modules/@nx/react/typings/cssmodule.d.ts",
"../../../node_modules/@nx/react/typings/image.d.ts"
],
"exclude": [
"jest.config.ts",
"**/*.spec.ts",
"**/*.test.ts",
"**/*.spec.tsx",
"**/*.test.tsx",
"**/*.spec.js",
"**/*.test.js",
"**/*.spec.jsx",
"**/*.test.jsx",
"dist/**"
],
"include": ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"]
}
3 changes: 2 additions & 1 deletion apps/manifest-demo/3010-rspack-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"@rspack/plugin-react-refresh": "0.5.9"
},
"dependencies": {
"antd": "4.24.15"
"antd": "4.24.15",
"react-router-dom": "^6.23.1"
}
}
1 change: 1 addition & 0 deletions apps/manifest-demo/3010-rspack-provider/rspack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ module.exports = composePlugins(
'react-dom': {},
'react-dom/': {},
},
dataPrefetch: true,
}),
);
(config.devServer = {
Expand Down
2 changes: 2 additions & 0 deletions apps/manifest-demo/3010-rspack-provider/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import LocalButton from './Button';
import { Await } from 'react-router-dom';
console.log(Await);
nyqykk marked this conversation as resolved.
Show resolved Hide resolved
nyqykk marked this conversation as resolved.
Show resolved Hide resolved

const App = () => (
<div>
Expand Down
3 changes: 3 additions & 0 deletions apps/manifest-demo/webpack-host/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React, { Suspense, lazy } from 'react';
// @ts-ignore
import ReactComponent from 'modern-js-provider/react-component';
import TestRemoteHook from './test-remote-hook';
import { loadRemote } from '@module-federation/runtime';
import LocalBtn from './components/ButtonOldAnt';
Expand Down Expand Up @@ -29,6 +31,7 @@ const WebpackPngRemote = lazy(() => import('remote1/WebpackPng'));

const App = () => (
<div>
<ReactComponent />
<h2>Manifest Basic Usage</h2>
<h3>check static remote</h3>
<table border={1} cellPadding={5}>
Expand Down
1 change: 1 addition & 0 deletions apps/manifest-demo/webpack-host/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = composePlugins(withNx(), withReact(), (config, context) => {
'rspack_manifest_provider@http://localhost:3011/mf-manifest.json',
'js-entry-provider':
'rspack_js_entry_provider@http://localhost:3012/remoteEntry.js',
'modern-js-provider': 'app1@http://localhost:4001/mf-manifest.json',
},
filename: 'remoteEntry.js',
exposes: {
Expand Down
2 changes: 1 addition & 1 deletion apps/modernjs/cypress/e2e/app.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ describe('modernjs/', () => {

describe('Welcome message', () => {
it('should display welcome message', () => {
cy.get('.title').contains('Welcome');
cy.get('.container-box').contains('Resend request with parameters');
});
});
});
3 changes: 3 additions & 0 deletions apps/modernjs/modern.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default defineConfig({
webpack: (config, { webpack, appendPlugins }) => {
if (config?.output) {
config.output.publicPath = 'http://localhost:4001/';
config.output.uniqueName = 'modern-js-app1';
}

appendPlugins([
Expand All @@ -44,12 +45,14 @@ export default defineConfig({
name: 'app1',
exposes: {
'./thing': './src/test.ts',
'./react-component': './src/components/react-component.tsx',
},
runtimePlugins: ['./runtimePlugin.ts'],
shared: {
react: { singleton: true },
'react-dom': { singleton: true },
},
dataPrefetch: true,
}),
]);
},
Expand Down
19 changes: 19 additions & 0 deletions apps/modernjs/src/components/react-component.prefetch.ts
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);
}),
});
44 changes: 44 additions & 0 deletions apps/modernjs/src/components/react-component.tsx
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;
2 changes: 2 additions & 0 deletions apps/modernjs/src/routes/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-nocheck
import { Helmet } from '@modern-js/runtime/head';
import Component from '../components/react-component';
import './index.css';

const Index = () => (
Expand Down Expand Up @@ -87,6 +88,7 @@ const Index = () => (
</a>
</div>
</main>
<Component />
</div>
);

Expand Down
5 changes: 5 additions & 0 deletions apps/website-new/docs/en/guide/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@
"type": "dir",
"name": "framework",
"label": "Frameworks"
},
{
"type": "dir",
"name": "performance",
"label": "Performance"
}
]
1 change: 1 addition & 0 deletions apps/website-new/docs/en/guide/performance/_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["prefetch"]
Loading
Loading