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

[WIP] Support RSC #6460

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
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: 3 additions & 2 deletions examples/basic-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
"@types/react-dom": "^18.0.2",
"speed-measure-webpack-plugin": "^1.5.0",
"webpack": "^5.86.0"
}
}
},
"repository": "[email protected]:alibaba/ice.git"
}
2 changes: 2 additions & 0 deletions examples/rsc-project/.browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
defaults
ios_saf 9
21 changes: 21 additions & 0 deletions examples/rsc-project/ice.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { defineConfig } from '@ice/app';
import auth from '@ice/plugin-auth';
import SpeedMeasurePlugin from 'speed-measure-webpack-plugin';

export default defineConfig(() => ({
publicPath: '/',
webpack: (webpackConfig) => {
if (process.env.NODE_ENV !== 'test') {
webpackConfig.plugins?.push(new SpeedMeasurePlugin());
}
return webpackConfig;
},
dropLogLevel: 'warn',
plugins: [
auth(),
],
eslint: true,
ssr: false,
ssg: false,
rsc: true,
}));
32 changes: 32 additions & 0 deletions examples/rsc-project/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@examples/basic-project",
"version": "1.0.0",
"private": true,
"scripts": {
"start": "ice start",
"build": "ice build",
"serve": "tsx server.mts"
},
"description": "",
"author": "",
"license": "MIT",
"dependencies": {
"@ice/app": "workspace:*",
"@ice/plugin-auth": "workspace:*",
"@ice/runtime": "workspace:*",
"antd-mobile": "^5.12.6",
"compression": "^1.7.4",
"react": "^18.3.0-canary-1cea38448-20230530",
"react-dom": "^18.3.0-canary-1cea38448-20230530",
"react-server-dom-webpack": "^18.3.0-canary-1cea38448-20230530",
"react-router-dom": "6.11.2"
},
"devDependencies": {
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"speed-measure-webpack-plugin": "^1.5.0",
"webpack": "^5.86.0",
"tslib": "^2.5.0",
"tsx": "^3.12.1"
}
}
17 changes: 17 additions & 0 deletions examples/rsc-project/src/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use client';
import { defineAppConfig } from 'ice';
import { defineAuthConfig } from '@ice/plugin-auth/types';

console.log('__LOG__');
console.warn('__WARN__');
console.error('__ERROR__');

export const authConfig = defineAuthConfig(() => {
return {
initialAuth: {
admin: true,
},
};
});

export default defineAppConfig(() => ({}));
8 changes: 8 additions & 0 deletions examples/rsc-project/src/components/bar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use client';
export default function Bar() {
return (
<div>
bar
</div>
);
}
28 changes: 28 additions & 0 deletions examples/rsc-project/src/document.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use client';

import { DocumentClientBody, DocumentClientHead } from './documentClient';
// import RscServerRouter from './rscServerRouter';

// import { Meta, Title, Links, Main, Scripts } from 'ice';

function Document(props) {
return (
<html>
<head>
<meta charSet="utf-8" />
<meta name="description" content="ICE Demo" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<DocumentClientHead />
</head>
<body>
<DocumentClientBody />
</body>
</html>
// <>
// <DocumentClientHead />
// <DocumentClientBody />
// </>
);
}

export default Document;
22 changes: 22 additions & 0 deletions examples/rsc-project/src/documentClient.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use client';
import { Meta, Title, Links, Main, Scripts } from 'ice';

export function DocumentClientHead() {
return (
<>
<Meta />
<Title />
<Links />
</>
);
}

export function DocumentClientBody() {
return (
<>
<Main />
<Scripts />
</>
);
}

56 changes: 56 additions & 0 deletions examples/rsc-project/src/pages/about.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'use client';
// @ts-expect-error
import { Link, useData, useConfig, definePageConfig, defineDataLoader } from 'ice';
import url from './ice.png';
import Blog from './blog';

interface Data {
name: string;
}

export default function About() {
const data = useData<Data>();
const config = useConfig();

console.log('render About', 'data', data, 'config', config);

return (
<>
<h2>About Page</h2>
<Link to="/">home</Link><br />
<Link to="/blog">blog</Link>
<img src={url} height="40" width="40" />
<span className="mark">new</span>
</>
);
}

export const pageConfig = definePageConfig(() => {
return {
title: 'About',
meta: [
{
name: 'theme-color',
content: '#eee',
},
],
links: [{
href: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css',
rel: 'stylesheet',
}],
scripts: [{
src: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/lodash.min.js',
}],
auth: ['admin'],
};
});

export const dataLoader = defineDataLoader(() => {
return new Promise((resolve) => {
setTimeout(() => {
resolve({
name: 'About',
});
}, 1 * 100);
});
});
27 changes: 27 additions & 0 deletions examples/rsc-project/src/pages/blog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use client';
import { Link, useData, useConfig, definePageConfig } from 'ice';

interface Data {
name: string;
}

export default function Blog() {
const data = useData<Data>();
const config = useConfig();

console.log('render Blog', 'data', data, 'config', config);

return (
<>
<h2>Blog Page</h2>
<Link to="/">home</Link>
</>
);
}

export const pageConfig = definePageConfig(() => {
return {
title: 'Blog',
auth: ['guest'],
};
});
Binary file added examples/rsc-project/src/pages/ice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions examples/rsc-project/src/pages/index.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.title {
color: red;
}
58 changes: 58 additions & 0 deletions examples/rsc-project/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
'use client';
import { Suspense } from 'react';
import { Link, useData, useConfig, definePageConfig, defineDataLoader } from 'ice';
// Not recommended but works.
import styles from './index.module.css';
// import { Button } from 'antd-mobile';

// const Bar = lazy(() => import('../components/bar'));

export default function Home() {
// console.log('render Home', props);

// const appContext = useAppContext();
// console.log('get AppContext', appContext);

const data = useData();
const config = useConfig();

console.log('render Home', 'data', data, 'config', config);

return (
<>
<h2 className={styles.title}>Home Page</h2>
<Link to="/about">about</Link>
<Suspense fallback={<div>hello</div>}>
{/* <Bar /> */}
{/* <Button onClick={() => alert('Hello ICE.')}>Click Me</Button> */}
</Suspense>
</>
);
}

export const pageConfig = definePageConfig(() => {
return {
title: 'Home',
meta: [
{
name: 'theme-color',
content: '#000',
},
{
name: 'title-color',
content: '#f00',
},
],
auth: ['admin'],
};
});

export const dataLoader = defineDataLoader(() => {
return new Promise((resolve) => {
setTimeout(() => {
resolve({
name: 'Home',
});
}, 1 * 100);
});
});
39 changes: 39 additions & 0 deletions examples/rsc-project/src/pages/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use client';
import { Outlet, useData, useConfig, definePageConfig, defineDataLoader } from 'ice';

export default () => {
const data = useData();
const config = useConfig();

console.log('render Layout', 'data', data, 'config', config);

return (
<div>
<h1>Layout</h1>
<Outlet />
</div>
);
};

export const pageConfig = definePageConfig(() => {
return {
title: 'Layout',
meta: [
{
name: 'layout-color',
content: '#f00',
},
],
auth: ['admin'],
};
});

export const dataLoader = defineDataLoader(() => {
return new Promise((resolve) => {
setTimeout(() => {
resolve({
layout: true,
});
}, 1 * 100);
});
});
Loading