Giter Site home page Giter Site logo

react-page's Introduction


This project is not actively maintained. Proceed at your own risk!


  • Render [React](http://www.github.com/facebook/react/) pages on the server or client - _effortlessly_.

  • Use CommonJS to build and share UI components.

  • Develop rapidly - instant reloading.


##Install (Mac/Linux - requires a recent version of node/npm)

Clone this project

git clone https://github.com/facebook/react-page
cd react-page
npm install                            # install dependencies.

Try out the server rendering

node server.js
# open http://localhost:8080/index.html
# Make changes to src/index.js, and refresh instantly!

##Philosophy

Why Server Rendering?
  • Faster Pages: Markup displayed before downloading JS (with SEO benefits)
  • Page generation on a fast server vs. low power client devices.
  • Instantly refresh while developing.
  • Static content sites: As easy as a single wget command.
Why React?
  • React is a client/server rendering framework from the ground up.
  • When performance constraints change, simply change where you render it - don't change your app.
  • React is functional. Explore the documentation on the React Github Page.
  • Server rendering optional - you can always just use React as a declarative client side framework.

##Developing

Default Project Structure

The included directory structure suggests a way to organize a single or multi-page app. npm install other components/libraries and they automatically work. It's the same commonJS that you know and love.

react-page/
 ├── package.json                # Add npm dependencies here.
 ├── server.js                   # Start web server with `node server.js`
 ├── ...                         # Create more pages/directories here
 └── src                         # All your application JS.
     ├── elements/               # Shared React components.
     │   ├── SiteBoilerPlate.js  # Reusable html/body component
     │   └── Banner.js           # An example component for displaying text
     │
     ├── index.js                # localhost:8080/index.html routed here
     └── pages                   # Make your site structure
         └── about.js            # localhost:8080/pages/about.html

Everything Is A Component

React's philosophy is that mutation-minimal functions and composition are the best tools for building sophisticated applications with low complexity. In React, "components" are the tool for composing. react-page embraces this simplicity, even allowing the entire page to be expressed as an arbitrarily deep composition of components.

react-page/src/index.js corresponds to index.html. index.js is a React component that renders the <html>,<body>, and all the contents of the page.

If you look at index.js, you'll notice that it doesn't output all the <div>s and <span>s directly - it composes other components that take on much of that responsibility. index.js composes a <Banner> component, and inside of Banner.js, you'll see that the implementation of <Banner> outputs an <h1> DOM component. Even DOM representations such as <h1> are components in React

To build out your app, just add or install more components with npm.

Simple Default Page Routing

Requests to path/file.html are routed to your React component located at src/path/file.js. By default all page requests are routed to the src directory, but you can customize that behavior via the pageRouteRoot setting.

Here are a couple of examples of the default configuration:

http://localhost:8080/index.html => react-page/src/pages/index.js
http://localhost:8080/docs/hello.html => react-page/src/pages/docs/hello.js
http://localhost:8080/pages/about.html => react-page/src/pages/about/index.js
http://localhost:8080/path/img.png => react-page/src/path/img.png
  • Currently, every html routing must map to a .js file that exports a single React component, that renders the page, including html/body tags.
  • Routing is customizable (more later).

How Does Server Rendering Work?

  • react-page computes page markup on the server, sends it to the client so the user can see it quickly.
  • The corresponding JavaScript is then packaged and sent.
  • The browser runs that JavaScript, so that all of the event handlers, interactions and update code will run seamlessly on top of the server generated markup.
  • From the developer's (and the user's) perspective, it's just as if the rendering occurred on the client, only faster.

Command Line Usage:

# --useSourceMaps=true        # default:true
# --useBrowserBuiltins=false  # Allow node modules (util)  - default:false
# --logTiming=true            # Shows colored timing metrics - default:true
# --pageRouteRoot=<root_dir>  # page URLs root - default: react-page/src

# for example:
node server.js --useSourceMaps=true

Node Modules in the Browser: You can use modules installed via npm, but if anything requires builtin modules (such as util), make sure to enable the useBrowserBuiltins option.

React As A Blogging Engine:

