From 551096f39e29752fc670bae7c79cc74894919d36 Mon Sep 17 00:00:00 2001 From: Joel Chen Date: Thu, 19 Dec 2019 13:37:33 -0800 Subject: [PATCH] subapp.start handles inline rendering --- packages/subapp-web/src/index.js | 18 +++++++++++------- samples/poc-subapp/src/components/deals.jsx | 4 +--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/subapp-web/src/index.js b/packages/subapp-web/src/index.js index ebba57afb..779afbfbf 100644 --- a/packages/subapp-web/src/index.js +++ b/packages/subapp-web/src/index.js @@ -7,10 +7,14 @@ export { default as makeSubAppSpec } from "./make-subapp-spec"; export { default as AppContext } from "./app-context"; export function defaultRenderStart(Component, ssr, element, props) { - if (ssr) { - hydrate(, element); + if (element) { + if (ssr) { + hydrate(, element); + } else { + render(, element); + } } else { - render(, element); + return ; } } @@ -45,7 +49,7 @@ export function loadSubApp(info, renderStart) { this.info.StartComponent || this.info.Component, options.serverSideRendering, element, - options._prepared + { ...options._prepared, ...options.props } ); }; @@ -64,9 +68,10 @@ export function loadSubApp(info, renderStart) { } else { instance.element = element; } + console.log("rendering subapp", name, "into", element); } else { - console.error(`Starting subapp ${name} without options.id`); - return undefined; + // inline rendering, no instance + instance = { props: options.props }; } const callStart = () => { @@ -76,7 +81,6 @@ export function loadSubApp(info, renderStart) { return subApp.info.start(instance, element); } - console.log("rendering subapp", name, "into", element); return subApp._renderStart(instance, element); }; diff --git a/samples/poc-subapp/src/components/deals.jsx b/samples/poc-subapp/src/components/deals.jsx index 9f3641d96..7a8d7a0ee 100644 --- a/samples/poc-subapp/src/components/deals.jsx +++ b/samples/poc-subapp/src/components/deals.jsx @@ -24,9 +24,7 @@ class SubApp extends React.Component { return (
-
- -
+
{subapp.start({ props: this.props })}
);