Skip to content

Commit

Permalink
subapp-pbundle: send location to StartComponent and reduxStoreReady (#…
Browse files Browse the repository at this point in the history
…1544)

* subapp-pbundle: send location to StartComponent and reduxStoreReady

* Only send request instead of location
  • Loading branch information
christianlent authored Feb 27, 2020
1 parent 7298f1e commit 35285f7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/subapp-pbundle/lib/framework-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ class FrameworkLib {
createTopComponent(initialProps) {
const { request } = this.ref.context.user;
const { subApp } = this.ref;

const TopComponent = createElement(this.StartComponent, initialProps);
const TopComponent = createElement(this.StartComponent, {
request,
...initialProps
});

return createElement(
AppContext.Provider,
Expand Down Expand Up @@ -189,7 +191,11 @@ class FrameworkLib {
this.ref.subAppServer.reduxStoreReady || this.ref.subApp.reduxStoreReady;

if (reduxStoreReady) {
await reduxStoreReady({ store: this.store });
const { request } = this.ref.context.user;
await reduxStoreReady({
request,
store: this.store
});
}
}
}
Expand Down
27 changes: 27 additions & 0 deletions packages/subapp-pbundle/test/spec/ssr-framework.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,31 @@ describe("SSR Preact framework", function() {
await framework.handleSSR();
expect(JSON.parse(framework.initialStateStr).hello).to.equal("universe");
});

it("should provide location prop to StartComponent", async () => {
const framework = new lib.FrameworkLib({
subApp: {
__redux: true,
reduxCreateStore(initialState) {
return composeBundles(helloBundle)(initialState);
}
},
subAppServer: {
StartComponent: ({ request }) => `path is: ${request.url.pathname}`
},
context: {
user: {
request: {
url: {
pathname: "somepath"
}
}
}
},
options: { serverSideRendering: true }
});

const html = await framework.handleSSR();
expect(html).to.equal("path is: somepath");
});
});

0 comments on commit 35285f7

Please sign in to comment.