React can power dynamic, network-connected apps. But with react-page, React can also be used to build a static blog, Github documentation, or any other static site. Because react-page uses server rendering, creating a static site is as easy as a single wget command.

node server.js
wget -mpck --user-agent="" -e robots=off http://localhost:8080/index.html

Get wget on OS X: try http://osxdaily.com/2012/05/22/install-wget-mac-os-x/ or if you have brew: brew install wget

This prebuilds your entire interactive site, so it can be served from a file server or github etc. Don't forget to enable gzip on your file server! React markup is large but compresses very well.

Motivations/Next-Steps:

-react-page is a rapid development environment for experimenting with new ways of building production web apps powered by React. It provides a common environment that allows sharing of modules client/server architecture prototypes.

In order to use this technology in a production environment, you must audit and verify that the server rendering strategy is safe and suitable for your purposes.

  • You must ensure that a proper server sandbox is enforced. However, react-page does run your UI rendering code inside of contextify as a preliminary sandbox.

  • In production, the js packaging features of react-page should be performed ahead of time and stored in a CDN. However, dynamic server rendering is a compelling production feature.

  • Additional connect middleware should be added to prevent stack traces from showing up in browser.

TODO:

  • Windows support (depends on fixing facebookarchive/node-haste#2)
  • Allow sharing of css/images through npm packages.
  • Experiments with optimizing page load time - incremental streaming of markup/resources.
  • Advanced packaging such as splitting projects into several independently cacheable sub-packages.
  • require('image/path/img.jpg') should resolve to image path.
  • A way to automatically package/bundle css, regardless of file path of depending js resource. (using require('commonJSPath/to/css.css'))

react-page's People

Contributors

ammit avatar jordwalke avatar joshduck avatar kassens avatar pborreli avatar petehunt avatar rboyce avatar sebmarkbage avatar steveluscher avatar stoyan avatar subtlegradient avatar vjeux avatar zpao 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-page's Issues

Error with --dev=true

node server.js --dev=true

Bundling 105 JS files for /index.html   -   HTML blocks UI, JS Gen does not
----------------------------------------------------------------------------------------------------------------------------------------------------
HTML Gen: find/transform 618ms (WARMING UP ON FIRST LOAD)                                                  c render 223ms                       se

Error: ERROR RENDERING PAGE ON SERVER:
<mapped error>
ReferenceError: window is not defined
    at /Volumes/Data/Users/stevo/git/react-page/node_modules/react-tools/src/test/ReactDefaultPerf.js:409:21
    at require (/Volumes/Data/Users/stevo/git/react-page/node_modules/react-page-middleware/polyfill/require.js:232:25)
    at Object.inject (/Volumes/Data/Users/stevo/git/react-page/node_modules/react-tools/src/core/ReactDefaultInjection.js:71:39)
    at /Volumes/Data/Users/stevo/git/react-page/node_modules/react-tools/src/core/React.js:32:23
    at require (/Volumes/Data/Users/stevo/git/react-page/node_modules/react-page-middleware/polyfill/require.js:232:25)
    at /Volumes/Data/Users/stevo/git/react-page/src/elements/VectorWidget/VectorWidget.js:143:16
    at Object.Contextify.sandbox.run (/Volumes/Data/Users/stevo/git/react-page/node_modules/react-page-middleware/node_modules/contextify/lib/contextify.js:12:24)
    at renderReactPage (/Volumes/Data/Users/stevo/git/react-page/node_modules/react-page-middleware/src/renderReactPage.js:77:13)
    at renderedBundledText (/Volumes/Data/Users/stevo/git/react-page/node_modules/react-page-middleware/src/index.js:165:5)
    at /Volumes/Data/Users/stevo/git/react-page/node_modules/react-page-middleware/src/guard.js:29:10
</mapped error>

    at renderReactPage (/Volumes/Data/Users/stevo/git/react-page/node_modules/react-page-middleware/src/renderReactPage.js:99:18)
    at renderedBundledText (/Volumes/Data/Users/stevo/git/react-page/node_modules/react-page-middleware/src/index.js:165:5)
    at /Volumes/Data/Users/stevo/git/react-page/node_modules/react-page-middleware/src/guard.js:29:10
    at Packager.computePackageForAbsolutePath.merge.onComputePackageDone (/Volumes/Data/Users/stevo/git/react-page/node_modules/react-page-middleware/src/index.js:140:7)
    at Object.onComputePackageDone (/Volumes/Data/Users/stevo/git/react-page/node_modules/react-page-middleware/src/guard.js:29:10)
    at onWarmed (/Volumes/Data/Users/stevo/git/react-page/node_modules/react-page-middleware/src/Packager.js:259:17)
    at /Volumes/Data/Users/stevo/git/react-page/node_modules/react-page-middleware/node_modules/async/lib/async.js:116:25
    at /Volumes/Data/Users/stevo/git/react-page/node_modules/react-page-middleware/node_modules/async/lib/async.js:24:16
    at warmCache (/Volumes/Data/Users/stevo/git/react-page/node_modules/react-page-middleware/src/Packager.js:222:5)
    at /Volumes/Data/Users/stevo/git/react-page/node_modules/react-page-middleware/node_modules/async/lib/async.js:108:13

npm install fails

On a new machine, with the latest Node and NPM, doing npm install gives the error below. It seems strange that it would complain about Xcode.

Also, apparently react-tools should be installed globally. Is this really required? I want to put this on my web server, and would rather not muck about with folders that require root access.

npm http 304 https://registry.npmjs.org/amdefine
xcode-select: Error: No Xcode is selected. Use xcode-select -switch , or see the xcode-select manpage (man xcode-select) for further information.

gyp: Error 2 running xcodebuild
gyp ERR! configure error
gyp ERR! stack Error: gyp failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:424:16)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Darwin 12.4.1
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/shaneos/Dev/react-page/node_modules/react-page-middleware/node_modules/contextify
gyp ERR! node -v v0.10.18
gyp ERR! node-gyp -v v0.10.9
gyp ERR! not ok
npm http 304 https://registry.npmjs.org/esprima-fb/1001.1001.1000-dev-harmony-fb
npm ERR! Error: ENOENT, open '/Users/shaneos/Dev/react-page/node_modules/react-page-middleware/node_modules/node-haste/node_modules/esprima-fb/.npmignore'
npm ERR! If you need help, you may report this log at:
npm ERR! http://github.com/isaacs/npm/issues
npm ERR! or email it to:
npm ERR! [email protected]

