76
React on Rails Dierent ways of integrating. Pros and Cons

Different ways of integrating React into Rails - Mikhail Bortnyk

Embed Size (px)

Citation preview

Page 1: Different ways of integrating React into Rails - Mikhail Bortnyk

React on RailsDifferent ways of integrating. Pros and Cons

Page 2: Different ways of integrating React into Rails - Mikhail Bortnyk
Page 3: Different ways of integrating React into Rails - Mikhail Bortnyk

About me• name’s Mikhail Bortnyk

Page 4: Different ways of integrating React into Rails - Mikhail Bortnyk

About me• name’s Mikhail Bortnyk

• team leader in Amoniac OU

Page 5: Different ways of integrating React into Rails - Mikhail Bortnyk

About me• name’s Mikhail Bortnyk

• team leader in Amoniac OU

• co-founder of kottans.org

Page 6: Different ways of integrating React into Rails - Mikhail Bortnyk

About me• name’s Mikhail Bortnyk

• team leader in Amoniac OU

• co-founder of kottans.org

• Ruby language researcher

Page 7: Different ways of integrating React into Rails - Mikhail Bortnyk

About me• name’s Mikhail Bortnyk

• team leader in Amoniac OU

• co-founder of kottans.org

• Ruby language researcher

• twitter: @mikhailbortnyk

Page 8: Different ways of integrating React into Rails - Mikhail Bortnyk

About me• name’s Mikhail Bortnyk

• team leader in Amoniac OU

• co-founder of kottans.org

• Ruby language researcher

• twitter: @mikhailbortnyk

• github: @vessi

Page 9: Different ways of integrating React into Rails - Mikhail Bortnyk

Short history of SPA in Rails

Page 10: Different ways of integrating React into Rails - Mikhail Bortnyk

Short history of SPA in Rails• Started from UJS

Page 11: Different ways of integrating React into Rails - Mikhail Bortnyk

Short history of SPA in Rails• Started from UJS

• continued with Backbone.js (Marionette.js afterwards)

Page 12: Different ways of integrating React into Rails - Mikhail Bortnyk

Short history of SPA in Rails• Started from UJS

• continued with Backbone.js (Marionette.js afterwards)

• progressed to angular.js

Page 13: Different ways of integrating React into Rails - Mikhail Bortnyk

Short history of SPA in Rails• Started from UJS

• continued with Backbone.js (Marionette.js afterwards)

• progressed to angular.js

• appeared react.js support (3rd party gems)

Page 14: Different ways of integrating React into Rails - Mikhail Bortnyk

Short history of SPA in Rails• Started from UJS

• continued with Backbone.js (Marionette.js afterwards)

• progressed to angular.js

• appeared react.js support (3rd party gems)

• webpack becomes part of Rails via webpacker gem

Page 15: Different ways of integrating React into Rails - Mikhail Bortnyk

DHH dislikes SPAs

Page 16: Different ways of integrating React into Rails - Mikhail Bortnyk

DHH dislikes SPAshttps://www.reddit.com/r/ruby/comments/341dyk/

why_does_dhh_dislike_spas_so_much/

Page 17: Different ways of integrating React into Rails - Mikhail Bortnyk

We are not DHHand sometimes we need something more than Rails

Page 18: Different ways of integrating React into Rails - Mikhail Bortnyk

How do we do frontend in Railsfrom some hands-on experience

Page 19: Different ways of integrating React into Rails - Mikhail Bortnyk

Case 1. Boring (Standalone application)

Page 20: Different ways of integrating React into Rails - Mikhail Bortnyk

Standalone frontend• Pros and Cons

Page 21: Different ways of integrating React into Rails - Mikhail Bortnyk

Standalone frontend• Pros:

• full control on frontend development process

Page 22: Different ways of integrating React into Rails - Mikhail Bortnyk

Standalone frontend• Pros:

• full control on frontend development process

• use what you actually want

Page 23: Different ways of integrating React into Rails - Mikhail Bortnyk

Standalone frontend• Pros:

• full control on frontend development process

• use what you actually want

• no need to fight with assets pipeline

Page 24: Different ways of integrating React into Rails - Mikhail Bortnyk

Standalone frontend• Pros:

• full control on frontend development process

• use what you actually want

• no need to fight with assets pipeline

• SPA loads independently

Page 25: Different ways of integrating React into Rails - Mikhail Bortnyk

