question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

partial-app-loading for an isomorphic app

See original GitHub issue

Looking at the partial-app-loading example, it seems it will work only for client side:

var PreDashboard = React.createClass({
  mixins: [ AsyncElement ],
  bundle: require('bundle?lazy!./dashboard.js'),
  preRender: function () {
    return <div>Loading dashboard...</div>;
  }
});

In an isomorphic environment, I get the following error when I run it Server side:

Error: Cannot find module 'bundle?lazy!./dashboard.js'

It seems that bundle-loader doesn’t recognize the module server side.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
anatomiccommented, Jul 1, 2015

Ok, so I’d advise you switch to using require.ensure on the client side and a synchronous polyfill on the server.

Something like:

if( typeof require.ensure !== "function") {
    require.ensure = function(deps, callback) {
        callback(require);
    }
}

Your code would then also need changing from require('bundle?lazy'... to something more like:

var PreDashboard = React.createClass({
  mixins: [ AsyncElement ],
  bundle: function(cb) {
      require.ensure([], function(require) {
          cb(require('./dashboard.js'));
      });
  },
  preRender: function () {
    return <div>Loading dashboard...</div>;
  }
});

// Or using ES6 fat arrow functions

var PreDashboard = React.createClass({
  mixins: [ AsyncElement ],
  bundle: (cb) => {
      require.ensure([], (require) => {
          cb(require('./dashboard.js'));
      });
  },
  preRender: function () {
    return <div>Loading dashboard...</div>;
  }
});

This will still use the load function from AsyncElement and should replicate the functionality you had previously with the bundle-loader. Let me know if it works!

0reactions
ryanflorencecommented, Sep 9, 2015

you just shim require.ensure in node-land to be synchronous and then it can work. I haven’t done it yet, but there will eventually be a demo.

Read more comments on GitHub >

github_iconTop Results From Across the Web

partial-app-loading for an isomorphic app · Issue #1435 - GitHub
Looking at the partial-app-loading example, it seems it will work only for client side: var PreDashboard = React.
Read more >
What is an isomorphic application? - Lullabot
In web development, an isomorphic application is one whose code (in this case, JavaScript) can run both in the server and the client....
Read more >
An Introduction to Isomorphic Web Application Architecture
An isomorphic app is a web app that blends a server-rendered web app with a single-page application. On the one hand, we want...
Read more >
Chapter 1. Introduction to isomorphic web application ...
An isomorphic app is a web app that blends a server-rendered web app with a single-page application. On the one hand, we want...
Read more >
The Pain and the Joy of creating isomorphic apps in ReactJS
Writing isomorphic application is the simplest and the most suitable solution in this case. What parts of your app should be isomorphic?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found