npm ERR! System Darwin 12.4.1
npm ERR! command "node" "/usr/local/bin/npm" "install"
npm ERR! cwd /Users/shaneos/Dev/react-page
npm ERR! node -v v0.10.18
npm ERR! npm -v 1.3.8
npm ERR! path /Users/shaneos/Dev/react-page/node_modules/react-page-middleware/node_modules/node-haste/node_modules/esprima-fb/.npmignore
npm ERR! code ENOENT
npm ERR! errno 34

Reload subcomponent code on the fly.

A special feature just for React modules - it probably wouldn't make sense to build into node-haste, so react-page-middleware is suitable.

If we detect that a js module file has changed, and it parses correctly - we should push that new module code - and only that new module code to the browser. We should write a react-specific reloadReactModule function that patches deep component instances to have the new prototype/methods of the newly injected module (including the new render function) - but preserve all the existing page state. So the end result is that as you type, just the nested components that you effect by typing are reloaded and dynamically rerendered every x milliseconds.

Diverged dependencies (error on startup)

Running node 0.10.24

I'm getting the following error:
> node server.js

/Users/parris/Projects/react-page/node_modules/react-page-middleware/src/Packager.js:36
 reactVisitors = require('react-tools/vendor/fbtransform/visitors').getVisitor
                                                                ^
TypeError: Object #<Object> has no method 'getVisitorsList'

I am guessing react-tools has diverged from react-page.

I would comment on those projects; however, I noticed that the tools are just being hosted through git. Perhaps those git repos should be replaced with the npm packages or have a specific git tag associated with them.

500 Error: Syntax Error: /home/[..]/react-page/src/index.js TypeError: Object #<Object> has no method 'traverse'

