From b5479619f8a20ea0594d5878afe421a1bc0d833d Mon Sep 17 00:00:00 2001 From: zhangyuang Date: Thu, 20 Jun 2019 10:45:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=84=9A=E6=89=8B?= =?UTF-8?q?=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/guide/hydrate.md | 10 ++-- docs/guide/stream.md | 2 +- example/ssr-with-js/package.json | 2 +- packages/yk-cli/bin/app.js | 2 +- packages/yk-cli/bin/cache.js | 12 ++-- packages/yk-cli/bin/config.js | 14 ++--- packages/yk-cli/bin/help.js | 2 +- packages/yk-cli/bin/index.js | 6 +- packages/yk-cli/bin/package.js | 4 +- packages/yk-cli/bin/util/fileconfig.js | 6 +- packages/yk-cli/bin/util/readFileList.js | 4 +- packages/yk-cli/bin/util/versionCompare.js | 18 +++--- packages/yk-cli/bin/util/versionEffective.js | 6 +- packages/yk-cli/bin/webcomponent.js | 34 +++++------ packages/yk-cli/bin/webpackconfig.js | 4 +- packages/yk-cli/src/cache.ts | 3 +- packages/yk-cli/src/util/fileconfig.ts | 2 +- packages/yk-cli/types/app.d.ts | 2 +- packages/yk-cli/types/cache.d.ts | 2 +- packages/yk-cli/types/config.d.ts | 2 +- packages/yk-cli/types/index.d.ts | 1 + packages/yk-cli/types/interface/option.d.ts | 6 +- packages/yk-cli/types/package.d.ts | 2 +- packages/yk-cli/types/update.d.ts | 2 +- packages/yk-cli/types/util/render.d.ts | 2 +- .../yk-cli/types/util/versionCompare.d.ts | 6 +- packages/yk-cli/types/webcomponent.d.ts | 2 +- packages/yk-cli/types/webpackconfig.d.ts | 2 +- .../es/components/getinitialProps.js | 41 ++++++------- packages/ykfe-utils/es/components/onlyCsr.js | 25 ++++---- packages/ykfe-utils/es/getComponent.js | 12 ++-- packages/ykfe-utils/es/index.js | 10 ++-- packages/ykfe-utils/es/renderToStream.js | 58 +++++++++---------- packages/ykfe-utils/lib/renderToStream.js | 2 +- packages/ykfe-utils/package.json | 2 +- packages/ykfe-utils/src/renderToStream.js | 2 +- 36 files changed, 155 insertions(+), 157 deletions(-) diff --git a/docs/guide/hydrate.md b/docs/guide/hydrate.md index abf437c7..b70237fa 100644 --- a/docs/guide/hydrate.md +++ b/docs/guide/hydrate.md @@ -11,21 +11,21 @@ import React from 'react' import ReactDOM from 'react-dom' import { BrowserRouter, StaticRouter, Route } from 'react-router-dom' import defaultLayout from '@/layout' -import { GetinitialProps, getComponent } from 'ykfe-utils' +import { getWrappedComponent, getComponent } from 'ykfe-utils' import { routes as Routes } from '../config/config.default' const clientRender = async () => { // 客户端渲染|水合 ReactDOM[window.__USESSR__ ? 'hydrate' : 'render']( - { - // 使用HOC使得csr首次进入页面以及csr/ssr切换路由时调用getInitialProps + { + // 使用高阶组件getWrappedComponent使得csr首次进入页面以及csr/ssr切换路由时调用getInitialProps Routes.map(({ path, exact, Component }, key) => { const ActiveComponent = Component() const Layout = ActiveComponent.Layout || defaultLayout return { - const HOC = GetinitialProps(ActiveComponent) - return + const WrappedComponent = getWrappedComponent(ActiveComponent) + return }} /> }) } diff --git a/docs/guide/stream.md b/docs/guide/stream.md index 975fd15c..3a1225e6 100644 --- a/docs/guide/stream.md +++ b/docs/guide/stream.md @@ -65,7 +65,7 @@ const beginDocStream = stringToStream(beginDoc.replace('') - const beginDoc = docArr[0].trim().replace('\n', '') - const beginDocStream = stringToStream(beginDoc.replace('', ` `)) - const initialData = !isCsr ? `` : '' - const injectScript = config.injectScript(chunkName).join('') - const endDoc = docArr[1].trim().replace('\n', '') - const endDocStream = stringToStream(endDoc.replace('', initialData).replace('', injectScript)) - const streamArr = isCsr ? [beginDocStream, endDocStream] : [beginDocStream, stream, endDocStream] - return multiStream(streamArr) -} - -export default renderToStream + const docArr = baseHtml.split(''); + const beginDoc = docArr[0].trim().replace('\n', ''); + const beginDocStream = stringToStream(beginDoc.replace('', ` `)); + const initialData = !isCsr ? `` : ''; + const injectScript = config.injectScript ? config.injectScript(chunkName).join('') : config.injectSrcipt(chunkName).join(''); + const endDoc = docArr[1].trim().replace('\n', ''); + const endDocStream = stringToStream(endDoc.replace('', initialData).replace('', injectScript)); + const streamArr = isCsr ? [beginDocStream, endDocStream] : [beginDocStream, stream, endDocStream]; + return multiStream(streamArr); +}; + +export default renderToStream; \ No newline at end of file diff --git a/packages/ykfe-utils/lib/renderToStream.js b/packages/ykfe-utils/lib/renderToStream.js index ea1ea2c3..f4985513 100644 --- a/packages/ykfe-utils/lib/renderToStream.js +++ b/packages/ykfe-utils/lib/renderToStream.js @@ -46,7 +46,7 @@ const renderToStream = async (ctx, chunkName, config) => { const beginDoc = docArr[0].trim().replace('\n', ''); const beginDocStream = stringToStream(beginDoc.replace('', ` `)); const initialData = !isCsr ? `` : ''; - const injectScript = config.injectScript(chunkName).join(''); + const injectScript = config.injectScript ? config.injectScript(chunkName).join('') : config.injectSrcipt(chunkName).join(''); const endDoc = docArr[1].trim().replace('\n', ''); const endDocStream = stringToStream(endDoc.replace('', initialData).replace('', injectScript)); const streamArr = isCsr ? [beginDocStream, endDocStream] : [beginDocStream, stream, endDocStream]; diff --git a/packages/ykfe-utils/package.json b/packages/ykfe-utils/package.json index 9fcf6175..e16d875f 100644 --- a/packages/ykfe-utils/package.json +++ b/packages/ykfe-utils/package.json @@ -1,6 +1,6 @@ { "name": "ykfe-utils", - "version": "1.2.5", + "version": "1.2.6", "description": "", "main": "lib/index.js", "module": "es/index.js", diff --git a/packages/ykfe-utils/src/renderToStream.js b/packages/ykfe-utils/src/renderToStream.js index 50139acf..66f9c99a 100644 --- a/packages/ykfe-utils/src/renderToStream.js +++ b/packages/ykfe-utils/src/renderToStream.js @@ -31,7 +31,7 @@ const renderToStream = async (ctx, chunkName, config) => { const beginDoc = docArr[0].trim().replace('\n', '') const beginDocStream = stringToStream(beginDoc.replace('', ` `)) const initialData = !isCsr ? `` : '' - const injectScript = config.injectScript(chunkName).join('') + const injectScript = config.injectScript ? config.injectScript(chunkName).join('') : config.injectSrcipt(chunkName).join('') const endDoc = docArr[1].trim().replace('\n', '') const endDocStream = stringToStream(endDoc.replace('', initialData).replace('', injectScript))