GithubHelp home page GithubHelp logo

michaelbenin / react-ssr-spa Goto Github PK

View Code? Open in Web Editor NEW
30.0 4.0 2.0 1.54 MB

Server side rendered single page app using reactjs official libraries.

License: MIT License

JavaScript 85.30% CSS 14.70%
react ansistrano pm2 ansible universal isomorphic react-router redux react-router-redux express

react-ssr-spa's People

Contributors

johnferrie avatar michaelbenin avatar nsp-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

react-ssr-spa's Issues

Increase server rendering performance

Thread here: facebook/react#812

In initializer for server use this snippet:

if (process.env.NODE_ENV === 'production') {
    require('react/dist/react.min.js');
    require.cache[require.resolve('react')] = require.cache[require.resolve('react/dist/react.min.js')];

    require('react-dom/dist/react-dom-server.min.js');
    require.cache[require.resolve('react-dom/server')] = require.cache[require.resolve('react-dom/dist/react-dom-server.min.js')];
}

Example setting host in supertest

// https://github.com/visionmedia/supertest/pull/297#issuecomment-275826472
function createVhostTester(app, vhost) {
  const real = supertest(app);
  const proxy = {};

  Object.keys(real).forEach(methodName => {
    proxy[methodName] = function() {
      return real[methodName]
        .apply(real, arguments)
        .set('host', vhost);
    }
  });

  return proxy;
}

var api = createVhostTester(appInstance, 'api.example.com');
var appTest = createVhostTester(appInstance, 'app.example.com');

babel-server resiliency on failed transpilations

Close the stream on error:

import gulp from 'gulp';
import { log } from 'gulp-util';
import changed from 'gulp-changed';
import babel from 'gulp-babel';
import config from './../configs/config';

gulp.task('babel-server', function babelServer() {
  const babelStream = babel({
    sourceMaps: 'inline',
    presets: [
      'react',
      [
        'env',
        {
          targets: {
            node: 'current'
          }
        }
      ]
    ]
  });

  babelStream.on('error', function handleError(err) {
    log(`Error transpiling babel in gulp_babel_server task.`);
    log(err);
    babelStream.end();
  });

  return gulp
    .src(config.server.src)
    .pipe(changed(config.dest))
    .pipe(babelStream)
    .pipe(gulp.dest(config.dest));
});

Source: gulpjs/gulp#71

Add example of components only meant to be rendered client side

Sometimes we have components which only work in the client and we don't want to render them on the server. What we can do here is check for the initial page load in the state, if it is don't render the component until after that render. Essentially, render first without client side component by doing a check if it's initial page load, after that, an event is dispatched, the component then rerenders with the client side component. This solves issues with invariants with components from react-d3 and many others.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.