Skip to content

Separate build code from runtime code #797

@jhnns

Description

@jhnns

Following up #794


Currently, the react-server-cli generates code that is dependent on data that is provided on build time (like the routes file) or the clientBootstrapFile.

Since this code is part of the react-server runtime, it should imho be located in the react-server package. All the dynamic stuff like logging options and routes should be provided by static objects that are generated on build time (and are not actually written to disk).

This way, it's easier to reason about the actual code since code generation can quickly become messy. The clientBootstrapFile, for instance, would look like this:

if (typeof window !== "undefined") {
	window.__setReactServerBase = function(path) {
		__webpack_public_path__ = path;
		window.__reactServerBase = path;
	}
}
var reactServer = require("react-server");

// dynamic modules generated on build time
var options = require("react-server/options");
var routes = require("react-server/routes");

window.rfBootstrap = function() {
	reactServer.logging.setLevel('main', options.logLevel);
	reactServer.logging.setLevel('time', options.timingLogLevel);
	reactServer.logging.setLevel('gauge', options.gaugeLogLevel);
	new reactServer.ClientController({routes: routes}).init();
}

It also provides a cleaner separation of react-server and react-server-cli which means that I could use my own react-server-cli if the cli is too invasive for my taste. Ideally, it would even be possible to use another bundler but that is beyond my personal scope.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions