Slide 1

Slide 1 text

Albert PazderiÄ Vladimir Dementyev The future of begins in the Rails browser

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

https://guides.rubyonrails.org/getting_started.html#prerequisites https://guides.rubyonrails.org/install_ruby_on_rails.html

Slide 4

Slide 4 text

https://rails-tutorial.evilmartians.io

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

IDE, Node.js runtimS Terminal, file syste1 npm instal All in the browserÈ no server attacheF Zero-setu development experience

Slide 8

Slide 8 text

https://bolt.new by StackBlitz but with AI writing code Zero-setu$ vibe-coding experience

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

Can we bring the same zero-setup UÄ to the Rails world? Where it could be the most beneficial (spoiler: yes, we can0 (spoiler: learning)

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

https://rails-tutorial.evilmartians.io THE TALK The Key Ingredient) The Challenges

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

C Ruby Web browsers Standalone runtimes x86 ARM WASM .wasm Compiler (e.g. LLVM) Rust

Slide 16

Slide 16 text

C Ruby Web browsers Standalone runtimes x86 ARM WASM .wasm Compiler (e.g. LLVM) Rust C Ruby Web browsers Standalone runtimes x86 ARM WASM .wasm Compiler (e.g. LLVM) Rust

Slide 17

Slide 17 text

C Ruby Web browsers Standalone runtimes x86 ARM WASM .wasm Compiler (e.g. LLVM) Rust

Slide 18

Slide 18 text

C Ruby Web browsers Standalone runtimes x86 ARM WASM .wasm Compiler (e.g. LLVM) Rust

Slide 19

Slide 19 text

C Ruby Web browsers Standalone runtimes x86 ARM WASM .wasm Compiler (e.g. LLVM) Rust

Slide 20

Slide 20 text

WASÆ module Browser Networking# File system?

Slide 21

Slide 21 text

WASM-WASÄ module

Slide 22

Slide 22 text

WASM-WASI module import "sys_call" ... call $sys_call WASI-compatible runtime Implements "sys_call"

Slide 23

Slide 23 text

https://github.com/ruby/ruby.wasm

Slide 24

Slide 24 text

Bringing Ruby to the Browser: ruby.wasm ruby.wasm WASM WASI Packaging toolchain

Slide 25

Slide 25 text

Bringing Ruby to the Browser: ruby.wasm ruby.wasm WASM WASI Packaging toolchain a Pre-compiled Ruby Runtimes

Slide 26

Slide 26 text

Bringing Ruby to the Browser: ruby.wasm ruby.wasm WASM WASI Packaging toolchain g Pre-compiled Ruby Runtimes g Gem packaging toolchain

Slide 27

Slide 27 text

Bringing Ruby to the Browser: ruby.wasm G Pre-compiled Ruby Runtimes G Gem packaging toolchain G Compatibility patches ruby.wasm WASM WASI Packaging toolchain + patches

Slide 28

Slide 28 text

The Final Ingredient: wasmify-rails wasmify-rails ruby.wasm Rails shims WASM WASI Packaging toolchain Rails config

Slide 29

Slide 29 text

The Final Ingredient: wasmify-rails wasmify-rails ruby.wasm Rails shims WASM WASI Packaging toolchain Rails config

Slide 30

Slide 30 text

The Final Ingredient: wasmify-rails wasmify-rails ruby.wasm Rails shims WASM WASI Packaging toolchain Rails config

Slide 31

Slide 31 text

https://writebook-on-wasm.fly.dev

Slide 32

Slide 32 text

wasmify-rails ruby.wasm Rails shims WASM WASI Packaging toolchain Rails config ? ?

Slide 33

Slide 33 text

https://rails-tutorial.evilmartians.io

Slide 34

Slide 34 text

https://rails-tutorial.evilmartians.io

Slide 35

Slide 35 text

wasmify-rails ruby.wasm Rails shims WASM WASI Packaging toolchain Rails config Database Web server

Slide 36

Slide 36 text

Database È SQLite.was È PGlite PGLite/SQLite.wasm Compatibility layer OFPS Indexed DB Memory

Slide 37

Slide 37 text

Database  SQLite.was"  PGlite PGLite/SQLite.wasm Compatibility layer OFPS Indexed DB Memory Same API in the browser and Node.js

Slide 38

Slide 38 text

Node.js?

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

Web Applicaiton (main JS thread) WebContainer runtimH (isolated Web Worker) WebContainer API Client Terminal UI Node.js Runtim™ (V8 based) Virtual File Systek (in memory) Service WorkeŒ (browser-level network proxy) (HTTP Traffic) (HTTP Traffic) Preview Iframe

Slide 41

Slide 41 text

Web Applicaiton (main JS thread) WebContainer runtimH (isolated Web Worker) WebContainer API Client Terminal UI Node.js Runtim™ (V8 based) Virtual File Systek (in memory) Service WorkeŒ (browser-level network proxy) (HTTP Traffic) (HTTP Traffic) Preview Iframe

Slide 42

Slide 42 text

Web Applicaiton (main JS thread) WebContainer runtimH (isolated Web Worker) WebContainer API Client Terminal UI Node.js Runtim™ (V8 based) Virtual File Systek (in memory) Service WorkeŒ (browser-level network proxy) (HTTP Traffic) (HTTP Traffic) Preview Iframe

Slide 43

Slide 43 text

Web Applicaiton (main JS thread) WebContainer runtimH (isolated Web Worker) WebContainer API Client Terminal UI Node.js Runtim™ (V8 based) Virtual File Systek (in memory) Service WorkeŒ (browser-level network proxy) (HTTP Traffic) (HTTP Traffic) Preview Iframe

Slide 44

Slide 44 text

Web Applicaiton (main JS thread) WebContainer runtimH (isolated Web Worker) WebContainer API Client Terminal UI Node.js Runtim™ (V8 based) Virtual File Systek (in memory) Service WorkeŒ (browser-level network proxy) (HTTP Traffic) (HTTP Traffic) Preview Iframe

Slide 45

Slide 45 text

Web Applicaiton (main JS thread) WebContainer runtimH (isolated Web Worker) WebContainer API Client Terminal UI Node.js Runtim™ (V8 based) Virtual File Systek (in memory) Service WorkeŒ (browser-level network proxy) (HTTP Traffic) (HTTP Traffic) Preview Iframe

Slide 46

Slide 46 text

WebContainer wasmify-rails ruby.wasm WASM WASI Packaging toolchain Rails config Rails shims Web server Database

Slide 47

Slide 47 text

WebContainer wasmify-rails ruby.wasm WASM WASI Packaging toolchain Rails config Rails shims Web server Database

Slide 48

Slide 48 text

THE CHallenge Express.js rails.wasm

Slide 49

Slide 49 text

 É È Ç Æ Å Ä Ã À 1Á 1 1É 1È 1Ç 1Æ 1Å 1Ä 18 module module class def self require new en" en! en" end RackuU Handlee WASIServee . (app, options1 port options[ 2 ::Rack:: ::IncomingHandler. (app1 a ::Wasmify::ExternalCommands.server(port1 register , WASIServee run ** = = "rack/wasi/incoming_handler‡ :Port WASI :wasi # Init a global handler for the ap€ $incoming_handler # Signal to the JS host that the server is reads

Slide 50

Slide 50 text

Rack::WASI::IncomingHandler ) ' & % $ # " !  10 class def en2 end Rack:: ::IncomingHandlei (req, resE request Rack::MockRequest.env_for(uri.to_s, headersD response .call(requestD WASI handle # parse headero # ..f # ..f @app # handle responsp = =

Slide 51

Slide 51 text

express.js 1. Receives HTTP request 2. Registers the request to the global scope 7 . Unpacks the data from the ruby response 8. Build & send the final response to the client 3. Invokes vm.evalAsync() & await rails.wasm 4. Reads request data from "JS.global" 6. Packages response into JS proxy object 5. Converts request into a standard Rack env hash & @app.call(env) Promise resolve trigger wm.evalAsync()

Slide 52

Slide 52 text

express.js 1. Receives HTTP request 2. Registers the request to the global scope 7 . Unpacks the data from the ruby response 8. Build & send the final response to the client 3. Invokes vm.evalAsync() & await rails.wasm 4. Reads request data from "JS.global" 6. Packages response into JS proxy object 5. Converts request into a standard Rack env hash & @app.call(env) Promise resolve trigger wm.evalAsync()

Slide 53

Slide 53 text

express.js 1. Receives HTTP request 2. Registers the request to the global scope 7 . Unpacks the data from the ruby response 8. Build & send the final response to the client 3. Invokes vm.evalAsync() & await rails.wasm 4. Reads request data from "JS.global" 6. Packages response into JS proxy object 5. Converts request into a standard Rack env hash & @app.call(env) Promise resolve trigger wm.evalAsync()

Slide 54

Slide 54 text

express.js 1. Receives HTTP request 2. Registers the request to the global scope 7 . Unpacks the data from the ruby response 8. Build & send the final response to the client 3. Invokes vm.evalAsync() & await rails.wasm 4. Reads request data from "JS.global" 6. Packages response into JS proxy object 5. Converts request into a standard Rack env hash & @app.call(env) Promise resolve trigger wm.evalAsync()

Slide 55

Slide 55 text

express.js 1. Receives HTTP request 2. Registers the request to the global scope 7 . Unpacks the data from the ruby response 8. Build & send the final response to the client 3. Invokes vm.evalAsync() & await rails.wasm 4. Reads request data from "JS.global" 6. Packages response into JS proxy object 5. Converts request into a standard Rack env hash & @app.call(env) Promise resolve trigger wm.evalAsync()

Slide 56

Slide 56 text

express.js 1. Receives HTTP request 2. Registers the request to the global scope 7 . Unpacks the data from the ruby response 8. Build & send the final response to the client 3. Invokes vm.evalAsync() & await rails.wasm 4. Reads request data from "JS.global" 6. Packages response into JS proxy object 5. Converts request into a standard Rack env hash & @app.call(env) Promise resolve trigger wm.evalAsync()

Slide 57

Slide 57 text

express.js 1. Receives HTTP request 2. Registers the request to the global scope 7 . Unpacks the data from the ruby response 8. Build & send the final response to the client 3. Invokes vm.evalAsync() & await rails.wasm 4. Reads request data from "JS.global" 6. Packages response into JS proxy object 5. Converts request into a standard Rack env hash & @app.call(env) Promise resolve trigger wm.evalAsync()

Slide 58

Slide 58 text

express.js 1. Receives HTTP request 2. Registers the request to the global scope 7 . Unpacks the data from the ruby response 8. Build & send the final response to the client 3. Invokes vm.evalAsync() & await rails.wasm 4. Reads request data from "JS.global" 6. Packages response into JS proxy object 5. Converts request into a standard Rack env hash & @app.call(env) Promise resolve trigger wm.evalAsync()

Slide 59

Slide 59 text

express.js 1. Receives HTTP request 2. Registers the request to the global scope 7 . Unpacks the data from the ruby response 8. Build & send the final response to the client 3. Invokes vm.evalAsync() & await rails.wasm 4. Reads request data from "JS.global" 6. Packages response into JS proxy object 5. Converts request into a standard Rack env hash & @app.call(env) Promise resolve trigger wm.evalAsync()

Slide 60

Slide 60 text

THE CHallenge One cannot develop without a console

Slide 61

Slide 61 text

  È Ç Æ Ä Ã Â À 1Á 1 1 1È 1Ç 1Æ 1Ä 1à 1 1À 2Á 2 2 2È 2Ç 25 import from export default class async const await this this async await this null repl E IRBRepl Y () Y prompt .vm. ( Q repG . ({ prompt, eval .eval, writer rubyWriter }Q . ( , () process. ())D 5 V (cmd, _, _, callback) Y result .vm. ( ${cmd} )D ( , result)D 5 } "node:repl" h require "irbn class IRB::Ir‡ def eval_code(codew # ..s enq enp $irb = IRB::Irb.new(nil, IRB::StdioInputMethod.neww ` 'exit' `$irb.eval_code( )` start evalAsync start on exit eval evalAsync callback = : : => =

Slide 62

Slide 62 text

https:/ /github.com/kateinoigakukun/irb.wasm

Slide 63

Slide 63 text

THE CHallenge bin/rails

Slide 64

Slide 64 text

One-shot Interactive rails new rails generate rails routes rails server rails console

Slide 65

Slide 65 text

One-shot Interactive rails new rails generate rails routes rails server rails console Solution: delegate to Rails

Slide 66

Slide 66 text

One-shot Interactive rails new rails generate rails routes rails server rails console Solution: delegate to Rails

Slide 67

Slide 67 text

 É Ç Æ Å Ä Ã Â À 1Á 1 1É 1Ç 1Æ 1Å 1Ä 1Ã 1Â 1À 2Á 2 22 export default class this async function const await this async function return new return this ExternalCommands X (port) X . (vm) X server (vm, {skipRackup })I server. (port, () X . ( ${port} )H . ( )H })H 2 1 () X . (vm) X IRBRepl(vm). ()H 2 1 (vm) X . (vm)H 2 } server command createRackServer listen log log console command start invoke command = = : => console console = true `Express.js server started on port ` `Use Ctrl-C to stop`

Slide 68

Slide 68 text

What about the UI?

Slide 69

Slide 69 text

 É È Ç Å Ä Ã Â À 1Á 1 1É 1È 14 import from const await const await const await await await { WebContainer } 4 webcontainerInstance WebContainer. ()5 files { {file {contents }}}5 webcontainerInstance. (files)5 process webcontainerInstance. ( , [ ])5 process.exit5 webcontainerInstance. ( , [ , ])5 webcontainerInstance. ( , (port, url) (iframeEl.src url)); '@webcontainer/api' "..." 'npm' 'install' 'npm' 'run' 'dev' 'server-ready' // Instantiatinf // File syste” // `npm install‘ // `npm run dev‘ // Previe = = : : : = => = boot mount spawn spawn on 'package.json'

Slide 70

Slide 70 text

https://tutorialkit.dev/

Slide 71

Slide 71 text

TutorialKit UI WebContainer runtime rails.wasm Ruby VM: WASM + WASI Gems Native extensions System tools PGLite Rack-compatibl— web server Lesson files Previep Iframe T erminal UI App code

Slide 72

Slide 72 text

TutorialKit UI WebContainer runtime rails.wasm Ruby VM: WASM + WASI Gems Native extensions System tools PGLite Rack-compatibl— web server Lesson files Previep Iframe T erminal UI App code

Slide 73

Slide 73 text

TutorialKit UI WebContainer runtime rails.wasm Ruby VM: WASM + WASI Gems Native extensions System tools PGLite Rack-compatibl— web server Lesson files Previep Iframe T erminal UI App code

Slide 74

Slide 74 text

TutorialKit UI WebContainer runtime rails.wasm Ruby VM: WASM + WASI Gems Native extensions System tools PGLite Rack-compatibl— web server Lesson files Previep Iframe T erminal UI App code

Slide 75

Slide 75 text

TutorialKit UI WebContainer runtime rails.wasm Ruby VM: WASM + WASI Gems Native extensions System tools PGLite Rack-compatibl— web server Lesson files Previep Iframe T erminal UI App code

Slide 76

Slide 76 text

TutorialKit UI WebContainer runtime rails.wasm Ruby VM: WASM + WASI Gems Native extensions System tools PGLite Rack-compatibl— web server Lesson files Previep Iframe T erminal UI App code

Slide 77

Slide 77 text

https://rails-tutorial.evilmartians.io

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

https://bolt.new

Slide 80

Slide 80 text

github.com/palkan/rails-tutorial-template

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

No content

Slide 84

Slide 84 text

THANK YOU Albert Pazderi Vladimir Dementyev Evil MartianA evilmartians.com