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))