You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now the only way of running JS code on Elixir is using NodeJS call but
there are other ways of executing JS like for example using Bun runtime
or in development rendering the inertia app using VideJS dev server.
This changes allow users to hook into inertia's ssr system and use their
own adapters.
Copy file name to clipboardExpand all lines: README.md
+24-6Lines changed: 24 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,7 +55,7 @@ config :inertia,
55
55
# conventional in JavaScript. Defaults to `false`.
56
56
camelize_props:false,
57
57
58
-
# Instruct the client side whether to encrypt the page object in the window history
58
+
# Instruct the client side whether to encrypt the page object in the window history
59
59
# state. This can also be set/overridden on a per-request basis, using the `encrypt_history`
60
60
# controller helper. Defaults to `false`.
61
61
history: [encrypt:false],
@@ -64,6 +64,10 @@ config :inertia,
64
64
# see instructions below). Defaults to `false`.
65
65
ssr:false,
66
66
67
+
# By default the server side rendering is done by executing nodejs.
68
+
# you can use your own adapter following the spec.
69
+
ssr_adapter:MyAdapter
70
+
67
71
# Whether to raise an exception when server-side rendering fails (only applies
68
72
# when SSR is enabled). Defaults to `true`.
69
73
#
@@ -313,7 +317,7 @@ conn
313
317
314
318
## Deferred props
315
319
316
-
**Requires Inertia v2.x on the client-side**.
320
+
**Requires Inertia v2.x on the client-side**.
317
321
318
322
If you have expensive data that you'd like to automatically fetch (from the client-side via an async background request) after the page is initially rendered, you can mark the prop as deferred:
319
323
@@ -361,7 +365,7 @@ defmodule MyApp.UserAuth do
361
365
362
366
defauthenticate_user(conn, _opts) do
363
367
user =get_user_from_session(conn)
364
-
368
+
365
369
# Here we are storing the user in the conn assigns (so
366
370
# we can use it for things like checking permissions later on),
367
371
# AND we are assigning a serialized represention of the user
@@ -405,7 +409,7 @@ The `assign_errors` function will automatically convert the changeset errors int
405
409
{
406
410
"name"=>"can't be blank",
407
411
408
-
// Nested errors keys are flattened with a dot separator (`.`)
412
+
// Nested errors keys are flattened with a dot separator (`.`)
409
413
"team.name"=>"must be at least 3 characters long",
410
414
411
415
// Nested arrays are zero-based and indexed using bracket notation (`[0]`)
@@ -507,7 +511,6 @@ conn
507
511
508
512
The `Inertia.Testing` module includes helpers for testing your Inertia controller responses, such as the `inertia_component/1` and `inertia_props/1` functions.
509
513
510
-
511
514
```elixir
512
515
useMyAppWeb.ConnCase
513
516
@@ -629,6 +632,7 @@ Add the `ssr` build to the watchers in your dev environment, alongside the other
629
632
]
630
633
```
631
634
635
+
### Build and deploy with SSR
632
636
Add the `ssr` build step to the asset build and deploy scripts.
633
637
634
638
```diff
@@ -714,7 +718,7 @@ Then, update your config to enable SSR (if you'd like to enable it globally).
714
718
# assets using the `static_paths` config). Defaults to "1".
715
719
default_version: "1",
716
720
717
-
# Enable server-side rendering for page responses (requires some additional setup,
721
+
# Enable server-side rendering for page responses (requires some additional setup,
718
722
# see instructions below). Defaults to `false`.
719
723
- ssr: false
720
724
+ ssr: true
@@ -728,6 +732,20 @@ Then, update your config to enable SSR (if you'd like to enable it globally).
728
732
raise_on_ssr_failure: config_env() != :prod
729
733
```
730
734
735
+
### Using ESM (EcmaScript Modules) on SSR entrypoint
736
+
737
+
By default this library uses CommonJS modules for SSR. If you want to use ESM (EcmaScript Modules) set `esm: true` in your config.
You can setup your own SSR adapter. This is a list of third party adapters.
746
+
747
+
-[vitex](https://github.com/andresgutgon/vitex) is a package that helps with ViteJS development in Phoenix apps. It has a custom SSR adapter for this package (inertia-phoenix) so SSR can be handle in development through Vite Dev server instead of calling a NodeJS process like we do in production. You can see [how it's configured here](https://github.com/andresgutgon/vitex?tab=readme-ov-file#configuring-vitejs-in-your-phoenix-app)
748
+
731
749
### Installing Node.js in your production
732
750
733
751
You need to have Node.js installed in your production server environment, so that we can call the SSR script when serving pages. These steps assume you are deploying your application using a Dockerfile and releases.
0 commit comments