@umijs/renderer-react
Advanced tools
Comparing version 3.2.0-beta.5 to 3.2.0-beta.6
@@ -33,4 +33,2 @@ import { FunctionComponent } from 'react'; | ||
export { default as renderClient } from './renderClient/renderClient'; | ||
export { default as renderServer, createServerElement, } from './renderServer/renderServer'; | ||
export { default as renderRoutes } from './renderRoutes/renderRoutes'; | ||
export { matchRoutes } from 'react-router-config'; |
import { hydrate, render } from 'react-dom'; | ||
import React, { useState, useEffect } from 'react'; | ||
import { __RouterContext, matchPath, Redirect, ApplyPluginsType, Router, StaticRouter } from '@umijs/runtime'; | ||
import { __RouterContext, matchPath, Redirect, ApplyPluginsType, Router } from '@umijs/runtime'; | ||
import { matchRoutes } from 'react-router-config'; | ||
export { matchRoutes } from 'react-router-config'; | ||
import ReactDOMServer from 'react-dom/server'; | ||
@@ -316,3 +314,3 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { | ||
var _opts$plugin$applyPlu, modifyGetInitialPropsCtx, defaultCtx, ctx, _initialProps; | ||
var ctx, _opts$plugin$applyPlu, modifyGetInitialPropsCtx, _initialProps; | ||
@@ -323,8 +321,3 @@ return regeneratorRuntime.wrap(function _callee$(_context) { | ||
case 0: | ||
_opts$plugin$applyPlu = opts.plugin.applyPlugins({ | ||
key: 'ssr', | ||
type: ApplyPluginsType.modify, | ||
initialValue: {} | ||
}), modifyGetInitialPropsCtx = _opts$plugin$applyPlu.modifyGetInitialPropsCtx; | ||
defaultCtx = _objectSpread2({ | ||
ctx = _objectSpread2({ | ||
isServer: false, | ||
@@ -334,3 +327,3 @@ match: props === null || props === void 0 ? void 0 : props.match | ||
if (!modifyGetInitialPropsCtx) { | ||
if (!Component.getInitialProps) { | ||
_context.next = 8; | ||
@@ -340,29 +333,20 @@ break; | ||
_context.next = 5; | ||
return modifyGetInitialPropsCtx(defaultCtx); | ||
_opts$plugin$applyPlu = opts.plugin.applyPlugins({ | ||
key: 'ssr', | ||
type: ApplyPluginsType.modify, | ||
initialValue: {} | ||
}), modifyGetInitialPropsCtx = _opts$plugin$applyPlu.modifyGetInitialPropsCtx; | ||
case 5: | ||
_context.t0 = _context.sent; | ||
_context.next = 9; | ||
break; | ||
case 8: | ||
_context.t0 = defaultCtx; | ||
case 9: | ||
ctx = _context.t0; | ||
if (!Component.getInitialProps) { | ||
_context.next = 15; | ||
break; | ||
if (typeof modifyGetInitialPropsCtx === 'function') { | ||
modifyGetInitialPropsCtx(ctx); | ||
} | ||
_context.next = 13; | ||
_context.next = 6; | ||
return Component.getInitialProps(ctx); | ||
case 13: | ||
case 6: | ||
_initialProps = _context.sent; | ||
setInitialProps(_initialProps); | ||
case 15: | ||
case 8: | ||
case "end": | ||
@@ -394,5 +378,4 @@ return _context.stop(); | ||
var defaultPageInitialProps = process.env.__IS_SERVER ? {} : window.g_initialProps; | ||
var defaultAppInitialData = process.env.__IS_SERVER ? {} : window.g_initialData; | ||
var newProps = _objectSpread2({}, props, {}, opts.extraProps, {}, opts.pageInitialProps || defaultPageInitialProps, {}, opts.appInitialData || defaultAppInitialData, { | ||
var newProps = _objectSpread2({}, props, {}, opts.extraProps, {}, opts.pageInitialProps || defaultPageInitialProps, { | ||
route: route | ||
@@ -640,72 +623,2 @@ }); // @ts-ignore | ||
/** | ||
* 处理 getInitialProps、路由 StaticRouter、数据预获取 | ||
* @param opts | ||
*/ | ||
function createServerElement(opts) { | ||
var path = opts.path, | ||
context = opts.context, | ||
_opts$basename = opts.basename, | ||
basename = _opts$basename === void 0 ? '/' : _opts$basename, | ||
renderRoutesProps = _objectWithoutProperties(opts, ["path", "context", "basename"]); | ||
return renderRoutesProps.plugin.applyPlugins({ | ||
type: ApplyPluginsType.modify, | ||
key: 'rootContainer', | ||
initialValue: | ||
/*#__PURE__*/ | ||
// basename maybe react-router bug, will lead to double slash | ||
React.createElement(StaticRouter, { | ||
basename: basename === '/' ? '' : basename, | ||
location: path, | ||
context: context | ||
}, renderRoutes(renderRoutesProps)), | ||
args: { | ||
// special rootContainer | ||
// DISCUSS: history | ||
// history, | ||
type: 'ssr', | ||
routes: opts.routes, | ||
plugin: opts.plugin | ||
} | ||
}); | ||
} | ||
function renderServer(_x) { | ||
return _renderServer.apply(this, arguments); | ||
} | ||
function _renderServer() { | ||
_renderServer = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(opts) { | ||
var element; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
element = createServerElement(opts); | ||
if (!(opts.mode === 'stream')) { | ||
_context.next = 3; | ||
break; | ||
} | ||
return _context.abrupt("return", { | ||
html: ReactDOMServer[opts.staticMarkup ? 'renderToStaticNodeStream' : 'renderToNodeStream'](element) | ||
}); | ||
case 3: | ||
return _context.abrupt("return", { | ||
html: ReactDOMServer[opts.staticMarkup ? 'renderToStaticMarkup' : 'renderToString'](element) | ||
}); | ||
case 4: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return _renderServer.apply(this, arguments); | ||
} | ||
export { createServerElement, renderClient, renderRoutes, renderServer }; | ||
export { renderClient, renderRoutes }; |
@@ -12,3 +12,2 @@ 'use strict'; | ||
var reactRouterConfig = require('react-router-config'); | ||
var ReactDOMServer = _interopDefault(require('react-dom/server')); | ||
@@ -323,3 +322,3 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { | ||
var _opts$plugin$applyPlu, modifyGetInitialPropsCtx, defaultCtx, ctx, _initialProps; | ||
var ctx, _opts$plugin$applyPlu, modifyGetInitialPropsCtx, _initialProps; | ||
@@ -330,8 +329,3 @@ return regeneratorRuntime.wrap(function _callee$(_context) { | ||
case 0: | ||
_opts$plugin$applyPlu = opts.plugin.applyPlugins({ | ||
key: 'ssr', | ||
type: runtime.ApplyPluginsType.modify, | ||
initialValue: {} | ||
}), modifyGetInitialPropsCtx = _opts$plugin$applyPlu.modifyGetInitialPropsCtx; | ||
defaultCtx = _objectSpread2({ | ||
ctx = _objectSpread2({ | ||
isServer: false, | ||
@@ -341,3 +335,3 @@ match: props === null || props === void 0 ? void 0 : props.match | ||
if (!modifyGetInitialPropsCtx) { | ||
if (!Component.getInitialProps) { | ||
_context.next = 8; | ||
@@ -347,29 +341,20 @@ break; | ||
_context.next = 5; | ||
return modifyGetInitialPropsCtx(defaultCtx); | ||
_opts$plugin$applyPlu = opts.plugin.applyPlugins({ | ||
key: 'ssr', | ||
type: runtime.ApplyPluginsType.modify, | ||
initialValue: {} | ||
}), modifyGetInitialPropsCtx = _opts$plugin$applyPlu.modifyGetInitialPropsCtx; | ||
case 5: | ||
_context.t0 = _context.sent; | ||
_context.next = 9; | ||
break; | ||
case 8: | ||
_context.t0 = defaultCtx; | ||
case 9: | ||
ctx = _context.t0; | ||
if (!Component.getInitialProps) { | ||
_context.next = 15; | ||
break; | ||
if (typeof modifyGetInitialPropsCtx === 'function') { | ||
modifyGetInitialPropsCtx(ctx); | ||
} | ||
_context.next = 13; | ||
_context.next = 6; | ||
return Component.getInitialProps(ctx); | ||
case 13: | ||
case 6: | ||
_initialProps = _context.sent; | ||
setInitialProps(_initialProps); | ||
case 15: | ||
case 8: | ||
case "end": | ||
@@ -401,5 +386,4 @@ return _context.stop(); | ||
var defaultPageInitialProps = process.env.__IS_SERVER ? {} : window.g_initialProps; | ||
var defaultAppInitialData = process.env.__IS_SERVER ? {} : window.g_initialData; | ||
var newProps = _objectSpread2({}, props, {}, opts.extraProps, {}, opts.pageInitialProps || defaultPageInitialProps, {}, opts.appInitialData || defaultAppInitialData, { | ||
var newProps = _objectSpread2({}, props, {}, opts.extraProps, {}, opts.pageInitialProps || defaultPageInitialProps, { | ||
route: route | ||
@@ -647,81 +631,3 @@ }); // @ts-ignore | ||
/** | ||
* 处理 getInitialProps、路由 StaticRouter、数据预获取 | ||
* @param opts | ||
*/ | ||
function createServerElement(opts) { | ||
var path = opts.path, | ||
context = opts.context, | ||
_opts$basename = opts.basename, | ||
basename = _opts$basename === void 0 ? '/' : _opts$basename, | ||
renderRoutesProps = _objectWithoutProperties(opts, ["path", "context", "basename"]); | ||
return renderRoutesProps.plugin.applyPlugins({ | ||
type: runtime.ApplyPluginsType.modify, | ||
key: 'rootContainer', | ||
initialValue: | ||
/*#__PURE__*/ | ||
// basename maybe react-router bug, will lead to double slash | ||
React__default.createElement(runtime.StaticRouter, { | ||
basename: basename === '/' ? '' : basename, | ||
location: path, | ||
context: context | ||
}, renderRoutes(renderRoutesProps)), | ||
args: { | ||
// special rootContainer | ||
// DISCUSS: history | ||
// history, | ||
type: 'ssr', | ||
routes: opts.routes, | ||
plugin: opts.plugin | ||
} | ||
}); | ||
} | ||
function renderServer(_x) { | ||
return _renderServer.apply(this, arguments); | ||
} | ||
function _renderServer() { | ||
_renderServer = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(opts) { | ||
var element; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
element = createServerElement(opts); | ||
if (!(opts.mode === 'stream')) { | ||
_context.next = 3; | ||
break; | ||
} | ||
return _context.abrupt("return", { | ||
html: ReactDOMServer[opts.staticMarkup ? 'renderToStaticNodeStream' : 'renderToNodeStream'](element) | ||
}); | ||
case 3: | ||
return _context.abrupt("return", { | ||
html: ReactDOMServer[opts.staticMarkup ? 'renderToStaticMarkup' : 'renderToString'](element) | ||
}); | ||
case 4: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return _renderServer.apply(this, arguments); | ||
} | ||
Object.defineProperty(exports, 'matchRoutes', { | ||
enumerable: true, | ||
get: function () { | ||
return reactRouterConfig.matchRoutes; | ||
} | ||
}); | ||
exports.createServerElement = createServerElement; | ||
exports.renderClient = renderClient; | ||
exports.renderRoutes = renderRoutes; | ||
exports.renderServer = renderServer; |
@@ -9,5 +9,4 @@ import { Plugin } from '@umijs/runtime'; | ||
getInitialPropsCtx?: object; | ||
appInitialData?: object; | ||
} | ||
export default function renderRoutes(opts: IOpts): JSX.Element | null; | ||
export {}; |
{ | ||
"name": "@umijs/renderer-react", | ||
"version": "3.2.0-beta.5", | ||
"version": "3.2.0-beta.6", | ||
"description": "@umijs/renderer-react", | ||
@@ -31,3 +31,3 @@ "main": "dist/index.js", | ||
"@types/react-router-config": "^5.0.1", | ||
"@umijs/runtime": "3.2.0-beta.5", | ||
"@umijs/runtime": "3.2.0-beta.6", | ||
"react": "^16.13.1", | ||
@@ -34,0 +34,0 @@ "react-dom": "^16.13.1", |
4
37427
11
1102
+ Added@umijs/runtime@3.2.0-beta.6(transitive)
- Removed@umijs/runtime@3.2.0-beta.5(transitive)
Updated@umijs/runtime@3.2.0-beta.6