Skip to content

Commit

Permalink
Merge pull request #4067 from alibaba/release-next
Browse files Browse the repository at this point in the history
Release/1.15.2
  • Loading branch information
SoloJiang authored Jan 28, 2021
2 parents 39ec797 + 1343838 commit 1d428d0
Show file tree
Hide file tree
Showing 28 changed files with 639 additions and 377 deletions.
1 change: 0 additions & 1 deletion examples/basic-mpa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "exmaple-basic-mpa",
"description": "",
"dependencies": {
"ice.js": "^1.0.11",
"react": "^16.4.1",
"react-dom": "^16.4.1"
},
Expand Down
18 changes: 15 additions & 3 deletions examples/basic-ssr-with-lazy-load/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import { runApp, IAppConfig, config, request } from 'ice';
import { runApp, IAppConfig, config } from 'ice';
import React from 'react';

const delay = (time) => new Promise<void>((resolve) => setTimeout(() => resolve(), time));

const appConfig: IAppConfig = {
app: {
getInitialData: async () => {
const res = await request('/user');
return res;
// const res = await request('/user');
// return res;
await delay(1500);

return {
data: {
user: {
name: 'Jack Ma',
id: 10001,
}
},
};
}
},
router: {
Expand Down
34 changes: 24 additions & 10 deletions examples/basic-ssr-with-lazy-load/src/pages/Home/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState, useEffect } from 'react';
import { request, Link, logger, Helmet, store as appStore } from 'ice';
import { Link, logger, Helmet, store as appStore } from 'ice';
import pageStore from './store';
import styles from './index.module.scss';

export default function Home(props) {
Expand All @@ -13,29 +14,42 @@ export default function Home(props) {
}, []);

const [userState] = appStore.useModel('user');
const [counterState] = pageStore.useModel('counter');

return (
<>
<main>
<Helmet>
<meta charSet="utf-8" />
<title>{props.title}</title>
<meta name="keywords" content={props.keywords} />
<meta name="description" content={props.description} />
</Helmet>
<h2 className={styles.title}>{props.title}</h2>
<div>
<div><strong>name:</strong>{userState.name}</div>
<div><strong>id:</strong>{userState.id}</div>
<div><strong>address:</strong>{props.profile && props.profile.address}</div>
<div><strong>data:</strong>{dataSource.join(' ')}</div>
</div>
<div>counterState: {counterState.count}</div>
<div>name: {userState.name}</div>
<div>id: {userState.id}</div>
<div>address: {props.profile && props.profile.address}</div>
<strong>data: {dataSource.join(' ')}</strong>
<br />
<Link to="/about">about</Link>
</>
</main>
);
}

Home.getInitialProps = async () => {
const res = await request('/profile');
// const res = await request('/profile');
const res = {
data: {
profile: {
id: 10001,
name: 'Jack Ma',
edu: 'Hangzhou Normal University',
address: 'Hangzhou'
},
title: 'Home Page...',
content: 'Home Content...',
description: 'Home Description...'
}
};
return { ...res.data, title: 'Home Page...' };
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
state: {
count: 1
}
};
6 changes: 6 additions & 0 deletions examples/basic-ssr-with-lazy-load/src/pages/Home/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createStore } from 'ice';
import counter from './models/counter';

const models = { counter };

export default createStore(models);
21 changes: 16 additions & 5 deletions examples/basic-ssr/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import { runApp, IAppConfig, config, request } from 'ice';
import { runApp, IAppConfig, config } from 'ice';

const delay = (time) => new Promise<void>((resolve) => setTimeout(() => resolve(), time));

const appConfig: IAppConfig = {
app: {
getInitialData: async (ctx) => {
console.log('getInitialData ctx', ctx);
getInitialData: async () => {
// console.log('getInitialData ctx', ctx);

const res = await request('/user');
return res;
// const res = await request('/user');
// return res;
await delay(1500);
return {
data: {
user: {
name: 'Jack Ma',
id: 10001,
}
},
};
}
},
router: {
Expand Down
36 changes: 26 additions & 10 deletions examples/basic-ssr/src/pages/Home/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState, useEffect } from 'react';
import { request, Link, logger, Helmet, store as appStore } from 'ice';
import { Link, logger, Helmet, store as appStore } from 'ice';
import pageStore from './store';
import styles from './index.module.scss';

export default function Home(props) {
Expand All @@ -13,30 +14,45 @@ export default function Home(props) {
}, []);

const [userState] = appStore.useModel('user');
const [counterState] = pageStore.useModel('counter');

return (
<>
<main>
<Helmet>
<meta charSet="utf-8" />
<title>{props.title}</title>
<meta name="keywords" content={props.keywords} />
<meta name="description" content={props.description} />
</Helmet>
<h2 className={styles.title}>{props.title}</h2>
<div>
<div><strong>name:</strong>{userState.name}</div>
<div><strong>id:</strong>{userState.id}</div>
<div><strong>address:</strong>{props.profile && props.profile.address}</div>
<div><strong>data:</strong>{dataSource.join(' ')}</div>
</div>
<div>counterState: {counterState.count}</div>
<div>name: {userState.name}</div>
<div>id: {userState.id}</div>
<div>address: {props.profile && props.profile.address}</div>
<strong>data: {dataSource.join(' ')}</strong>
<br />
<Link to="/about">about</Link>
<br />
<Link to="/dashboard">dashboard</Link>
</>
</main>
);
}

Home.getInitialProps = async () => {
const res = await request('/profile');
// const res = await request('/profile');
const res = {
data: {
profile: {
id: 10001,
name: 'Jack Ma',
edu: 'Hangzhou Normal University',
address: 'Hangzhou'
},
title: 'Home Page...',
content: 'Home Content...',
description: 'Home Description...'
}
};

return { ...res.data, title: 'Home Page...' };
};
5 changes: 5 additions & 0 deletions examples/basic-ssr/src/pages/Home/models/counter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
state: {
count: 1
}
};
6 changes: 6 additions & 0 deletions examples/basic-ssr/src/pages/Home/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createStore } from 'ice';
import counter from './models/counter';

const models = { counter };

export default createStore(models);
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@types/node": "^14.14.21",
"@types/puppeteer": "^5.4.2",
"ali-oss": "^6.7.0",
"cheerio": "^1.0.0-rc.3",
"codecov": "^3.6.5",
"create-test-server": "^3.0.1",
"dependency-check": "^4.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/create-app-shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-app-shared",
"version": "0.2.0",
"version": "0.2.1",
"description": "",
"author": "[email protected]",
"homepage": "https://github.com/alibaba/ice#readme",
Expand Down Expand Up @@ -30,4 +30,4 @@
"bugs": {
"url": "https://github.com/alibaba/ice/issues"
}
}
}
15 changes: 1 addition & 14 deletions packages/create-app-shared/src/createBaseApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import RuntimeModule from './runtimeModule';
import { createHistory } from './history';
import { isMiniAppPlatform } from './env';
import collectAppLifeCycle from './collectAppLifeCycle';
import getSearchParams from './getSearchParams';

// eslint-disable-next-line
const deepmerge = require('deepmerge');
Expand All @@ -17,7 +16,7 @@ const DEFAULE_APP_CONFIG = {
};

export default ({ loadRuntimeModules, createElement, initHistory = true }) => {
const createBaseApp = async (appConfig, buildConfig, context: any = {}) => {
const createBaseApp = (appConfig, buildConfig, context: any = {}) => {

// Merge default appConfig to user appConfig
appConfig = deepmerge(DEFAULE_APP_CONFIG, appConfig);
Expand All @@ -32,17 +31,6 @@ export default ({ loadRuntimeModules, createElement, initHistory = true }) => {
appConfig.router.history = history;
}

if (!context.initialData && appConfig?.app?.getInitialData) {
const location = history.location ? history.location : window.location;
const pathname = location.pathname;
context.initialData = await appConfig.app.getInitialData({
pathname,
path: pathname,
query: getSearchParams(location),
ssrError: (window as any)?.__ICE_SSR_ERROR__
});
}

context.createElement = createElement;

// Load runtime modules
Expand All @@ -51,7 +39,6 @@ export default ({ loadRuntimeModules, createElement, initHistory = true }) => {

// Collect app lifeCyle
collectAppLifeCycle(appConfig);

return {
history,
runtime,
Expand Down
3 changes: 1 addition & 2 deletions packages/create-app-shared/src/getSearchParams.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as queryString from 'query-string';
import { getHistory } from './history';

export default function(location?) {
if (location) return queryString.parse(location.search);
export default function() {
const history = getHistory();
if (history && history.location && history.location.search) {
return queryString.parse(history.location.search);
Expand Down
6 changes: 3 additions & 3 deletions packages/icejs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ice.js",
"version": "1.15.1",
"version": "1.15.2",
"description": "command line interface and builtin plugin for icejs",
"author": "[email protected]",
"homepage": "",
Expand Down Expand Up @@ -31,8 +31,8 @@
"build-plugin-ice-mpa": "1.8.4",
"build-plugin-ice-request": "1.7.4",
"build-plugin-ice-router": "1.9.0",
"build-plugin-ice-ssr": "2.0.0",
"build-plugin-ice-store": "1.9.2",
"build-plugin-ice-ssr": "2.0.1",
"build-plugin-ice-store": "1.9.3",
"build-plugin-react-app": "1.8.0",
"build-plugin-miniapp": "0.1.7",
"chalk": "^4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/miniapp-renderer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "miniapp-renderer",
"version": "0.1.6",
"version": "0.1.7",
"description": "",
"author": "[email protected]",
"homepage": "https://github.com/alibaba/ice#readme",
Expand Down
4 changes: 2 additions & 2 deletions packages/miniapp-renderer/src/miniappRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
async function miniappRenderer(
function miniappRenderer(
{ appConfig = {} as any, createBaseApp, createHistory, staticConfig, pageProps, emitLifeCycles, ErrorBoundary },
{ mount, unmount, createElement, Component }
) {
const history = createHistory({ routes: staticConfig.routes });

const { runtime } = await createBaseApp(appConfig);
const { runtime } = createBaseApp(appConfig);
const AppProvider = runtime?.composeAppProvider?.();

const { app = {} } = appConfig;
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-app-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
"url": "[email protected]:alibaba/ice.git"
},
"gitHead": "07ac7bb07162aac8c90778dd1de4a2060f8df498"
}
}
4 changes: 2 additions & 2 deletions packages/plugin-ice-ssr/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-ice-ssr",
"version": "2.0.0",
"version": "2.0.1",
"description": "ssr plugin",
"author": "[email protected]",
"homepage": "",
Expand Down Expand Up @@ -32,4 +32,4 @@
"parseurl": "^1.3.3",
"query-string": "^6.13.7"
}
}
}
4 changes: 2 additions & 2 deletions packages/plugin-ice-ssr/src/server.ts.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const serverRender = async ({ ctx = {}, pathname, initialData, htmlTemplate, loa

// generate bundle content and register global variables in html
console.log('[SSR]', 'generating html content');
const renderResult = await reactAppRendererWithSSR({
const renderResult = reactAppRendererWithSSR({
initialContext,
initialData,
pageInitialProps
Expand Down Expand Up @@ -109,7 +109,7 @@ const serverRender = async ({ ctx = {}, pathname, initialData, htmlTemplate, loa
error = e;
$('head').append(`
<script>
window.__ICE_SSR_ERROR__ = '${error}';
window.__ICE_SSR_ERROR__ = "${(error instanceof Error ? error.message : error).replace(/\"/g, '\'')}";
</script>`)
logError('[SSR] generate html template error');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-store/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-ice-store",
"version": "1.9.2",
"version": "1.9.3",
"description": "builtin `icestore` in icejs",
"author": "[email protected]",
"homepage": "",
Expand Down
Loading

0 comments on commit 1d428d0

Please sign in to comment.