Skip to content

[pull] master from thereactivestack-legacy:master #4

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

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
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
106 changes: 54 additions & 52 deletions .versions
Original file line number Diff line number Diff line change
@@ -1,60 +1,62 @@
accounts-base@1.2.7
[email protected].4
babel-compiler@6.6.4
[email protected].8
[email protected].8
[email protected].8
blaze@2.1.7
[email protected].8
boilerplate-generator@1.0.8
[email protected].8
[email protected].1
accounts-base@1.3.0
[email protected].5
babel-compiler@6.19.1
babel-runtime@1.0.1
[email protected].10
[email protected].10
blaze@2.3.2
[email protected].10
boilerplate-generator@1.1.0
[email protected].10
[email protected].5
chuangbo:[email protected]
[email protected]
ddp-client@1.2.7
[email protected].5
[email protected].4
ddp-server@1.2.6
ddp-client@1.3.4
[email protected].8
[email protected].7
ddp-server@1.3.14
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
meteorhacks:[email protected]
meteorhacks:[email protected]
[email protected]
[email protected]
[email protected]
meteorhacks:[email protected]
meteorhacks:[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
reactrouter:[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
reactrouter:[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
staringatlights:[email protected]
staringatlights:[email protected]
tmeasday:[email protected]
tracker@1.0.13
[email protected].11
[email protected].8
url@1.0.9
webapp@1.2.8
tracker@1.1.3
[email protected].13
[email protected].10
url@1.1.0
webapp@1.3.16
[email protected]
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# ANNOUNCEMENT: This project will now be maintained by [copleykj](https://github.com/copleykj). Please support this project if you would like to keep it alive and updated.

Server-side rendering for react-router and react-meteor-data rehydratating Meteor subscriptions

It has a protection against leaking your data. Only subscribed data will be available just the way it would be on the client.

What about your SEO? Just `npm install react-helmet` and hook it with `htmlHook(html): string` (see the example below).

## Supporting the project
In the spirit of keeping this package alive and in active development, I ask that if you find it useful, please donate to it's development.

[Bitcoin](https://www.coinbase.com/checkouts/4a52f56a76e565c552b6ecf118461287) / [Patreon](https://www.patreon.com/user?u=4866588) / [Paypal](https://www.paypal.me/copleykj)

## Install
`meteor add reactrouter:react-router-ssr`

@@ -32,6 +39,7 @@ Your main `<Route />` node of your application.<br />
- `dehydrateHook` [function() : data]: Supply data that should be dehydrated and sent to client.
- `fetchDataHook` [function(components) : Array<Promise>]: Trigger the fetchData on your components that have it
- `preRender` [function(req, res)]: Executed just before the renderToString
- `dataLoader` [function(req, res, app)]: Executed just after the wrapperHook to populate any data.
- `postRender` [function(req, res)]: Executed just after the renderToString
- `dontMoveScripts` [bool]: Keep the script inside the head tag instead of moving it at the end of the body
- `disableSSR` [bool]: Disable server-side rendering, in case the application depends on code which doesn't work on the server.
12 changes: 9 additions & 3 deletions lib/client.jsx
Original file line number Diff line number Diff line change
@@ -46,15 +46,21 @@ const ReactRouterSSR = {
});
}

let app = (
let appGenerator = (addProps) => (
<Router
history={history}
children={routes}
{...clientOptions.props} />
{...clientOptions.props}
{...addProps } />
);

let app = <Router
history={history}
children={routes}
{...clientOptions.props} />;

if (typeof clientOptions.wrapperHook === 'function') {
app = clientOptions.wrapperHook(app);
app = clientOptions.wrapperHook(appGenerator);
}

if (typeof clientOptions.renderHook === 'function') {
2 changes: 1 addition & 1 deletion lib/react-router-ssr.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { checkNpmVersions } from 'meteor/tmeasday:check-npm-versions';
checkNpmVersions({
'react': '15.x',
'react-dom': '15.x',
'react-router': '2.x'
'react-router': '3.x'
}, 'reactrouter:react-router-ssr');

if (Meteor.isClient) {
24 changes: 16 additions & 8 deletions lib/server.jsx
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ import patchSubscribeData from './ssr_data';
import ReactDOMServer from 'react-dom/server';
import cookieParser from 'cookie-parser';
import Cheerio from 'cheerio';
import merge from 'lodash/merge';

function IsAppUrl(req) {
var url = req.url;
@@ -43,9 +44,10 @@ ReactRouterSSR.LoadWebpackStats = function(stats) {
webpackStats = stats;
};

// this line just patches Subscribe and find mechanisms
patchSubscribeData(ReactRouterSSR);

ReactRouterSSR.Run = function(routes, clientOptions, serverOptions) {
// this line just patches Subscribe and find mechanisms
patchSubscribeData(ReactRouterSSR);

if (!clientOptions) {
clientOptions = {};
@@ -203,11 +205,18 @@ function generateSSRData(clientOptions, serverOptions, req, res, renderProps) {
...serverOptions.props
};

fetchComponentData(serverOptions, renderProps);
let app = <RouterContext {...renderProps} />;
// Instead of fetchComponentData we need to fetch from Apollo Data
//fetchComponentData(serverOptions, renderProps);
let appGenerator = (addProps) => <RouterContext {...renderProps} {...addProps} />;

let app = <RouterContext {...renderProps} />;
if (typeof clientOptions.wrapperHook === 'function') {
app = clientOptions.wrapperHook(app);
app = clientOptions.wrapperHook(appGenerator);
}

// Adding new parameter dataLoader for loading data through Apollo
if (serverOptions.dataLoader) {
serverOptions.dataLoader(req, res, app);
}

if (!serverOptions.disableSSR){
@@ -227,9 +236,8 @@ function generateSSRData(clientOptions, serverOptions, req, res, renderProps) {
}

// I'm pretty sure this could be avoided in a more elegant way?
const context = FastRender.frContext.get();
const data = context.getData();
InjectData.pushData(res, 'fast-render-data', data);
const data = FastRender.frContext.get().getData();
InjectData.pushData(res, 'fast-render-data', merge(data, frData));
}
catch(err) {
console.error(new Date(), 'error while server-rendering', err.stack);
10 changes: 4 additions & 6 deletions lib/ssr_context.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// server/ssr_context.js
// stolen from https://github.com/kadirahq/flow-router/blob/ssr/server/ssr_context.js

import deepMerge from 'deepmerge';

export default class SsrContext {
constructor() {
this._collections = {};
@@ -26,8 +24,8 @@ export default class SsrContext {
);
}

const args = [name].concat(params);
const data = fastRenderContext.subscribe(...args);

const data = fastRenderContext.subscribe(name, ...params);
this.addData(data);
}

@@ -38,9 +36,9 @@ export default class SsrContext {
collData.forEach((item) => {
const existingDoc = collection.findOne(item._id);
if (existingDoc) {
const newDoc = deepMerge(existingDoc, item);
const newDoc = { ...existingDoc, ...item };
delete newDoc._id;
collection.update(item._id, newDoc);
collection.update(item._id, { $set: newDoc });
} else {
collection.insert(item);
}
11 changes: 5 additions & 6 deletions package.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
Package.describe({
name: 'reactrouter:react-router-ssr',
version: '3.1.5',
version: '3.1.7',
summary: 'Server-side rendering for react-router and react-meteor-data rehydratating Meteor subscriptions',
git: 'https://github.com/thereactivestack/meteor-react-router-ssr.git',
git: 'https://github.com/copleykj/meteor-react-router-ssr.git',
documentation: 'README.md'
});

Npm.depends({
'cookie-parser': '1.4.1',
'cheerio': '0.20.0',
'deepmerge': '0.2.10'
});

Package.onUse(function(api) {
@@ -18,8 +17,8 @@ Package.onUse(function(api) {
'ecmascript',
'tracker',
'[email protected]',
'meteorhacks:[email protected].0',
'meteorhacks:[email protected].0',
'staringatlights:[email protected].2',
'staringatlights:[email protected].4',
'tmeasday:[email protected]'
]);

@@ -34,7 +33,7 @@ Package.onUse(function(api) {
api.use([
'[email protected]',
'tmeasday:[email protected]',
'promise@0.5.1'
'promise@0.8.8'
], 'server', {weak: true})

api.export('ReactRouterSSR');
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@
"react": "^15.3.0",
"react-dom": "^15.3.0",
"react-helmet": "^3.1.0",
"react-router": "^2.0.1",
"react-router": "^3.0.0",
"underscore": "^1.8.3"
}
}