Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"validator",
"actix-validator"
],
"rust-analyzer.checkOnSave.command": "clippy",
"rust-analyzer.checkOnSave": true,
"rust-analyzer.check.command": "clippy",
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer",
"editor.formatOnSave": true
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog

## Unreleased
### Changed
- Undeserializable responses from SSR server now are parsed as string and added to the error message;
- Pages will only be logged in debug level and only when an error occur.

## v2.4.4
### Changed
Expand Down
3 changes: 1 addition & 2 deletions examples/actix_ssr/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3,564 changes: 1,448 additions & 2,116 deletions examples/actix_ssr/package-lock.json

Large diffs are not rendered by default.

24 changes: 11 additions & 13 deletions examples/actix_ssr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,20 @@
"preview": "vite preview"
},
"dependencies": {
"@inertiajs/core": "2.0",
"@inertiajs/react": "2.0",
"@phosphor-icons/react": "^2.1.7",
"@vitejs/plugin-react": "^4.3.1",
"laravel-vite-plugin": "^1.0.5",
"react": "^18.3.1",
"react-dom": "^18.3.1"
"@inertiajs/core": "2.2",
"@inertiajs/react": "2.2",
"@phosphor-icons/react": "2.1.10",
"@tailwindcss/vite": "^4.1.16",
"@vitejs/plugin-react": "5.1.0",
"laravel-vite-plugin": "2.0.1",
"react": "19",
"react-dom": "19"
},
"devDependencies": {
"@types/node": "^22.7.4",
"@types/react-dom": "^18.3.0",
"autoprefixer": "^10.4.20",
"postcss-import": "^16.1.0",
"tailwindcss": "^3.4.14",
"vite": "5.4.8",
"vite-rs-plugin": "^1.0.1"
"@types/react-dom": "19",
"tailwindcss": "4",
"vite": "7"
},
"keywords": [],
"author": "",
Expand Down
7 changes: 0 additions & 7 deletions examples/actix_ssr/postcss.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion examples/actix_ssr/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn get_server() -> App<

