Skip to content

Commit f39b142

Browse files
authored
Upgrade inertia to v3 (#258)
* Upgrade inertia to v3 * CI updates * Update brakeman from 8.0.2 to 8.0.4 (required by scan_ruby step) * Add void to createInertiaApp on ssr entrypoint (required by lint_js step) * Update gem versions Required by scan_ruby ci step due to vulnerabilities * Drop ssr.tsx and pass entrypoint to vite * Address ssr error in use-mobile hook This addresses the error: SSR ERROR window is not defined Source: hooks/use-mobile.ts:5:13
1 parent 1492485 commit f39b142

13 files changed

Lines changed: 187 additions & 359 deletions

File tree

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
source "https://rubygems.org"
44

55
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
6-
gem "rails", "~> 8.1.1"
6+
gem "rails", "~> 8.1.3"
77
# The modern asset pipeline for Rails [https://github.com/rails/propshaft]
88
gem "propshaft"
99
# Use sqlite3 as the database for Active Record
@@ -40,7 +40,7 @@ gem "thruster", require: false
4040
gem "vite_rails", "~> 3.0"
4141

4242
# The Rails adapter for Inertia.js [https://inertia-rails.dev]
43-
gem "inertia_rails", "~> 3.6"
43+
gem "inertia_rails", "~> 3.19"
4444

4545
# An authentication system generator for Rails applications
4646
# we leave gem here to watch for security updates

Gemfile.lock

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,68 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
action_text-trix (2.1.16)
4+
action_text-trix (2.1.17)
55
railties
6-
actioncable (8.1.2)
7-
actionpack (= 8.1.2)
8-
activesupport (= 8.1.2)
6+
actioncable (8.1.3)
7+
actionpack (= 8.1.3)
8+
activesupport (= 8.1.3)
99
nio4r (~> 2.0)
1010
websocket-driver (>= 0.6.1)
1111
zeitwerk (~> 2.6)
12-
actionmailbox (8.1.2)
13-
actionpack (= 8.1.2)
14-
activejob (= 8.1.2)
15-
activerecord (= 8.1.2)
16-
activestorage (= 8.1.2)
17-
activesupport (= 8.1.2)
12+
actionmailbox (8.1.3)
13+
actionpack (= 8.1.3)
14+
activejob (= 8.1.3)
15+
activerecord (= 8.1.3)
16+
activestorage (= 8.1.3)
17+
activesupport (= 8.1.3)
1818
mail (>= 2.8.0)
19-
actionmailer (8.1.2)
20-
actionpack (= 8.1.2)
21-
actionview (= 8.1.2)
22-
activejob (= 8.1.2)
23-
activesupport (= 8.1.2)
19+
actionmailer (8.1.3)
20+
actionpack (= 8.1.3)
21+
actionview (= 8.1.3)
22+
activejob (= 8.1.3)
23+
activesupport (= 8.1.3)
2424
mail (>= 2.8.0)
2525
rails-dom-testing (~> 2.2)
26-
actionpack (8.1.2)
27-
actionview (= 8.1.2)
28-
activesupport (= 8.1.2)
26+
actionpack (8.1.3)
27+
actionview (= 8.1.3)
28+
activesupport (= 8.1.3)
2929
nokogiri (>= 1.8.5)
3030
rack (>= 2.2.4)
3131
rack-session (>= 1.0.1)
3232
rack-test (>= 0.6.3)
3333
rails-dom-testing (~> 2.2)
3434
rails-html-sanitizer (~> 1.6)
3535
useragent (~> 0.16)
36-
actiontext (8.1.2)
36+
actiontext (8.1.3)
3737
action_text-trix (~> 2.1.15)
38-
actionpack (= 8.1.2)
39-
activerecord (= 8.1.2)
40-
activestorage (= 8.1.2)
41-
activesupport (= 8.1.2)
38+
actionpack (= 8.1.3)
39+
activerecord (= 8.1.3)
40+
activestorage (= 8.1.3)
41+
activesupport (= 8.1.3)
4242
globalid (>= 0.6.0)
4343
nokogiri (>= 1.8.5)
44-
actionview (8.1.2)
45-
activesupport (= 8.1.2)
44+
actionview (8.1.3)
45+
activesupport (= 8.1.3)
4646
builder (~> 3.1)
4747
erubi (~> 1.11)
4848
rails-dom-testing (~> 2.2)
4949
rails-html-sanitizer (~> 1.6)
50-
activejob (8.1.2)
51-
activesupport (= 8.1.2)
50+
activejob (8.1.3)
51+
activesupport (= 8.1.3)
5252
globalid (>= 0.3.6)
53-
activemodel (8.1.2)
54-
activesupport (= 8.1.2)
55-
activerecord (8.1.2)
56-
activemodel (= 8.1.2)
57-
activesupport (= 8.1.2)
53+
activemodel (8.1.3)
54+
activesupport (= 8.1.3)
55+
activerecord (8.1.3)
56+
activemodel (= 8.1.3)
57+
activesupport (= 8.1.3)
5858
timeout (>= 0.4.0)
59-
activestorage (8.1.2)
60-
actionpack (= 8.1.2)
61-
activejob (= 8.1.2)
62-
activerecord (= 8.1.2)
63-
activesupport (= 8.1.2)
59+
activestorage (8.1.3)
60+
actionpack (= 8.1.3)
61+
activejob (= 8.1.3)
62+
activerecord (= 8.1.3)
63+
activesupport (= 8.1.3)
6464
marcel (~> 1.0)
65-
activesupport (8.1.2)
65+
activesupport (8.1.3)
6666
base64
6767
bigdecimal
6868
concurrent-ruby (~> 1.0, >= 1.3.1)
@@ -80,13 +80,13 @@ GEM
8080
ast (2.4.3)
8181
authentication-zero (4.0.3)
8282
base64 (0.3.0)
83-
bcrypt (3.1.21)
83+
bcrypt (3.1.22)
8484
bcrypt_pbkdf (1.1.2)
8585
bigdecimal (4.0.1)
8686
bindex (0.8.1)
8787
bootsnap (1.23.0)
8888
msgpack (~> 1.2)
89-
brakeman (8.0.2)
89+
brakeman (8.0.4)
9090
racc
9191
builder (3.3.0)
9292
bundler-audit (0.9.3)
@@ -135,7 +135,7 @@ GEM
135135
activesupport (>= 6.1)
136136
i18n (1.14.8)
137137
concurrent-ruby (~> 1.0)
138-
inertia_rails (3.17.0)
138+
inertia_rails (3.19.0)
139139
railties (>= 6)
140140
io-console (0.8.2)
141141
irb (1.17.0)
@@ -149,7 +149,7 @@ GEM
149149
js-routes (2.3.6)
150150
railties (>= 5)
151151
sorbet-runtime
152-
json (2.18.1)
152+
json (2.19.2)
153153
kamal (2.10.1)
154154
activesupport (>= 7.0)
155155
base64 (~> 0.2)
@@ -170,7 +170,7 @@ GEM
170170
launchy (>= 2.2, < 4)
171171
lint_roller (1.1.0)
172172
logger (1.7.0)
173-
loofah (2.25.0)
173+
loofah (2.25.1)
174174
crass (~> 1.0.2)
175175
nokogiri (>= 1.12.0)
176176
mail (2.9.0)
@@ -201,19 +201,19 @@ GEM
201201
net-protocol
202202
net-ssh (7.3.0)
203203
nio4r (2.7.5)
204-
nokogiri (1.19.0-aarch64-linux-gnu)
204+
nokogiri (1.19.1-aarch64-linux-gnu)
205205
racc (~> 1.4)
206-
nokogiri (1.19.0-aarch64-linux-musl)
206+
nokogiri (1.19.1-aarch64-linux-musl)
207207
racc (~> 1.4)
208-
nokogiri (1.19.0-arm-linux-gnu)
208+
nokogiri (1.19.1-arm-linux-gnu)
209209
racc (~> 1.4)
210-
nokogiri (1.19.0-arm-linux-musl)
210+
nokogiri (1.19.1-arm-linux-musl)
211211
racc (~> 1.4)
212-
nokogiri (1.19.0-arm64-darwin)
212+
nokogiri (1.19.1-arm64-darwin)
213213
racc (~> 1.4)
214-
nokogiri (1.19.0-x86_64-linux-gnu)
214+
nokogiri (1.19.1-x86_64-linux-gnu)
215215
racc (~> 1.4)
216-
nokogiri (1.19.0-x86_64-linux-musl)
216+
nokogiri (1.19.1-x86_64-linux-musl)
217217
racc (~> 1.4)
218218
ostruct (0.6.3)
219219
parallel (1.27.0)
@@ -236,7 +236,7 @@ GEM
236236
nio4r (~> 2.0)
237237
raabro (1.4.0)
238238
racc (1.8.1)
239-
rack (3.2.4)
239+
rack (3.2.5)
240240
rack-proxy (0.7.7)
241241
rack
242242
rack-session (2.1.1)
@@ -246,30 +246,30 @@ GEM
246246
rack (>= 1.3)
247247
rackup (2.3.1)
248248
rack (>= 3)
249-
rails (8.1.2)
250-
actioncable (= 8.1.2)
251-
actionmailbox (= 8.1.2)
252-
actionmailer (= 8.1.2)
253-
actionpack (= 8.1.2)
254-
actiontext (= 8.1.2)
255-
actionview (= 8.1.2)
256-
activejob (= 8.1.2)
257-
activemodel (= 8.1.2)
258-
activerecord (= 8.1.2)
259-
activestorage (= 8.1.2)
260-
activesupport (= 8.1.2)
249+
rails (8.1.3)
250+
actioncable (= 8.1.3)
251+
actionmailbox (= 8.1.3)
252+
actionmailer (= 8.1.3)
253+
actionpack (= 8.1.3)
254+
actiontext (= 8.1.3)
255+
actionview (= 8.1.3)
256+
activejob (= 8.1.3)
257+
activemodel (= 8.1.3)
258+
activerecord (= 8.1.3)
259+
activestorage (= 8.1.3)
260+
activesupport (= 8.1.3)
261261
bundler (>= 1.15.0)
262-
railties (= 8.1.2)
262+
railties (= 8.1.3)
263263
rails-dom-testing (2.3.0)
264264
activesupport (>= 5.0.0)
265265
minitest
266266
nokogiri (>= 1.6)
267267
rails-html-sanitizer (1.6.2)
268268
loofah (~> 2.21)
269269
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
270-
railties (8.1.2)
271-
actionpack (= 8.1.2)
272-
activesupport (= 8.1.2)
270+
railties (8.1.3)
271+
actionpack (= 8.1.3)
272+
activesupport (= 8.1.3)
273273
irb (~> 1.13)
274274
rackup (>= 1.0.0)
275275
rake (>= 12.2)
@@ -431,14 +431,14 @@ DEPENDENCIES
431431
capybara-lockstep
432432
debug
433433
factory_bot_rails
434-
inertia_rails (~> 3.6)
434+
inertia_rails (~> 3.19)
435435
jbuilder
436436
js-routes
437437
kamal
438438
letter_opener
439439
propshaft
440440
puma (>= 5.0)
441-
rails (~> 8.1.1)
441+
rails (~> 8.1.3)
442442
rspec-rails (~> 8.0)
443443
rubocop-rails-omakase
444444
selenium-webdriver
Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import type { ResolvedComponent } from "@inertiajs/react"
21
import { createInertiaApp } from "@inertiajs/react"
3-
import { StrictMode } from "react"
4-
import { createRoot } from "react-dom/client"
52

63
import { initializeTheme } from "@/hooks/use-appearance"
74
import PersistentLayout from "@/layouts/persistent-layout"
@@ -14,51 +11,17 @@ void createInertiaApp({
1411
//
1512
title: (title) => (title ? `${title} - ${appName}` : appName),
1613

17-
resolve: (name) => {
18-
const pages = import.meta.glob<{ default: ResolvedComponent }>(
19-
"../pages/**/*.tsx",
20-
{
21-
eager: true,
22-
},
23-
)
24-
const page = pages[`../pages/${name}.tsx`]
25-
if (!page) {
26-
console.error(`Missing Inertia page component: '${name}.tsx'`)
27-
}
28-
29-
// To use a default layout, import the Layout component
30-
// and use the following line.
31-
// see https://inertia-rails.dev/guide/pages#default-layouts
32-
//
33-
page.default.layout ??= [PersistentLayout]
14+
pages: "../pages",
3415

35-
return page
36-
},
16+
layout: () => [PersistentLayout],
3717

38-
setup({ el, App, props }) {
39-
// Uncomment the following to enable SSR hydration:
40-
// if (el.hasChildNodes()) {
41-
// hydrateRoot(el, <App {...props} />)
42-
// return
43-
// }
44-
createRoot(el).render(
45-
<StrictMode>
46-
<App {...props} />
47-
</StrictMode>,
48-
)
49-
},
18+
strictMode: true,
5019

5120
defaults: {
5221
form: {
5322
forceIndicesArrayFormatInFormData: false,
5423
withAllErrors: true,
5524
},
56-
future: {
57-
useScriptElementForInitialPage: true,
58-
useDataInertiaHeadAttribute: true,
59-
useDialogForErrorModal: true,
60-
preserveEqualProps: true,
61-
},
6225
},
6326

6427
progress: {
@@ -80,4 +43,6 @@ void createInertiaApp({
8043
})
8144

8245
// This will set light / dark mode on load...
83-
initializeTheme()
46+
if (typeof localStorage !== "undefined") {
47+
initializeTheme()
48+
}

app/frontend/hooks/use-mobile.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,27 @@ import { useSyncExternalStore } from "react"
22

33
const MOBILE_BREAKPOINT = 768
44

5-
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
5+
const mql =
6+
typeof window !== "undefined"
7+
? window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
8+
: null
69

710
function mediaQueryListener(callback: (event: MediaQueryListEvent) => void) {
8-
mql.addEventListener("change", callback)
11+
mql?.addEventListener("change", callback)
912

1013
return () => {
11-
mql.removeEventListener("change", callback)
14+
mql?.removeEventListener("change", callback)
1215
}
1316
}
1417

1518
function isSmallerThanBreakpoint() {
16-
return mql.matches
19+
return mql!.matches
1720
}
1821

1922
export function useIsMobile() {
20-
return useSyncExternalStore(mediaQueryListener, isSmallerThanBreakpoint)
23+
return useSyncExternalStore(
24+
mediaQueryListener,
25+
isSmallerThanBreakpoint,
26+
() => false,
27+
)
2128
}

app/frontend/routes/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @file Generated by js-routes 2.3.6. Based on Rails 8.1.2 routes of ReactStarterKit::Application.
2+
* @file Generated by js-routes 2.3.6. Based on Rails 8.1.3 routes of ReactStarterKit::Application.
33
* @version 743c630cafd479b5d9ad42a7803e8be1fdeb9448419ce21d215b267e2b0ae749
44
* @see https://github.com/railsware/js-routes
55
*/

app/frontend/routes/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @file Generated by js-routes 2.3.6. Based on Rails 8.1.2 routes of ReactStarterKit::Application.
2+
* @file Generated by js-routes 2.3.6. Based on Rails 8.1.3 routes of ReactStarterKit::Application.
33
* @version 743c630cafd479b5d9ad42a7803e8be1fdeb9448419ce21d215b267e2b0ae749
44
* @see https://github.com/railsware/js-routes
55
*/

0 commit comments

Comments
 (0)