Well after some messing around, I was able to get this to work, after running bun install ziggy-js and using this as my ssr.jsx file and HandlesInertiaRequests.php file:
import { createInertiaApp } from "@inertiajs/react";
import createServer from "@inertiajs/react/server";
import ReactDOMServer from "react-dom/server";
import { route } from "ziggy-js";
const appName = import.meta.env.VITE_APP_NAME || "Laravel";
createServer((page) => {
globalThis.Ziggy = page.props.ziggy;
return createInertiaApp({
title: (title) => `${title} - ${appName}`,
page,
render: ReactDOMServer.renderToString,
resolve: (name) => {
const pages = import.meta.glob("./Pages/**/*.jsx", { eager: true });
return pages[`./Pages/${name}.jsx`];
},
setup: ({ App, props }) => {
const Ziggy = {
// Pull the Ziggy config off of the props.
...props.initialPage.props.ziggy,
// Build the location, since there is
// no window.location in Node.
location: new URL(props.initialPage.props.ziggy.url),
};
global.route = (name, params, absolute, config = Ziggy) =>
route(name, params, absolute, config);
return <App {...props} />;
},
progress: {
color: "#4B5563",
},
});
});
<?php
namespace App\Http\Middleware;
use Illuminate\Http\Request;
use Inertia\Middleware;
use Tighten\Ziggy\Ziggy;
class HandleInertiaRequests extends Middleware
{
/**
* The root template that is loaded on the first page visit.
*
* @var string
*/
protected $rootView = 'app';
/**
* Determine the current asset version.
*/
public function version(Request $request): ?string
{
return parent::version($request);
}
/**
* Define the props that are shared by default.
*
* @return array<string, mixed>
*/
public function share(Request $request): array
{
$ziggy = new Ziggy($group = null, $request->url());
return array_merge(parent::share($request), [
// Add in Ziggy routes for SSR
'ziggy' => $ziggy->toArray(),
'auth' => [
'user' => $request->user(),
],
]);
}
}