SlideShare a Scribd company logo
Isomorphic React
In Real Life
Jonas Ohlsson
@pocketjoso
Who am I?
• Frond end developer at State
• Performance, tooling and open source geek
Isomorphic new site: http://alpha.state.com
Penthouse, Critical Path CSS Generator:
https://github.com/pocketjoso/penthouse
This talk
• Background: Isomorphism, React
• State’s isomorphic React render flow
- Data
- Bootstrap
- Stores
Isomorphic JavaScript
• Shared JS running both client and server
• Performance, graceful degradation, Accessibility, SEO
Flash of Client Side Rendering
Isomorphic React
• Easy - React.renderToString()
• What about data fetching, re-using render state, stores
React render flow (client)
URL Render
Fetch
data
Routing
table
React render flow (client)
Render
Fetch
data
Routing
table
URL
props = {
page: ExplorePage
};
React render flow (client)
Render
Fetch
data
Routing
table
URL
props = {
page: ExplorePage
};
React.render(
<App {…props} />,
containerElement
);
React render flow (client)
React Lifecycle method componentDidMount: http://facebook.github.io/react/docs/component-specs.html#mounting-componentdidmount
Render
Fetch
data
Routing
table
URL
props = {
page: ExplorePage
};
React.render(
<App {…props} />,
containerElement
);
componentDidMount
React render flow (client)
Render
Fetch
data
Routing
table
URL
props = {
page: ExplorePage
};
React.render(
<App {…props} />,
containerElement
);
componentDidMount
…
$.get().then(result){
this.setState({data:
result});
});
React render flow (client)
props = {
page: ExplorePage
};
can’t use on the server
Render
Fetch
data
Routing
table
URL
React.render(
<App {…props} />,
containerElement
);
componentDidMount
…
$.get().then(result){
this.setState({data:
result});
});
Isomorphic Render Flow
Isomorphic React render flow
Make requests
page asked for
React.
render/
renderToString(
<App {…props} />
);
Pre fetch
data
Render
Routing
table
URL
props = {
page: ExplorePage
};
Isomorphic React render flow
Make requests
page asked for
React.
render/
renderToString(
<App {…props} />
);
Pre fetch
data
Render
Routing
table
URL
props = {
page: ExplorePage
};
Pre data fetching
React Statics component property: http://facebook.github.io/react/docs/component-specs.html#statics
Isomorphic React render flow
data =
ExplorePage.
requestForProps();
Routing
table
URL Pre fetch
data
Render
React.
render/
renderToString(
<App {…props} />
);
props = {
page: ExplorePage
};
Isomorphic React render flow
data =
ExplorePage.
requestForProps();
props.data = data;
Routing
table
URL Pre fetch
data
Render
React.
render/
renderToString(
<App {…props} />
);
props = {
page: ExplorePage
};
Bootstrapping render context
React.render(
<App {…props}/>
);
Server Client
React.renderToString(
<App {…props}/>
);
Bootstrapping
Server Client
Bootstrapping render context
Flux
• Data changing over time (during a session)
• Cached data
Should I use Flux? https://medium.com/@dan_abramov/the-case-for-flux-379b7d1982c6
Flux
• Data changing over time (during a session)
• Cached data
Should I use Flux? https://medium.com/@dan_abramov/the-case-for-flux-379b7d1982c6
Isomorphic Flux Stores
Snapshot / restore
Add snapshots to render context JSON Restore on client
Store reset
• Stores are singletons
• Prevent data leaking
Stores listening for request data
Request
response
data
Distribute StoresNormalise
Stores listening for request data
Request
response
data
Distribute StoresNormalise
statement : {
creator : {
id : 12312,
name: Jonas
…
},
id: 199,
text: ‘This is …’
}
Stores listening for request data
Normalize data: https://github.com/gaearon/normalizr
Request
response
data
Distribute Stores
statement : {
creator : {
id : 12312,
name: Jonas
…
},
id: 199,
text: ‘This is …’
}
entities: {
users: {
12312: {
name: Jonas
}
},
statements: {
199: {
text: ‘This is …’
creator: 12312
}
}
}
Normalise
Stores listening for request data
Request
response
data
Distribute StoresNormalise
trigger(users)
trigger(statements)
statement : {
creator : {
id : 12312,
name: Jonas
…
},
id: 199,
text: ‘This is …’
}
entities: {
users: {
12312: {
name: Jonas
}
},
statements: {
199: {
text: ‘This is …’
creator: 12312
}
}
}
Stores listening for request data
UserStore = {
listenTo(
userProvider,
function(users){
// merge new users
// to store’s data
}
}
Request
response
data
Distribute Stores
statement : {
creator : {
id : 12312,
name: Jonas
…
},
id: 199,
text: ‘This is …’
}
Normalise
trigger(users)
trigger(statements)
entities: {
users: {
12312: {
name: Jonas
}
},
statements: {
199: {
text: ‘This is …’
creator: 12312
}
}
}
Full Render sequence: Server
• (Start stores when booting server)
• Execute requests via requestForProps for Page
• Distribute data to Stores (if not Automatic)
• React.RenderToString()
• Snapshot Stores, create render context JSON
• Send HTML to client
• Reset Stores
Full Render sequence: Client
• Parse render context JSON
• Start stores, and restore via snapshots
• React.render, with props from render context
Summary
• Fetch data before rendering React
• Statics to co-locate data requests with component logic
• Bootstrap server render context
• Snapshot, restore and reset Stores
• Optional: Auto distribute request data to Stores
Questions?
@pocketjoso
Blog post based on this talk
http://jonassebastianohlsson.com/blog/2015/03/24/isomorphic-react-in-real-life/

More Related Content

PPT
Introduction to JAX-RS
PDF
Side by Side with Elasticsearch and Solr
PPTX
CORS - Enable Alfresco for CORS
PDF
Ws rest
PDF
Data Exploration with Elasticsearch
PDF
Elasticsearch in 15 minutes
PPTX
apidays LIVE LONDON - Data Retrieval via APIs - Showdown of GraphQL vs ODATA ...
PPTX
MongoDB Aggregation Performance
Introduction to JAX-RS
Side by Side with Elasticsearch and Solr
CORS - Enable Alfresco for CORS
Ws rest
Data Exploration with Elasticsearch
Elasticsearch in 15 minutes
apidays LIVE LONDON - Data Retrieval via APIs - Showdown of GraphQL vs ODATA ...
MongoDB Aggregation Performance

What's hot (19)

PDF
MongoDB Launchpad 2016: What’s New in the 3.4 Server
PDF
Cross site calls with javascript - the right way with CORS
PPTX
Web Security - Cookies, Domains and CORS
ODP
Cool bonsai cool - an introduction to ElasticSearch
PDF
Distributed percolator in elasticsearch
PDF
Doing REST Right
PDF
elasticsearch - advanced features in practice
ODP
Terms of endearment - the ElasticSearch Query DSL explained
PDF
RESTful Web Services
PDF
Cross-domain requests with CORS
ODP
RESTful Web Services with JAX-RS
PDF
Con fess 2013-sse-websockets-json-bhakti
PPT
Easy rest service using PHP reflection api
PPTX
Леонід Кузьмін “Сам собі паблішер. Від сайту ігрової студії до універсального...
ODP
Query DSL In Elasticsearch
PDF
REST API Recommendations
ODP
Things I wish web graduates knew
PPT
RESTful services with JAXB and JPA
PDF
CORS and (in)security
MongoDB Launchpad 2016: What’s New in the 3.4 Server
Cross site calls with javascript - the right way with CORS
Web Security - Cookies, Domains and CORS
Cool bonsai cool - an introduction to ElasticSearch
Distributed percolator in elasticsearch
Doing REST Right
elasticsearch - advanced features in practice
Terms of endearment - the ElasticSearch Query DSL explained
RESTful Web Services
Cross-domain requests with CORS
RESTful Web Services with JAX-RS
Con fess 2013-sse-websockets-json-bhakti
Easy rest service using PHP reflection api
Леонід Кузьмін “Сам собі паблішер. Від сайту ігрової студії до універсального...
Query DSL In Elasticsearch
REST API Recommendations
Things I wish web graduates knew
RESTful services with JAXB and JPA
CORS and (in)security
Ad

Similar to Isomorphic react in real life (20)

PPTX
ReactJS Code Impact
PDF
Matheus Marsiglio - Isomorphic React + Redux App
PPTX
Relay: Seamless Syncing for React (VanJS)
PDF
An Intense Overview of the React Ecosystem
PDF
FRONTEND DEVELOPMENT WITH REACT.JS
PDF
TPSE Thailand 2015 - Rethinking Web with React and Flux
PDF
MidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
PDF
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
PPTX
Adding a modern twist to legacy web applications
PPTX
React js
PPTX
ReactJS - Re-rendering pages in the age of the mutable DOM
PDF
Functional Web Development
PDF
React, GraphQL и Relay - вполне себе нормальный компонентный подход (nodkz)
PDF
Tech Talk on ReactJS
PDF
An Overview of the React Ecosystem
PDF
Reacting to the Isomorphic Buzz
PDF
theory-slides-vueh3urh4ur4ur4r44oirj4riu4ri
PPTX
PDF
React JS and why it's awesome
PDF
React & Flux Workshop
ReactJS Code Impact
Matheus Marsiglio - Isomorphic React + Redux App
Relay: Seamless Syncing for React (VanJS)
An Intense Overview of the React Ecosystem
FRONTEND DEVELOPMENT WITH REACT.JS
TPSE Thailand 2015 - Rethinking Web with React and Flux
MidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Adding a modern twist to legacy web applications
React js
ReactJS - Re-rendering pages in the age of the mutable DOM
Functional Web Development
React, GraphQL и Relay - вполне себе нормальный компонентный подход (nodkz)
Tech Talk on ReactJS
An Overview of the React Ecosystem
Reacting to the Isomorphic Buzz
theory-slides-vueh3urh4ur4ur4r44oirj4riu4ri
React JS and why it's awesome
React & Flux Workshop
Ad

More from React London Community (7)

PDF
Meet Microplatforms. Stuart Harris, Red Badger
PDF
React for non techies
PDF
London React August - GraphQL at The Financial Times - Viktor Charypar
PDF
React London April- Fully functional: Central state is a great fit for React ...
PDF
London React April- r3t & a11y : This is for everyone , Shaun Dunne.
PDF
Building the worlds largest grocery shopping site with React
PDF
Tools & tricks for testing React applications
Meet Microplatforms. Stuart Harris, Red Badger
React for non techies
London React August - GraphQL at The Financial Times - Viktor Charypar
React London April- Fully functional: Central state is a great fit for React ...
London React April- r3t & a11y : This is for everyone , Shaun Dunne.
Building the worlds largest grocery shopping site with React
Tools & tricks for testing React applications

Recently uploaded (20)

PPT
Teaching material agriculture food technology
PPTX
Spectroscopy.pptx food analysis technology
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Encapsulation theory and applications.pdf
PPTX
Tartificialntelligence_presentation.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Approach and Philosophy of On baking technology
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Teaching material agriculture food technology
Spectroscopy.pptx food analysis technology
Empathic Computing: Creating Shared Understanding
Group 1 Presentation -Planning and Decision Making .pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Encapsulation theory and applications.pdf
Tartificialntelligence_presentation.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Network Security Unit 5.pdf for BCA BBA.
Per capita expenditure prediction using model stacking based on satellite ima...
Unlocking AI with Model Context Protocol (MCP)
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Advanced methodologies resolving dimensionality complications for autism neur...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Approach and Philosophy of On baking technology
A comparative analysis of optical character recognition models for extracting...
A comparative study of natural language inference in Swahili using monolingua...
Encapsulation_ Review paper, used for researhc scholars
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...

Isomorphic react in real life

  • 1. Isomorphic React In Real Life Jonas Ohlsson @pocketjoso
  • 2. Who am I? • Frond end developer at State • Performance, tooling and open source geek Isomorphic new site: http://alpha.state.com Penthouse, Critical Path CSS Generator: https://github.com/pocketjoso/penthouse
  • 3. This talk • Background: Isomorphism, React • State’s isomorphic React render flow - Data - Bootstrap - Stores
  • 4. Isomorphic JavaScript • Shared JS running both client and server • Performance, graceful degradation, Accessibility, SEO
  • 5. Flash of Client Side Rendering
  • 6. Isomorphic React • Easy - React.renderToString() • What about data fetching, re-using render state, stores
  • 7. React render flow (client) URL Render Fetch data Routing table
  • 8. React render flow (client) Render Fetch data Routing table URL props = { page: ExplorePage };
  • 9. React render flow (client) Render Fetch data Routing table URL props = { page: ExplorePage }; React.render( <App {…props} />, containerElement );
  • 10. React render flow (client) React Lifecycle method componentDidMount: http://facebook.github.io/react/docs/component-specs.html#mounting-componentdidmount Render Fetch data Routing table URL props = { page: ExplorePage }; React.render( <App {…props} />, containerElement ); componentDidMount
  • 11. React render flow (client) Render Fetch data Routing table URL props = { page: ExplorePage }; React.render( <App {…props} />, containerElement ); componentDidMount … $.get().then(result){ this.setState({data: result}); });
  • 12. React render flow (client) props = { page: ExplorePage }; can’t use on the server Render Fetch data Routing table URL React.render( <App {…props} />, containerElement ); componentDidMount … $.get().then(result){ this.setState({data: result}); });
  • 14. Isomorphic React render flow Make requests page asked for React. render/ renderToString( <App {…props} /> ); Pre fetch data Render Routing table URL props = { page: ExplorePage };
  • 15. Isomorphic React render flow Make requests page asked for React. render/ renderToString( <App {…props} /> ); Pre fetch data Render Routing table URL props = { page: ExplorePage };
  • 16. Pre data fetching React Statics component property: http://facebook.github.io/react/docs/component-specs.html#statics
  • 17. Isomorphic React render flow data = ExplorePage. requestForProps(); Routing table URL Pre fetch data Render React. render/ renderToString( <App {…props} /> ); props = { page: ExplorePage };
  • 18. Isomorphic React render flow data = ExplorePage. requestForProps(); props.data = data; Routing table URL Pre fetch data Render React. render/ renderToString( <App {…props} /> ); props = { page: ExplorePage };
  • 19. Bootstrapping render context React.render( <App {…props}/> ); Server Client React.renderToString( <App {…props}/> );
  • 21. Flux • Data changing over time (during a session) • Cached data Should I use Flux? https://medium.com/@dan_abramov/the-case-for-flux-379b7d1982c6
  • 22. Flux • Data changing over time (during a session) • Cached data Should I use Flux? https://medium.com/@dan_abramov/the-case-for-flux-379b7d1982c6
  • 24. Snapshot / restore Add snapshots to render context JSON Restore on client
  • 25. Store reset • Stores are singletons • Prevent data leaking
  • 26. Stores listening for request data Request response data Distribute StoresNormalise
  • 27. Stores listening for request data Request response data Distribute StoresNormalise statement : { creator : { id : 12312, name: Jonas … }, id: 199, text: ‘This is …’ }
  • 28. Stores listening for request data Normalize data: https://github.com/gaearon/normalizr Request response data Distribute Stores statement : { creator : { id : 12312, name: Jonas … }, id: 199, text: ‘This is …’ } entities: { users: { 12312: { name: Jonas } }, statements: { 199: { text: ‘This is …’ creator: 12312 } } } Normalise
  • 29. Stores listening for request data Request response data Distribute StoresNormalise trigger(users) trigger(statements) statement : { creator : { id : 12312, name: Jonas … }, id: 199, text: ‘This is …’ } entities: { users: { 12312: { name: Jonas } }, statements: { 199: { text: ‘This is …’ creator: 12312 } } }
  • 30. Stores listening for request data UserStore = { listenTo( userProvider, function(users){ // merge new users // to store’s data } } Request response data Distribute Stores statement : { creator : { id : 12312, name: Jonas … }, id: 199, text: ‘This is …’ } Normalise trigger(users) trigger(statements) entities: { users: { 12312: { name: Jonas } }, statements: { 199: { text: ‘This is …’ creator: 12312 } } }
  • 31. Full Render sequence: Server • (Start stores when booting server) • Execute requests via requestForProps for Page • Distribute data to Stores (if not Automatic) • React.RenderToString() • Snapshot Stores, create render context JSON • Send HTML to client • Reset Stores
  • 32. Full Render sequence: Client • Parse render context JSON • Start stores, and restore via snapshots • React.render, with props from render context
  • 33. Summary • Fetch data before rendering React • Statics to co-locate data requests with component logic • Bootstrap server render context • Snapshot, restore and reset Stores • Optional: Auto distribute request data to Stores
  • 34. Questions? @pocketjoso Blog post based on this talk http://jonassebastianohlsson.com/blog/2015/03/24/isomorphic-react-in-real-life/

Editor's Notes

  • #2: PRELOAD NSFW (/explore and /u/timbl) Hello Awesome time. Jonas - ISO REACT Thank RedBadger, Facebook, React 0:30
  • #3: Penthouse
  • #6: Developer Evangelist - Web
  • #7: Easy! ASK: Raise of hands: How many of you use React isomorphically? We found it hard - this speech! 0:45 (4:00)
  • #13: (5:30)
  • #15: Router - same Render - same (<html> etc added) Data
  • #16: Data - co locate with component logic routing table - far way from component (6:30)
  • #17: provider - Abstraction of API - works both server and client Sync on server
  • #19: Plonk into Render - Full flow client/server EXCEPT 1:00 (8:30)
  • #20: Boot render client - listeners
  • #21: context -> Full ISO flow EXCEPT FOR
  • #23: Actions - Stores - Views (Pages) We wondered - Stores on the server etc? SOLUTION
  • #25: No raw data
  • #26: Because Singletons; booted at start of app Stores containing user specific data (client - auth)
  • #28: one Store per resource type Nesting - bad for Flux
  • #29: Split by Type Reference by ID
  • #31: This setup: requestForProps -> Stores AUTO
  • #32: Possible - not too complex. Add: Store/Page/Component/Route - write once - isomorphically.
  • #33: Possible - not too complex. Add: Store/Page/Component/Route - write once - isomorphically.
  • #34: Possible - not too complex. Add: Store/Page/Component/Route - write once - isomorphically.