@serveside/react
Advanced tools
Comparing version 0.0.1-alpha.11 to 0.0.1-alpha.13
@@ -6,2 +6,10 @@ # Change Log | ||
## [0.0.1-alpha.13](https://github.com/serveside/serveside/compare/v0.0.1-alpha.12...v0.0.1-alpha.13) (2020-09-02) | ||
**Note:** Version bump only for package @serveside/react | ||
## [0.0.1-alpha.11](https://github.com/serveside/serveside/compare/v0.0.1-alpha.8...v0.0.1-alpha.11) (2020-09-02) | ||
@@ -8,0 +16,0 @@ |
@@ -14,2 +14,4 @@ "use strict"; | ||
var _reactIs = require("react-is"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -23,19 +25,29 @@ | ||
const componentString = _server.default.renderToString( /*#__PURE__*/_react.default.createElement(ResolvedComponent, componentProps)); | ||
try { | ||
if (!(0, _reactIs.isValidElementType)(ResolvedComponent)) { | ||
throw new Error('invalid element type', { ...req.locals | ||
}); | ||
} | ||
res.locals.html = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", { | ||
"data-serveside-component": component, | ||
"data-serveside-id": `se_embed_react_ssr_${req.id}`, | ||
dangerouslySetInnerHTML: { | ||
__html: componentString | ||
} | ||
}), /*#__PURE__*/_react.default.createElement("script", { | ||
dangerouslySetInnerHTML: { | ||
__html: ` | ||
window.__SSR_AAS_LOAD_PROPS__ ||= {}; | ||
window.__SSR_AAS_LOAD_PROPS__[${req.id}] = ${JSON.stringify(componentProps, null, 3)}; | ||
` | ||
} | ||
})); | ||
next(); | ||
const componentString = _server.default.renderToString( /*#__PURE__*/_react.default.createElement(ResolvedComponent, componentProps)); | ||
res.locals.jsx = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", { | ||
"data-serveside-component": component, | ||
"data-serveside-id": `se_embed_react_ssr_${req.id}`, | ||
dangerouslySetInnerHTML: { | ||
__html: componentString | ||
} | ||
}), /*#__PURE__*/_react.default.createElement("script", { | ||
dangerouslySetInnerHTML: { | ||
__html: ` | ||
window.__SERVESIDE_LOAD_PROPS__ ||= {}; | ||
window.__SERVESIDE_LOAD_PROPS__[${req.id}] = ${JSON.stringify(componentProps, null, 3)}; | ||
` | ||
} | ||
})); | ||
next(); | ||
} catch (error) { | ||
res.locals.error = error; | ||
next('route'); | ||
} | ||
} | ||
@@ -48,3 +60,3 @@ | ||
error = _req$locals2.error; | ||
res.locals.html = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", { | ||
res.locals.jsx = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", { | ||
"data-serveside-component": component, | ||
@@ -55,5 +67,5 @@ "data-serveside-id": `se_embed_react_ssr_${req.id}` | ||
__html: ` | ||
window.__SSR_AAS_LOAD_ERROR__ = ${JSON.stringify(error.message)}; | ||
window.__SSR_AAS_LOAD_PROPS__ ||= {}; | ||
window.__SSR_AAS_LOAD_PROPS__[${req.id}] = ${JSON.stringify(componentProps, null, 3)}; | ||
window.__SERVESIDE_LOAD_ERROR__ = ${JSON.stringify(error.message)}; | ||
window.__SERVESIDE_LOAD_PROPS__ ||= {}; | ||
window.__SERVESIDE_LOAD_PROPS__[${req.id}] = ${JSON.stringify(componentProps, null, 3)}; | ||
` | ||
@@ -66,5 +78,5 @@ } | ||
function htmlRenderer(__, res) { | ||
const html = _server.default.renderToStaticMarkup(res.locals.html); | ||
const html = _server.default.renderToStaticMarkup(res.locals.jsx); | ||
res.send(html); | ||
} |
{ | ||
"name": "@serveside/react", | ||
"version": "0.0.1-alpha.11", | ||
"version": "0.0.1-alpha.13", | ||
"description": "> TODO: description", | ||
@@ -32,5 +32,6 @@ "author": "Naftali Lubin <maniator@users.noreply.github.com>", | ||
"react": "^16.13.1", | ||
"react-dom": "^16.13.1" | ||
"react-dom": "^16.13.1", | ||
"react-is": "^16.13.1" | ||
}, | ||
"gitHead": "12de1ad45c704d27e27125bb522fc4717253638f" | ||
"gitHead": "819d5c3e7de7c3a2b1d30e56ce94aa837d47a034" | ||
} |
import React from 'react'; | ||
import ReactDOMServer from 'react-dom/server'; | ||
import { isValidElementType } from "react-is"; | ||
function htmlLoader(req, res, next) { | ||
const { ResolvedComponent, componentProps, component } = req.locals; | ||
const componentString = ReactDOMServer.renderToString( | ||
<ResolvedComponent {...componentProps} />, | ||
); | ||
try { | ||
if (!isValidElementType(ResolvedComponent)) { | ||
throw new Error('invalid element type', { ...req.locals }); | ||
} | ||
const componentString = ReactDOMServer.renderToString( | ||
<ResolvedComponent {...componentProps} />, | ||
); | ||
res.locals.html = ( | ||
<> | ||
<div | ||
data-serveside-component={component} | ||
data-serveside-id={`se_embed_react_ssr_${req.id}`} | ||
dangerouslySetInnerHTML={{ __html: componentString }} | ||
/> | ||
<script | ||
dangerouslySetInnerHTML={{ | ||
__html: ` | ||
window.__SSR_AAS_LOAD_PROPS__ ||= {}; | ||
window.__SSR_AAS_LOAD_PROPS__[${req.id}] = ${JSON.stringify( | ||
componentProps, | ||
null, | ||
3, | ||
)}; | ||
`, | ||
}} | ||
/> | ||
</> | ||
); | ||
next(); | ||
res.locals.jsx = ( | ||
<> | ||
<div | ||
data-serveside-component={component} | ||
data-serveside-id={`se_embed_react_ssr_${req.id}`} | ||
dangerouslySetInnerHTML={{ __html: componentString }} | ||
/> | ||
<script | ||
dangerouslySetInnerHTML={{ | ||
__html: ` | ||
window.__SERVESIDE_LOAD_PROPS__ ||= {}; | ||
window.__SERVESIDE_LOAD_PROPS__[${req.id}] = ${JSON.stringify( | ||
componentProps, | ||
null, | ||
3, | ||
)}; | ||
`, | ||
}} | ||
/> | ||
</> | ||
); | ||
next(); | ||
} catch (error) { | ||
res.locals.error = error; | ||
next('route'); | ||
} | ||
} | ||
@@ -38,3 +46,3 @@ | ||
res.locals.html = ( | ||
res.locals.jsx = ( | ||
<> | ||
@@ -48,5 +56,5 @@ <div | ||
__html: ` | ||
window.__SSR_AAS_LOAD_ERROR__ = ${JSON.stringify(error.message)}; | ||
window.__SSR_AAS_LOAD_PROPS__ ||= {}; | ||
window.__SSR_AAS_LOAD_PROPS__[${req.id}] = ${JSON.stringify( | ||
window.__SERVESIDE_LOAD_ERROR__ = ${JSON.stringify(error.message)}; | ||
window.__SERVESIDE_LOAD_PROPS__ ||= {}; | ||
window.__SERVESIDE_LOAD_PROPS__[${req.id}] = ${JSON.stringify( | ||
componentProps, | ||
@@ -66,3 +74,3 @@ null, | ||
function htmlRenderer(__, res) { | ||
const html = ReactDOMServer.renderToStaticMarkup(res.locals.html); | ||
const html = ReactDOMServer.renderToStaticMarkup(res.locals.jsx); | ||
res.send(html); | ||
@@ -69,0 +77,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11203
7
274
3