Skip to content

Commit

Permalink
Support unicode props
Browse files Browse the repository at this point in the history
  • Loading branch information
derrickreimer committed Jul 11, 2024
1 parent 9d92752 commit 0079beb
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.8.0

### Features

- Support unicode props (by using the `binary` flag on Node function calls)

## 0.7.0

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion lib/inertia/ssr.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ defmodule Inertia.SSR do
@doc false
def call(page) do
module = GenServer.call(Config, :module)
NodeJS.call({module, :render}, [page], name: supervisor_name())
NodeJS.call({module, :render}, [page], name: supervisor_name(), binary: true)
end

defp supervisor_name do
Expand Down
22 changes: 22 additions & 0 deletions test/inertia_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,28 @@ defmodule InertiaTest do
assert body =~ ~s(<div id="ssr"></div>)
end


test "supports binary", %{conn: conn} do
path =
__ENV__.file
|> Path.dirname()
|> Path.join("js")

start_supervised({Inertia.SSR, path: path})

Application.put_env(:inertia, :ssr, true)

conn =
conn
|> get(~p"/binary_props")

body = html_response(conn, 200)

assert body =~ ~r/<title inertia>(\s*)New title(\s*)<\/title>/
assert body =~ ~s(<meta name="description" content="Head stuff" />)
assert body =~ ~s(<div id="ssr">’</div>)
end

@tag :capture_log
test "falls back to CSR if SSR fails and failure mode set to csr", %{conn: conn} do
path =
Expand Down
4 changes: 2 additions & 2 deletions test/js/ssr.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// A dummy module to simulate Inertia SSR rendering responses
module.exports = {
render: (_page) => {
render: (page) => {
return {
head: [
`<title inertia>New title</title>`,
`<meta name="description" content="Head stuff" />`,
],
body: `<div id="ssr"></div>`,
body: `<div id="ssr">${page.props.content || ""}</div>`,
};
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ defmodule MyAppWeb.PageController do
|> render_inertia("Home")
end

def binary_props(conn, _params) do
conn
|> assign(:page_title, "Home")
|> assign_prop(:content, "’")
|> render_inertia("Home")
end

def update(conn, _params) do
conn
|> put_flash(:info, "Updated")
Expand Down
1 change: 1 addition & 0 deletions test/support/my_app/lib/my_app_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ defmodule MyAppWeb.Router do
get "/external_redirect", PageController, :external_redirect
get "/overridden_flash", PageController, :overridden_flash
get "/struct_props", PageController, :struct_props
get "/binary_props", PageController, :binary_props
put "/", PageController, :update
patch "/", PageController, :patch
delete "/", PageController, :delete
Expand Down

0 comments on commit 0079beb

Please sign in to comment.