Good people!
I'm getting the below error upon doing a clean git clone and npm install. Not sure if this is a bug or just me doing something stupid. I'm running node 0.10.21 on ubuntu 13.10.

"500 Error: Syntax Error: /home/henke/annat/react-page/src/index.js TypeError: Object # has no method 'traverse'
at transformModuleImpl (/home/henke/annat/react-page/node_modules/react-page-middleware/src/Packager.js:221:7)
at /home/henke/annat/react-page/node_modules/react-page-middleware/src/Packager.js:245:9
at fs.js:266:14
at Object.oncomplete (fs.js:107:15)"

Any thoughts?

Thanks a lot.

Remove react-styles dependency

I think it would be good if the basic react-page example would be more minimal and not rely on additional proprietary code. Additions such as react-styles add complexity that users have to understand at the same time they're trying to understand React itself.
I think a better place to demonstrate add-ons would be in separate sub-pages or branches.

Some css rules disappear on server rendering

I was trying out the server rendering feature on react-page with the default contents, and after deactivating JS on my browser (Chrome), I noticed something wasn't quite all right. The HTML is there, but it wasn't rendering properly.

After some debugging, I realized the 'h1.banner.fadeIn' rule was disappearing somewhere along the pipeline. That doesn't happen when JS is activated, so I assume the client side JS takes care of rendering that.

This is weird because the same component is used on both sides. I tried to debug the issue but can't really tell where the rule is disappearing and if this is an issue with react-page or react-styles.

Transform errors are particularly obscure.

@shaneosullivan reported a server error as:

500 Error: ERROR RENDERING PAGE ON SERVER: <mapped error> SyntaxError: Unexpected identifier at Object.Contextify.sandbox.run

I'm not sure why a syntax error would happen on the server - everything is transformed prior - but I'd like to look into this.

Node Module Problems (LevelUp)

So, I am having trouble using the node module LevelUp in my react-page project. I am requiring the module here and, initially, I get the following error from one of LevelUps dependencies, complaining that Buffer has not been defined (which is odd, browser-builtins contains buffer-browserify): https://gist.github.com/lyaunzbe/6344834. If I manually add Buffer = require('buffer').Buffer to the file that produces this error, this seems to take away the Buffer issue, but now leaves me with the following error message: https://gist.github.com/lyaunzbe/6345026. You guys have been super supportive and helpful throughout, so I just want to thank you in advance for putting up with my annoying requests :)

Cannot set property 'mtime' of null

Hello,
I'm evaluating React as a view replacement, trying to see how it works for server-side rendering.

My project is using the following developer dependencies:

{"devDependencies": {
    "bower": "~1.2.8",
    "grunt": "~0.4.2",
    "grunt-bower-requirejs": "~0.8.0",
    "grunt-contrib-clean": "~0.5.0",
    "grunt-contrib-compass": "~0.7.0",
    "grunt-contrib-concat": "~0.3.0",
    "grunt-contrib-copy": "~0.5.0",
    "grunt-contrib-cssmin": "~0.7.0",
    "grunt-contrib-htmlmin": "~0.1.3",
    "grunt-contrib-jasmine": "~0.5.2",
    "grunt-contrib-jshint": "~0.8.0",
    "grunt-contrib-uglify": "~0.2.7",
    "grunt-contrib-watch": "~0.5.3",
    "grunt-nginx": "~0.2.1",
    "grunt-open": "~0.2.2",
    "grunt-react": "~0.6.0",
    "grunt-requirejs": "~0.4.0",
    "grunt-rev": "~0.1.0",
    "grunt-usemin": "~2.0.2",
    "jshint-stylish": "~0.1.4",
    "load-grunt-tasks": "~0.2.1",
    "time-grunt": "~0.2.5"
  }
}

...just add them to the react-page's package.json, run npm install and then node server.

Now when I visit localhost:8080/index.html, I get the error Cannot set property 'mtime' of null.

/react-page/node_modules/react-page-middleware/node_modules/node-haste/lib/MapUpdateTask.js:179
          resource.mtime = record.mtime;
                         ^
