Skip to content
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

Support for OOTB isomorphic rendering #267

Closed
robframpton opened this issue Oct 2, 2017 · 4 comments
Closed

Support for OOTB isomorphic rendering #267

robframpton opened this issue Oct 2, 2017 · 4 comments
Assignees
Milestone

Comments

@robframpton
Copy link

robframpton commented Oct 2, 2017

It's currently possible to achieve server side rendering of Metal.js components, but it requires libraries such as https://www.npmjs.com/package/jsdom to accomplish.

// Node.js 
const JSDOM = require('jsdom').JSDOM;

const { document } = (new JSDOM()).window;

global.document = document;
global.window = document;

const Component = require('metal-component').Component;

const MyComponent = require('./MyComponent').MyComponent;

const htmlString = Component.renderToString(MyComponent);

However, it would be nice to have out of the box isomorphic rendering.

// Node.js 
const Component = require('metal-component').Component;

const MyComponent = require('./MyComponent').MyComponent;

const htmlString = Component.renderToString(MyComponent);

I have sent the following three pull requests relating to server side rendering of components.

#264 (metal-dom)
#265 (metal-soy)
#266 (metal-incremental-dom)

With these changes the second code snippet above should work correctly in a Node.js environment. Once/if these branches are merged, I would like to create a server side integration test separate from the current testing environment we have set up for this repo to test this functionality.

Update: I've sent another PR that adds a simple test for server side rendering.

#269

@brunobasto
Copy link

Awesome, Rob!

@jbalsas jbalsas added this to the 2.14.0 milestone Oct 3, 2017
@jbalsas
Copy link
Contributor

jbalsas commented Oct 3, 2017

Nice!!

@Robert-Frampton, following the example of the WebComponents story, could we prepare a guide on top of https://github.com/Robert-Frampton/metaljs.com/commits/tutorials?

robframpton pushed a commit to robframpton/metaljs.com that referenced this issue Oct 3, 2017
@robframpton
Copy link
Author

Hey @jbalsas

I sent a separate PR bryceosterhaus/metaljs.com#70.

@jbalsas
Copy link
Contributor

jbalsas commented Oct 11, 2017

All pieces have been merged into develop!

@jbalsas jbalsas closed this as completed Oct 11, 2017
robframpton pushed a commit to bryceosterhaus/metaljs.com that referenced this issue Oct 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants