Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subapp.start handles inline rendering #1477

Merged
merged 1 commit into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions packages/subapp-web/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(<Component {...props} />, element);
if (element) {
if (ssr) {
hydrate(<Component {...props} />, element);
} else {
render(<Component {...props} />, element);
}
} else {
render(<Component {...props} />, element);
return <Component {...props} />;
}
}

Expand Down Expand Up @@ -45,7 +49,7 @@ export function loadSubApp(info, renderStart) {
this.info.StartComponent || this.info.Component,
options.serverSideRendering,
element,
options._prepared
{ ...options._prepared, ...options.props }
);
};

Expand All @@ -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 = () => {
Expand All @@ -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);
};

Expand Down
4 changes: 1 addition & 3 deletions samples/poc-subapp/src/components/deals.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ class SubApp extends React.Component {
return (
<div className="col-sm-4">
<div className="panel panel-primary">
<div className="panel-body">
<subapp.info.Component {...this.props} />
</div>
<div className="panel-body">{subapp.start({ props: this.props })}</div>
</div>
</div>
);
Expand Down