TypeError: Cannot set property 'mtime' of null
    at ~/Development/react-page/node_modules/react-page-middleware/node_modules/node-haste/lib/MapUpdateTask.js:179:26
    at ~/Development/react-page/node_modules/react-page-middleware/node_modules/node-haste/lib/loader/ResourceLoader.js:88:7
    at fs.js:207:20
    at Object.oncomplete (fs.js:107:15)

After diving a bit into react-page-middleware/node-haste code I'm asking here for help since I can't find the cause of the problem.

For curiosity, why is node-haste looking into node_modules? The first-page load is also much slower when adding other modules. It would be nice to have a more in-depth documentation on how the middleware works.

Thank you!

Better support for <script>

&lt;script> is a bit hard to use right now.

  • If you have a {...} then it's going to start interpolating. And you are bound to have whenever you use if, function ... Workaround: you can wrap it inside of an interpolated string {'if (true) { ... }'}
  • If you have any ' or " it's going to output the html encoded version and Javascript is going to throw a parsing exception.

In order to workaround those two issues the best way I found is to use dangerouslySetInnerHTML and use ES6 backtick in order to have multi-line strings.

<script dangerouslySetInnerHTML={{__html: `
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  ga('send', 'pageview');
`}} />

We should probably make it easier, it's quite a pain to use right now.

Doesn't work on modern Firefox

The default page doesn't work properly on Firefox. The VectorWidget functionality (spinning and spinning faster when clicked) is not there.

ReferenceError: document is not defined

With the current state of the app, I am getting the following error after starting the server with node server.js and requesting a page at http://localhost:8080/:

Error: ERROR RENDERING PAGE ON SERVER:
<mapped error>
ReferenceError: document is not defined
    at /Users/ypinar/Tmp/react-page/node_modules/react-tools/src/core/ReactDOMSelection.js:152:8
    at require (/Users/ypinar/Tmp/react-page/node_modules/react-page-middleware/polyfill/require.js:232:25)
    at /Users/ypinar/Tmp/react-page/node_modules/react-tools/src/core/ReactInputSelection.js:21:25
    at require (/Users/ypinar/Tmp/react-page/node_modules/react-page-middleware/polyfill/require.js:232:25)
    at /Users/ypinar/Tmp/react-page/node_modules/react-tools/src/core/ReactReconcileTransaction.js:25:27
    at require (/Users/ypinar/Tmp/react-page/node_modules/react-page-middleware/polyfill/require.js:232:25)
    at /Users/ypinar/Tmp/react-page/node_modules/react-tools/src/core/ReactComponentBrowserEnvironment.js:26:33
    at require (/Users/ypinar/Tmp/react-page/node_modules/react-page-middleware/polyfill/require.js:232:25)
    at /Users/ypinar/Tmp/react-page/node_modules/react-tools/src/core/ReactComponentEnvironment.js:20:3
    at require (/Users/ypinar/Tmp/react-page/node_modules/react-page-middleware/polyfill/require.js:232:25)
</mapped error>

    at renderReactPage (/Users/ypinar/Tmp/react-page/node_modules/react-page-middleware/src/renderReactPage.js:99:18)
    at renderedBundledText (/Users/ypinar/Tmp/react-page/node_modules/react-page-middleware/src/index.js:171:5)
    at /Users/ypinar/Tmp/react-page/node_modules/react-page-middleware/src/guard.js:29:10
    at Packager.computePackageForAbsolutePath.merge.onComputePackageDone (/Users/ypinar/Tmp/react-page/node_modules/react-page-middleware/src/index.js:146:7)
    at Object.onComputePackageDone (/Users/ypinar/Tmp/react-page/node_modules/react-page-middleware/src/guard.js:29:10)
    at onWarmed (/Users/ypinar/Tmp/react-page/node_modules/react-page-middleware/src/Packager.js:268:17)
    at /Users/ypinar/Tmp/react-page/node_modules/react-page-middleware/node_modules/async/lib/async.js:116:25
    at /Users/ypinar/Tmp/react-page/node_modules/react-page-middleware/node_modules/async/lib/async.js:24:16
    at /Users/ypinar/Tmp/react-page/node_modules/react-page-middleware/src/Packager.js:235:7
    at fs.js:266:14

