1 of 62

A Front-End Journey

back to Rails

Or “How I learned to stop worrying & love the Hotwire”.

Kevin Vanzandberghe @kevinvzb

2 of 62

Hello!

  • Discovered Ruby & Rails in 2010.
  • First job as Rails developer in 2012.
  • Worked in agency / freelance / product.

3 of 62

Work: Nodalview

4 of 62

Play: Tabletop RPGs

5 of 62

Rails front-end

across the years

6 of 62

A few attempts

  • RJS
  • Asset pipeline
  • BackboneJS
  • jQuery
  • Rails UJS
  • CoffeeScript
  • SASS
  • Bundled JS gems
  • ERB alts (haml, slim)
  • Bower
  • Early frameworks (Ember, Angular)
  • Turbolinks
  • Early React
  • Webpack(er)
  • API mode + full front-end frameworks

7 of 62

React…

  • Small islands of isolated component trees.

8 of 62

React…

  • Small islands of isolated component trees.
  • Entire pages in a single component tree.

9 of 62

React…

  • Small islands of isolated component trees.
  • Entire pages in a single component tree.
  • Data fetching with GraphQL.

10 of 62

React…

  • Small islands of isolated component trees.
  • Entire pages in a single component tree.
  • Data fetching with GraphQL.
  • Client-side routing.

11 of 62

React…

  • Small islands of isolated component trees.
  • Entire pages in a single component tree.
  • Data fetching with GraphQL.
  • Client-side routing.
  • Etc.

12 of 62

Excellent UI fidelity.

Huge overhead.

13 of 62

Next.js

React meta-framework

  • Very opinionated.
  • Sane defaults.
  • Lots of features out of the box.

14 of 62

Time for a choice

15 of 62

No more hybrid stack.

One or the other.

16 of 62

First attempt: Next.js

“Famous last words”

17 of 62

“I’m going to need Rails at some point for that…”

18 of 62

Missing a lot

Feature

Rails

Next

ORM

ActiveRecord

No

Background Jobs

ActiveJob

No

File Uploads

ActiveStorage

No

Deploy anywhere

Yes

Kinda?

Is in Ruby

Yes

No

19 of 62

Increasing complexity

20 of 62

21 of 62

Second attempt: Rails

Kind of obvious in hindsight

22 of 62

One goal

All of Rails, without sacrificing UI/UX/DX.

23 of 62

I still want all that:

  • Components
  • Interactivity
  • UI Docs
  • Suspense
  • Inline forms
  • Form loading states
  • Confirm dialogs
  • Live updates

24 of 62

Can I?

Let’s find out!

25 of 62

Components

26 of 62

Components

Basics

27 of 62

Components

Views & Controllers

28 of 62

Components

Slots

29 of 62

Components

Interactivity

  • Hook a Stimulus Controller
  • Define targets
  • Define actions

30 of 62

Components

Stimulus

31 of 62

Components

Bonus: Hooks

32 of 62

Demo

33 of 62

Suspense

34 of 62

Suspense

35 of 62

Demo

36 of 62

Inline Forms

37 of 62

Inline Forms

Index page

38 of 62

Inline Forms

Form page

  • Caveat: extra methods might be due to a bug in Turbo 8 beta.

39 of 62

Inline Forms

Controller

  • No magic here!

40 of 62

Demo

41 of 62

Loading States

42 of 62

Loading states

  • Auto disabled on buttons & submits
  • turbo_submits_with for dynamic text

43 of 62

Demo

44 of 62

Live Updates

45 of 62

Live updates

  • Yes, that’s it.

46 of 62

Demo

47 of 62

Mission accomplished?

I’d say so.

48 of 62

But wait, there’s more…

49 of 62

Well, there’s less.

Fewer things to do for the same result.

50 of 62

No more

Internal APIs your front-end is the sole consumer of.

51 of 62

No more

Hard to debug local states.

52 of 62

No more

Duplicated logic across 2 half-stacks.

53 of 62

No more

Interminable asset compilations.

54 of 62

No more

Building expertise in two different frameworks.

55 of 62

Lessons

56 of 62

Tradeoffs

57 of 62

Tradeoffs

Minus

  • Limited access to cutting-edge front-end libraries
  • Not 100% native-feeling

58 of 62

Tradeoffs

Plus

  • Sticking with (one) framework’s defaults
  • Much faster iterations

59 of 62

I’m finding joy again

60 of 62

QA

61 of 62

hotwire-resources

All the links I’ve compiled while learning this.

github.com/kvzb/hotwire-resources

62 of 62

Thanks!