ozziexsh/laravel-jetstream-react

SSR not working

Closed this issue · 3 comments

jezzdk commented

I'm trying to get SSR to work but I'm running into issues. I haven't enabled SSR from scratch, I've enabled it only after a while, which might be why I'm having issues.

I'm running the latest version of everything. I've set up everything according to the guides, and the Inertia SSR server is running, but when I refresh the browser I get an error in the console about this line:

location: new URL((page.props as any).ziggy.url),

A console.log(page.props) reveals that there is no 'ziggy' property present, which is why it breaks when trying to access the page.props.ziggy.url property.

When does the ziggy property get set on the page props?

jezzdk commented

I can only get it to work if I run php artisan ziggy:generate and then use it in the ssr file:

import { Ziggy } from './ziggy.js';
...
return route(name, params, absolute, {
    ...Ziggy,
    location: new URL(Ziggy.url),
    ...config,
});

But should that really be necessary?

hey, thanks for opening this!

haven't tried this locally yet but a quick search seems like maybe this could be the cause:

laravel/jetstream#1024

if the project wasn't generated with the --ssr flag initially it would mean that the required ziggy data wasn't being shared by the middleware

can you ensure that your HandleInertiaRequests class has the ziggy key as shown here and report back?

https://github.com/laravel/jetstream/blob/3.x/stubs/inertia/app/Http/Middleware/HandleInertiaRequests.php#L34

jezzdk commented

I can confirm it's working with that change to the middleware. That was actually the missing piece of the puzzle! Next time I'm gonna use the --ssr flag in the initial setup 😅

Thanks for the help!