Asynchronous server-side rendering (follow-up of Stackoverflow/Twitter discussion)

This is a follow-up from http://stackoverflow.com/questions/20815423/how-to-render-asynchronously-initialized-components-on-the-server & https://twitter.com/elierotenberg/status/418358101880762368

Practical single-page apps are often rendered on the client asynchronously, usually dynamically issuing ajax requests to load parts of the content. Even on the server side, the full rendering often relies on asynchronous operations following node's non blocking, asynchronous paradigm, e.g. db queries or delegated services implementing a network API (REST or w/e). In addition, if the data/models are exposed via an asynchronous web service (usually ajax, or websockets), asynchronously rendered page can induce significant latency due to network roundtrips, which can be effectively handled by the server (either by ensuring that the server operating the rendering is efficently connected to the data service and/or by maintaining a data cache on the server).

I think the right place to initiate asynchronous loading is in ReactComponent.componentWillMount (since its called when using React.renderComponentToString prior to calling ReactComponent.render while React.componentDidMount isn't). However, React.renderComponentToString and the underlying rendering stack is synchronous; which means there is no simple way (or atleast I couldn't think of one) to perform complete server-side rendering of asynchronously-rendered pages. It might be worked around using a "global" per-request synchronization object containing the promises of the asynchronous operations involved, but I've found it to be tricky at best. Supporting asynchronous rendering would allow practical SPA to be rendered on the server.

React needs a special code-path for reconciling different component types rendered into HTML element

Currently React blows away entire markup during reconciliation if prev and next components have different constructors. That's not good for components rendered directly into <html> element — for example if some stylesheets were removed and then appended during reconciliation — page would blink.

In react-app I solve this by declaring that pages are not components but specifications which are mounted into a single long-lived Page component which is responsible to delegate render() and other lifecycle calls to such specifications.

The requirement for such page specification is to always return <html> markup from a render() call.

This works well but creates an indirection layer where top-level components are not components but pages. I'd rather like them to be the same so I was wondering if it's possible to add a special code-path to react reconciliation mechanism for handling <html> element re-renders.

Small Question About Using Other Node Modules

Hello! This is really great so far, definitely an improvement over reactapp. Just one small thing: How would I use other modules I have npm installed in my React components? It seems like react-middleware might not be bundling any of my other node modules besides React, or I may be missing something else more obvious? Thanks for all your help. Cheers 👍

Cannot switch top level component type.

We should document the limitation here, and possibly fix this in the react core. When the top level component type switches, we can't innerHTML the entire document, so we might need to special case it. Thanks to @andreypopp for finding this one.

Demonstrate/document/support NPM to share React components.

Right now, sharing of React components through NPM should work. However, there's still some questions about how components would render images with paths that refer to resources in their own npm module folder. They may be relative to their JS file, but JS files are packaged (as they should be) into a monolithic build - the contents' relative image urls would be incorrect.

I'll experiment with the ability to use commonJS path resolution for image URLs. That way npm projects can also expose their own resources (useful when mixing in/composing components).

<img src={require('yourProject/images/logo.png')} />
<img src={require('./insideMyProject/logo.png')} />

The reason why I suggest require() is because we can easily support it in react-page, but also because any React component deployed to to npm could work outside of react-page. Any node environment can implement custom handlers for image extensions such that it behaves exactly like react-page.

I'm looking for any solution satisfying:

  1. Easily share components with anyone through NPM.
  2. Relative image urls work in familiar way (commonJS require a strong candidate).
  3. A reasonable solution can/should easily be implementable outside of react-page.

No way to add in doctype

There does not appear to be any way to add in a doctype to React pages. The included example SiteBoilerPlate does not include any, and at least I cannot figure out how to modify the JSX to allow it. Perhaps this could be an option for the react-page-middleware if JSX/React is insufficient?

Why is this abandoned?

@jordwalke + @zpao

There's a fat banner on the top of your readme that says:

This project is not actively maintained. Proceed at your own risk!

