Comments (6)
Right now I'm experimenting with kind of skipping vision altogether by hooking up reply
with reply.renderReact()
which (simplified for clarity) looks kinda like this:
renderView.js
(+ server.decorate('reply', 'renderReact', require('./lib/renderView.js'));
)
module.exports = function(view, dataFromController) {
const data = extend(someDataWithLocaleOrOtherServerStuff, dataFromController);
const Component = require(`../components/${view}.js`);
const componentRenderer = render(<Component {...data} />);
const responseRenderer = template`
<html>
<head>
[...]
<div id="app-mount">${componentRenderer}</div>
[...]
<script id="app-state">
window.state = ${() => JSON.stringify(data)}
document.querySelector("#app-mount").setAttribute("data-react-checksum", "${componentRenderer.checksum()}")
</script>
<script src="/scripts/client.js"></script>
</body>
</html>
`;
const stream = responseRenderer.toStream();
this(stream);
}
someController.js
reply.renderReact('home', {
title: 'Home',
records: someDatabaseResult,
});
Which feels wrong but works surprisingly well.
from hapi-react-views.
Thanks for opening an issue. I'm time poor right now. Though, I'd be interested in what this would/could look like and how we'd integrate (optionally) rapscallion
in this module.
from hapi-react-views.
@tom2strobl I'd love for vision
to have a great solution for server-side React rendering (like this lib here!) -- what would be your ideal interface as far as passing options? Would anything else drive your decision besides streaming?
from hapi-react-views.
React v16 supports streaming:
Even though streaming isn't totally general purpose (there are some gotchas), I'm much more inclined to try incorporating a streaming API in hapi-react-views
now that's it's officially part of React.
Is rapscallion
still needed?
from hapi-react-views.
@wswoodruff to be honest we moved away from hapi directly serving client markup at all. We run next.js and it's getInitialProps
in the front and regular hapi in the back (and merged the next-handler into hapi to have one single clean server) and all data APIs and client templates are separated. Vision does both at the same time, gathering data and then rendering markup from a template. The age of code splitting, lazy loading and prefetching made things a little more complex…
from hapi-react-views.
@tom2strobl Cool! I haven't delved too much into SSR for React yet, seems like a great setup!
from hapi-react-views.
Related Issues (20)
- Update dependencies HOT 5
- Update readme examples for new version of hapijs/glue HOT 1
- React: onClick does not work HOT 3
- Layout feature proposal HOT 12
- Layout feature requires JSX file extension HOT 3
- Babel transpile JSX to JS - Handling for different file extensions HOT 7
- Support removeCache option for any file extension HOT 1
- Push State and static files HOT 2
- Babel-register on production HOT 1
- How do I set the `title` when using a layout? HOT 2
- how to pass props to layout? HOT 1
- Update to react v16 HOT 1
- Git Clone Link not working HOT 1
- Not issue but recommendation for updating documentation HOT 1
- additional rendering options HOT 2
- Update dependencies HOT 1
- can't use jsx file when build ahead of time HOT 3
- Update hoek dep HOT 2
- React.createFactory() is deprecated and will be removed in a future major release.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hapi-react-views.