Standalone frontend• Cons:

• +1 AJAX request to load data

Page 26: Different ways of integrating React into Rails - Mikhail Bortnyk

Standalone frontend• Cons:

• +1 AJAX request to load data

• you need to coordinate build and deployment

Page 27: Different ways of integrating React into Rails - Mikhail Bortnyk

Standalone frontend• Cons:

• +1 AJAX request to load data

• you need to coordinate build and deployment

• dependencies hell management

Page 28: Different ways of integrating React into Rails - Mikhail Bortnyk

Standalone frontend• Cons:

• +1 AJAX request to load data

• you need to coordinate build and deployment

• dependencies hell management

• coordinate, coordinate, and coordinate again

Page 29: Different ways of integrating React into Rails - Mikhail Bortnyk

Standalone frontend• Cons:

• +1 AJAX request to load data

• you need to coordinate build and deployment

• dependencies hell management

• coordinate, coordinate, and coordinate again

• and don’t forget about API versioning!

Page 30: Different ways of integrating React into Rails - Mikhail Bortnyk

Case 1.5. Creepy as hell (In-Rails JS)

Page 31: Different ways of integrating React into Rails - Mikhail Bortnyk

In-Rails JS• Pros and Cons

Page 32: Different ways of integrating React into Rails - Mikhail Bortnyk

In-Rails JS• Pros:

• Almost nothing

Page 33: Different ways of integrating React into Rails - Mikhail Bortnyk

In-Rails JS• Pros:

• Almost nothing

• Deployed at the same time

Page 34: Different ways of integrating React into Rails - Mikhail Bortnyk

In-Rails JS• Cons:

• Hardly maintainable

Page 35: Different ways of integrating React into Rails - Mikhail Bortnyk

In-Rails JS• Cons:

• Hardly maintainable

• supports only in-browser JSX

Page 36: Different ways of integrating React into Rails - Mikhail Bortnyk

In-Rails JS• Cons:

• Hardly maintainable

• supports only in-browser JSX

• dependencies hell

Page 37: Different ways of integrating React into Rails - Mikhail Bortnyk

In-Rails JS• Cons:

• Hardly maintainable

• supports only in-browser JSX

• dependencies hell

• suits only for very simple SPAs

Page 38: Different ways of integrating React into Rails - Mikhail Bortnyk

Case 2. Outdated (react-rails gem)

Page 39: Different ways of integrating React into Rails - Mikhail Bortnyk

react-rails gem• Pros and Cons

Page 40: Different ways of integrating React into Rails - Mikhail Bortnyk

react-rails gem• Pros:

• fixed react.js version

Page 41: Different ways of integrating React into Rails - Mikhail Bortnyk

react-rails gem• Pros:

• fixed react.js version

• server-side rendering

Page 42: Different ways of integrating React into Rails - Mikhail Bortnyk

react-rails gem• Pros:

• fixed react.js version

• server-side rendering

• components generators

Page 43: Different ways of integrating React into Rails - Mikhail Bortnyk

react-rails gem• Pros:

• fixed react.js version

• server-side rendering

• components generators

• UJS integration

Page 44: Different ways of integrating React into Rails - Mikhail Bortnyk

react-rails gem• Pros:

• fixed react.js version

• server-side rendering

• components generators

• UJS integration

• turbolinks integration

Page 45: Different ways of integrating React into Rails - Mikhail Bortnyk

react-rails gem• Cons:

• fixed react.js version

Page 46: Different ways of integrating React into Rails - Mikhail Bortnyk

react-rails gem• Cons:

• fixed react.js version

• deep integration with assets pipeline

Page 47: Different ways of integrating React into Rails - Mikhail Bortnyk

react-rails gem• Cons:

• fixed react.js version

• deep integration with assets pipeline

• no source maps

Page 48: Different ways of integrating React into Rails - Mikhail Bortnyk

react-rails gem• Cons:

• fixed react.js version

• deep integration with assets pipeline

• no source maps

• forget about “all-in-component” behavior

Page 49: Different ways of integrating React into Rails - Mikhail Bortnyk

Case 3. Current (react_on_rails gem)

Page 50: Different ways of integrating React into Rails - Mikhail Bortnyk

react_on_rails gem• Pros and Cons

Page 51: Different ways of integrating React into Rails - Mikhail Bortnyk

react_on_rails gem• Pros:

• separate SPA folder

Page 52: Different ways of integrating React into Rails - Mikhail Bortnyk

react_on_rails gem• Pros:

• separate SPA folder

• a lot of helpers for react and redux

Page 53: Different ways of integrating React into Rails - Mikhail Bortnyk

react_on_rails gem• Pros:

• separate SPA folder

• a lot of helpers for react and redux

• templates for SPAs

Page 54: Different ways of integrating React into Rails - Mikhail Bortnyk

react_on_rails gem• Pros:

• separate SPA folder

• a lot of helpers for react and redux

• templates for SPAs

• webpack as an app builder

Page 55: Different ways of integrating React into Rails - Mikhail Bortnyk

react_on_rails gem• Pros:

• separate SPA folder

• a lot of helpers for react and redux

• templates for SPAs

• webpack as an app builder

• yarn as a package manager

Page 56: Different ways of integrating React into Rails - Mikhail Bortnyk

react_on_rails gem• Cons:

• separate SPA folder

Page 57: Different ways of integrating React into Rails - Mikhail Bortnyk

react_on_rails gem• Cons:

• separate SPA folder

• dirty dances to get HMR working

Page 58: Different ways of integrating React into Rails - Mikhail Bortnyk

react_on_rails gem• Cons:

• separate SPA folder

• dirty dances to get HMR working

• complicated documentation

Page 59: Different ways of integrating React into Rails - Mikhail Bortnyk

react_on_rails gem• Cons:

• separate SPA folder

• dirty dances to get HMR working

• complicated documentation

• need to wait for upgrade dependencies

Page 60: Different ways of integrating React into Rails - Mikhail Bortnyk

react_on_rails gem• Cons:

• separate SPA folder

• dirty dances to get HMR working

• complicated documentation

• need to wait for upgrade dependencies

• a lot of side-selling in documentation

Page 61: Different ways of integrating React into Rails - Mikhail Bortnyk

Case 4. Probably future (webpacker gem)

Page 62: Different ways of integrating React into Rails - Mikhail Bortnyk

webpacker gem• Pros and Cons

Page 63: Different ways of integrating React into Rails - Mikhail Bortnyk

webpacker gem• Pros:

• easily managed components (via packs)

Page 64: Different ways of integrating React into Rails - Mikhail Bortnyk

webpacker gem• Pros:

• easily managed components (via packs)

• works with Turbolinks

Page 65: Different ways of integrating React into Rails - Mikhail Bortnyk

webpacker gem• Pros:

• easily managed components (via packs)

• works with Turbolinks

• supports hot loading out of box

Page 66: Different ways of integrating React into Rails - Mikhail Bortnyk

webpacker gem• Pros:

• easily managed components (via packs)

• works with Turbolinks

• supports hot loading out of box

• integrated into Rails starting from 5.1

Page 67: Different ways of integrating React into Rails - Mikhail Bortnyk

webpacker gem• Pros:

• easily managed components (via packs)

• works with Turbolinks

• supports hot loading out of box

• integrated into Rails starting from 5.1

• package.json lives in the same folder

Page 68: Different ways of integrating React into Rails - Mikhail Bortnyk

webpacker gem• Pros:

• easily managed components (via packs)

• works with Turbolinks

• supports hot loading out of box

• integrated into Rails starting from 5.1

• package.json lives in the same folder

• config lives altogether with your app config

Page 69: Different ways of integrating React into Rails - Mikhail Bortnyk

webpacker gem• Cons:

• No server-side rendering

Page 70: Different ways of integrating React into Rails - Mikhail Bortnyk

webpacker gem• Cons:

• No server-side rendering

• SPA is highly integrated into Rails App source code

Page 71: Different ways of integrating React into Rails - Mikhail Bortnyk

webpacker gem• Cons:

• No server-side rendering

• SPA is highly integrated into Rails App source code

• Still needs some setup ceremonies

Page 72: Different ways of integrating React into Rails - Mikhail Bortnyk
Page 73: Different ways of integrating React into Rails - Mikhail Bortnyk

Showtime

Page 74: Different ways of integrating React into Rails - Mikhail Bortnyk

Conclusions

Page 75: Different ways of integrating React into Rails - Mikhail Bortnyk

Questions?

Page 76: Different ways of integrating React into Rails - Mikhail Bortnyk

Thanks!