Box::pin(async move {
hashmap![
"version" => InertiaProp::always("0.1.0"),
"version" => InertiaProp::always("2"),
"assetsVersion" => InertiaProp::lazy(prop_resolver!({ ASSETS_VERSION.get().unwrap().into_inertia_value() })),
"flash" => InertiaProp::always(flash)
]
Expand Down
9 changes: 0 additions & 9 deletions examples/actix_ssr/tailwind.config.js

This file was deleted.

4 changes: 3 additions & 1 deletion examples/actix_ssr/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import react from '@vitejs/plugin-react';
import laravel from 'laravel-vite-plugin';
import { defineConfig } from 'vite';
import tailwindcss from "@tailwindcss/vite"

export default defineConfig(() => {
return {
plugins: [
plugins: [
laravel({
input: 'www/app.tsx',
buildDirectory: 'bundle',
ssrOutputDirectory: "dist/ssr",
ssr: "www/ssr.tsx",
}),
react(),
tailwindcss()
],
// important to serve statics from public dir directly from "localhost:5173/" instead of "localhost:5173/public"
// just "public" without slash prefix won't work
Expand Down
4 changes: 1 addition & 3 deletions examples/actix_ssr/www/index.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
@import "tailwindcss";

@layer base {
* {
Expand Down
4 changes: 2 additions & 2 deletions examples/actix_ssr/www/pages/Contact.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Head, Link } from "@inertiajs/react"
import { ArrowLeft } from "@phosphor-icons/react/dist/ssr/ArrowLeft"
import { ArrowLeftIcon } from "@phosphor-icons/react/dist/ssr/ArrowLeft"

type Props = {
user: {
Expand All @@ -25,7 +25,7 @@ export default function Contact({ user, assetsVersion }: Props) {
px-8 py-3 rounded-xl cursor-default
"
>
<span className="transition-all relative left-0 group-hover:-left-1"><ArrowLeft size={24} weight="bold" /></span>
<span className="transition-all relative left-0 group-hover:-left-1"><ArrowLeftIcon size={24} weight="bold" /></span>
Back to home!
</Link>

Expand Down
4 changes: 2 additions & 2 deletions examples/actix_ssr/www/pages/Foo/Index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Head, Link } from "@inertiajs/react";
import { ArrowLeft } from "@phosphor-icons/react/dist/ssr";
import { ArrowLeftIcon } from "@phosphor-icons/react/dist/ssr/ArrowLeft";
import { useEffect } from "react";

export default function Index(props: any) {
Expand All @@ -22,7 +22,7 @@ export default function Index(props: any) {
flex items-center gap-3 bg-purple-400/25 px-8 py-3 rounded-xl
"
>
<ArrowLeft size={24} weight="bold" />
<ArrowLeftIcon size={24} weight="bold" />
Go back, then?
</Link>
</div>
Expand Down
4 changes: 2 additions & 2 deletions examples/actix_ssr/www/pages/Index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Head, Link } from "@inertiajs/react"
import { ArrowSquareOut } from "@phosphor-icons/react/dist/ssr/ArrowSquareOut";
import { ArrowSquareOutIcon } from "@phosphor-icons/react/dist/ssr/ArrowSquareOut";
import { useState } from "react"

type Props = {
Expand Down Expand Up @@ -44,7 +44,7 @@ export default function Index({message, version}: Props) {
flex items-center gap-3 bg-purple-400/25 px-8 py-3 rounded-xl
"
>
Other page? <ArrowSquareOut size={24} weight="bold" />
Other page? <ArrowSquareOutIcon size={24} weight="bold" />
</Link>
</div>
</main>
Expand Down
10 changes: 8 additions & 2 deletions examples/actix_ssr/www/root.hbs
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
<!doctype html>
<html lang="en" class="h-full">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">
<link
href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap"
rel="stylesheet">
<meta name="ssr" content="{{ view_data.is_ssr }}">
{{{ vite_react_refresh }}}
{{{ vite }}}
{{{ inertia_head }}}
</head>

<body class="h-full">
{{{ inertia_body }}}
</body>

</html>
6 changes: 2 additions & 4 deletions src/providers/actix_provider/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ impl InertiaResponder<HttpResponse, HttpRequest, Redirect> for Inertia {
encrypt_history: req.should_encrypt_history(self.encrypt_history),
};

log::debug!("Starting render of page {page:#?}");

let response = if req.is_inertia_request() {
let mut response = page.respond_to(req);

Expand Down Expand Up @@ -333,10 +331,10 @@ impl Inertia {
.await
.map(Some)
.unwrap_or_else(|err| {
log::debug!("Failed to render page {page:#?}");
log::error!(
"[Inertia Rust] Error on server-side rendering page {} with page props {page:#?}: {}",
"Error on server-side rendering page {}: {err}",
page.component.0,
err
);

None
Expand Down
43 changes: 27 additions & 16 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,34 @@ pub(crate) async fn request_page_render(
.json(&page)
.timeout(Duration::from_secs(5))
.send()
.await;

let response = match response {
Err(err) => {
return Err(InertiaError::SsrError(format!(
.await
.map_err(|err| {
InertiaError::SsrError(format!(
"Failed to render the page at the SSR Server: {}",
err
)))
}
Ok(response) => response,
};
))
})?;

match response.json::<InertiaSSRPage>().await {
Err(err) => Err(InertiaError::SsrError(format!(
"Failed to desserialize InertiaSSRPage object: {}",
err
))),
Ok(page) => Ok(page),
}
let body = response
.bytes()
.await
.map_err(|err| {
InertiaError::SsrError(format!("Failed to read SSR response's bytes: {err}"))
})?
.to_vec();

serde_json::from_slice::<InertiaSSRPage>(&body).map_err(|json_err| {
let body_as_text = String::from_utf8(body);
match body_as_text {
Ok(text_body) => InertiaError::SsrError(format!(
"Failed to deserialize InertiaSSRPage object \
from body with error: {json_err}. Received body: {text_body}"
)),
Err(text_error) => InertiaError::SsrError(format!(
"Failed to deserialize InertiaSSRPage object \
from body with error: {json_err}. Also failed to read bytes as text \
with error: {text_error}",
)),
}
})
}