From 35285f7f11e78e6cf91b89c7b3cd354ae3c410fe Mon Sep 17 00:00:00 2001 From: Christian Lent Date: Thu, 27 Feb 2020 18:14:10 -0500 Subject: [PATCH] subapp-pbundle: send location to StartComponent and reduxStoreReady (#1544) * subapp-pbundle: send location to StartComponent and reduxStoreReady * Only send request instead of location --- packages/subapp-pbundle/lib/framework-lib.js | 12 ++++++--- .../test/spec/ssr-framework.spec.js | 27 +++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/packages/subapp-pbundle/lib/framework-lib.js b/packages/subapp-pbundle/lib/framework-lib.js index aad9c5ff0..dd429f680 100644 --- a/packages/subapp-pbundle/lib/framework-lib.js +++ b/packages/subapp-pbundle/lib/framework-lib.js @@ -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, @@ -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 + }); } } } diff --git a/packages/subapp-pbundle/test/spec/ssr-framework.spec.js b/packages/subapp-pbundle/test/spec/ssr-framework.spec.js index ec524b7a7..fb01c71c3 100644 --- a/packages/subapp-pbundle/test/spec/ssr-framework.spec.js +++ b/packages/subapp-pbundle/test/spec/ssr-framework.spec.js @@ -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"); + }); });