While I appreciate the warning, more detail would be helpful. Did you reach a dead-end while working on react-page? Is there a similar project that better solves this problem? Is it simply a matter of not having the resources to continue dev? Would you recommend others pick up where you left off?

Answers to some of these questions would be really helpful in understanding the best practices for using React on the server. (The SEO benefit from React's client/server agnosticism is a huge selling point for my team.)

console not available

When running react-page with --dev=true, the console warning about a missing key on a react component turns into a page fatal because console is not available in the sandbox. Not sure what the right solution is here, should node's console object be forwarded into the sandbox?

ReferenceError: console is not defined
at validateExplicitKey (./node_modules/react-tools/src/core/ReactComponent.js:103:3)
at validateChildKeys (./node_modules/react-tools/src/core/ReactComponent.js:119:9)
at ReactComponent.Mixin.merge.construct (./node_modules/react-tools/src/core/ReactComponent.js:308:11)
at Object.ConvenienceConstructor [as div] (./node_modules/react-tools/src/core/ReactDOM.js:48:24)
...

Similar to #13.

Requires node 0.10

Got an error with node 0.8.

package.info should include something like:

"engine": "node >= 0.10"

Error in Windows 7

When requesting a page http://localhost:8080/index.html get the following error:

I am running on Windows 7

Connect
500 Error: No modules for:C:\Users\lilo003\Downloads\react-page-master\src\index.js
at onWarmed (C:\Users\lilo003\Downloads\react-page-master\node_modules\react-page-middleware\src\Packager.js:267:13)
at Object.async.each (C:\Users\lilo003\Downloads\react-page-master\node_modules\react-page-middleware\node_modules\async\lib\async.js:104:20)
at Object.onModuleDependenciesLoaded as done
at MapUpdateTask. (C:\Users\lilo003\Downloads\react-page-master\node_modules\react-page-middleware\node_modules\node-haste\lib\HasteDependencyLoader.js:103:13)
at MapUpdateTask.EventEmitter.emit (events.js:117:20)
at MapUpdateTask. (C:\Users\lilo003\Downloads\react-page-master\node_modules\react-page-middleware\node_modules\node-haste\lib\MapUpdateTask.js:80:18)
at finished (C:\Users\lilo003\Downloads\react-page-master\node_modules\react-page-middleware\node_modules\node-haste\lib\MapUpdateTask.js:267:16)
at C:\Users\lilo003\Downloads\react-page-master\node_modules\react-page-middleware\node_modules\node-haste\lib\loader\ResourceLoader.js:145:5
at process._tickCallback (node.js:415:13)

Ciro

Clarify how to share a component between server and client

I got to hello world with this:

/**
 *
 * @jsx React.DOM
 */

var React = require('React');
var SiteBoilerPlate = require('../core/SiteBoilerPlate.js');
var Banner = require('../elements/Banner/Banner.js');

var hello = React.createClass({

  render: function() {
    return (
      <SiteBoilerPlate>
        <h1>HELLLLOO!!!!!111</h1>
      </SiteBoilerPlate>
    );
  }
});

module.exports = hello;

I'm wondering how I access this component from the client. I'm assuming that as it stands now, if I fire up node server.js and visit localhost:8080/pages/hello.html, that this is all rendered on the server. How would I render this from the client?

Perhaps the answer is obvious, but it's not obvious to me, and maybe many others.

500: No modules for C:\[...]\react-page\app\index.js

everything is up to date, latest version
Did npm install and what not

When trying to run the server and accessing index.html I get this error:

Error: No modules for:C:[...]\react-page\app\index.js
at onWarmed (C:[...]\react-page\node_modules\react-page-middleware\src\Packager.js:267:13)
at Object.async.each (C:[...]\react-page\node_modules\react-page-middleware\node_modules\async\lib\async.js:104:20)
at Object.onModuleDependenciesLoaded as done
at MapUpdateTask. (C:[...]\react-page\node_modules\react-page-middleware\node_modules\node-haste\lib\HasteDependencyLoader.js:103:13)
at MapUpdateTask.EventEmitter.emit (events.js:117:20)
at MapUpdateTask. (C:[...]\react-page\node_modules\react-page-middleware\node_modules\node-haste\lib\MapUpdateTask.js:80:18)
at finished (C:[...]\react-page\node_modules\react-page-middleware\node_modules\node-haste\lib\MapUpdateTask.js:267:16)
at C:[...]\react-page\node_modules\react-page-middleware\node_modules\node-haste\lib\loader\ResourceLoader.js:145:5
at process._tickCallback (node.js:415:13)

Allow injectable transforms

Different people will want to use different less/coffeescript syntaxes. We should let them specify which transforms they want, and somehow ensure that it plays well with react-page's own transforms.

Missing attributes for <meta>

Input:

<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta property="og:type" content="website" />

Output:

<meta />
<meta content="IE=edge,chrome=1" />
<meta content="website" />

Missing:

  • charset
  • http-equiv
  • property

Syntax error crashes node server

Open http://localhost:8080/index.html

/Users/phunt/Projects/preparable-react/node_modules/react-page-middleware/node_modules/react-tools/vendor/fbtransform/lib/transform.js:99
throw e;
^
Error: Parse Error: Line 418: Unexpected token )
at throwError (/Users/phunt/Projects/preparable-react/node_modules/react-page-middleware/node_modules/react-tools/node_modules/esprima/esprima.js:2132:21)
at throwUnexpected (/Users/phunt/Projects/preparable-react/node_modules/react-page-middleware/node_modules/react-tools/node_modules/esprima/esprima.js:2194:9)
at parseVariableIdentifier (/Users/phunt/Projects/preparable-react/node_modules/react-page-middleware/node_modules/react-tools/node_modules/esprima/esprima.js:3251:13)
at /Users/phunt/Projects/preparable-react/node_modules/react-page-middleware/node_modules/react-tools/node_modules/esprima/esprima.js:5717:38
at parseObjectProperty (/Users/phunt/Projects/preparable-react/node_modules/react-page-middleware/node_modules/react-tools/node_modules/esprima/esprima.js:2448:27)
at /Users/phunt/Projects/preparable-react/node_modules/react-page-middleware/node_modules/react-tools/node_modules/esprima/esprima.js:5717:38
at parseObjectInitialiser (/Users/phunt/Projects/preparable-react/node_modules/react-page-middleware/node_modules/react-tools/node_modules/esprima/esprima.js:2492:24)
at parsePrimaryExpression (/Users/phunt/Projects/preparable-react/node_modules/react-page-middleware/node_modules/react-tools/node_modules/esprima/esprima.js:2635:20)
at /Users/phunt/Projects/preparable-react/node_modules/react-page-middleware/node_modules/react-tools/node_modules/esprima/esprima.js:5717:38
at trackLeftHandSideExpressionAllowCall (/Users/phunt/Projects/preparable-react/node_modules/react-page-middleware/node_modules/react-tools/node_modules/esprima/esprima.js:5617:61)

Server then promptly dies and I'm back in bash.

Won't load. There is no visitors.js file in directory fbtransform

Won't load. There is no visitors.js file in directory fbtransform. Here is the message I get when I enter "node server" in my Linux terminal or try "build" in Sublime Text:
reactVisitors = require('react-tools/vendor/fbtransform/visitors').getVisitor
^
TypeError: Object # has no method 'getVisitorsList'
at Object. (/home/a/1_1_react_page/react-page/node_modules/react-page-middleware/src/Packager.js:36:72)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object. (/home/a/1_1_react_page/react-page/node_modules/react-page-middleware/src/index.js:18:16)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)

Routing example is wrong

It says:

http://localhost:8080/about => react-page/src/pages/about/index.js

However, if I go to /about I get the following error:

500 Error: Following module not in specified search paths: /home/vjeux/www/github/react-page/src/about/index.js

In order to render react-page/src/pages/about/index.js, I have to go to :8080/pages/about.html

Uncaught Error on localhost (local machine)

I have trouble running clean react-page clone on local machine. It always throws this exception in client chrome console:

Uncaught Error Requiring unknown module "es5-shim/es5-shim.js" E:\react-page\node_modules\react-page-middleware\polyfill\require.js:187

On server runs everything ok.

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.