Skip to content

Commit

Permalink
[major] remove loadable and replace with subapp v2
Browse files Browse the repository at this point in the history
  • Loading branch information
jchip committed Jan 29, 2021
1 parent 87ff73b commit 56b8d2d
Show file tree
Hide file tree
Showing 19 changed files with 1,866 additions and 2,861 deletions.
32 changes: 13 additions & 19 deletions packages/electrode-redux-router-engine/lib/redux-router-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ class ReduxRouterEngine {
startMatch(req, options = {}) {
// hapi@18 compatibility: use "origin" to determine (WHATWG has origin, Url.parse does not)
// https://github.com/hapijs/hapi/issues/3871
const url = (typeof req.url === "object") && ("origin" in req.url) && req.url.href
? req.url.href
: req.url;
const url =
typeof req.url === "object" && "origin" in req.url && req.url.href ? req.url.href : req.url;
const location = options.location || Url.parse(url || req.path);

options = Object.assign({}, options, { req, location });
Expand Down Expand Up @@ -270,25 +269,20 @@ class ReduxRouterEngine {
ssrApi = withIds ? ReactDomServer.renderToString : ReactDomServer.renderToStaticMarkup;
}

const target = util.getTargetByQuery(req.query, this._envTargets);
this._extractor = util.createdStatExtractor(target);

return ssrApi(
this._extractor.collectChunks(
React.createElement(
// server side context to provide request
ServerContext,
{ request: req },
// redux provider
React.createElement(
// server side context to provide request
ServerContext,
{ request: req },
// redux provider
Provider,
{ store },
// user route component
React.createElement(
Provider,
{ store },
// user route component
React.createElement(
StaticRouter,
{ location, context: routeContext, basename: this.options.basename },
this._routesComponent
)
StaticRouter,
{ location, context: routeContext, basename: this.options.basename },
this._routesComponent
)
)
)
Expand Down
10 changes: 0 additions & 10 deletions packages/electrode-redux-router-engine/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const Path = require("path");
const Fs = require("fs");
const { ChunkExtractor } = require("@loadable/server");

module.exports = {
es6Default: m => {
Expand All @@ -13,15 +12,6 @@ module.exports = {

return p.startsWith(".") ? Path.resolve(baseDir || "", p) : p;
},
createdStatExtractor: target => {
const filename = `${target !== "default" ? `${target}-` : ""}loadable-stats.json`;
const statsFile = Path.resolve(`./dist/server/${filename}`);
return Fs.existsSync(statsFile)
? new ChunkExtractor({ statsFile })
: {
collectChunks: app => app
};
},
getTargetByQuery: (query, envTargets) => {
const __dist = query && query.__dist;
return envTargets.includes(__dist) ? __dist : "default";
Expand Down
2 changes: 0 additions & 2 deletions packages/electrode-redux-router-engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
"xstdout": "^0.1.1"
},
"dependencies": {
"@loadable/component": "^5.7.0",
"@loadable/server": "^5.9.0",
"optional-require": "^1.0.0",
"react-redux": "^4.4.5 || ^5.x.x",
"react-router": "^5.1.2",
Expand Down
Loading

0 comments on commit 56b8d2d

Please sign in to comment.