Skip to content

Upgrade inertia to v3#258

Open
nerlichman wants to merge 5 commits intoinertia-rails:mainfrom
nerlichman:upgrade-inertia-3
Open

Upgrade inertia to v3#258
nerlichman wants to merge 5 commits intoinertia-rails:mainfrom
nerlichman:upgrade-inertia-3

Conversation

@nerlichman
Copy link
Copy Markdown
Contributor

@nerlichman nerlichman commented Mar 29, 2026

Changes

  • Upgrade @inertiajs/react from v2 to v3 and inertia_rails gem to ~> 3.19.
  • Add @inertiajs/vite plugin.
  • Simplify inertia and ssr entrypoints using pages, layout, and strictMode options instead of manual resolve/setup.
  • Remove future options block.
  • Update <title inertia> to <title data-inertia>.
  • Add use_data_inertia_head_attribute to Rails initializer.
  • Add void to ssr entrypoint (required by lint_js step).
  • Update gem versions required by scan_ruby ci step.

* 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)
Required by scan_ruby ci step due to vulnerabilities
@skryukov
Copy link
Copy Markdown
Collaborator

Thanks @nerlichman!

Do you think we should go further, drop ssr/ssr.tsx, and pass entry point to inertia vite plugin instead?

inertia({
  ssr: "app/frontend/entrypoints/inertia.tsx",
}),

@nerlichman
Copy link
Copy Markdown
Contributor Author

nerlichman commented Mar 29, 2026

Yeah, sounds great!

I'll also need to guard initializeTheme() on the entrypoint:

if (typeof localStorage !== "undefined") {
  initializeTheme()
}

I enabled SSR to test and found a few errors.

First in the vite config, setting this results in SSR ERROR ... module is not defined:

  ssr: {
    // prebuilds ssr.js so we can drop node_modules from the resulting container
    noExternal: true,
  },

In order not to remove this, the solution I found was doing the following:

export default defineConfig(({ command }) => ({
  ssr: command === "build"
    ? { noExternal: true } // prebuild ssr.js so we can drop node_modules from the container
    : undefined,
  plugins: [
//  ...

But I'm not sure if this is correct.

Another thing is that I also realized that SSR is not working, due to hooks/use-mobile.ts using window. But I thing this is better to address on a separate PR.
EDIT: I updated the hook with a guard to check if window is defined.

What do you think?

This addresses the error:

SSR ERROR  window is not defined
Source: hooks/use-mobile.ts:5:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants