0

I’m trying to deploy a Laravel application using Inertia.js with server-side rendering (SSR). However, when I navigate between links, I encounter the following error:

All Inertia requests must receive a valid Inertia response, however a plain JSON response was received.

My Setup:

  • Vue component link:
    <Link :href="route('welcome')" class="me-4 hover:underline md:me-6">
      Annonser
    </Link>

(I have imported Link from @inertiajs/vue3.)

  • Route definition:
  return Inertia::render('Welcome');

Server details:

  • Ubuntu 24.10
  • Nginx 1.26.0
  • PHP 8.3.11
  • php artisan inertia:start-ssr is running and active.

Observations:

  1. TCPDump:

When I use tcpdump on port 13714, I see traffic on the initial request. But when I try to navigate within the app, no traffic appears on this port, and the error occurs.

  1. Nginx Configuration Quirk:

If I modify my Nginx configuration so the default server block (using the IP xxx.xxx.xxx.xxx) points to laravel/public instead of the domain name (example.com), the navigation works as expected. But still tcpdump only show traffic on the initial request.

  1. Curl Request:

When I run curl 127.0.0.1:13714, I get:

    {"status":"NOT_FOUND","timestamp":1733846743327}

php artisan inertia:start-ssr is runnig.

  1. JavaScript Behavior:

When I disable JavaScript, the content disappears entirely.

Potential Issue:

Could this be related to a hostname misconfiguration in the SSR setup? I’ve ensured the X-Inertia header is present, but I still can’t figure out why it only works with the IP-based configuration.

Any help or insights on how to resolve this issue would be greatly appreciated!

UPDATE: When i disable javascript for my site, i get full page reloads now. Dont know if it was because i changed app.js

from

return createApp({ render: () => h(App, props) })

to

return createSSRApp({ render: () => h(App, props) })

This according to https://inertiajs.com/server-side-rendering. But 99% of users will have javascript enabled, so the error persists.

When php artisan inertia:start-ssr is running, and javascript is disabled, all links seems to be working. But when javascript is enabled, i still get Laravel Inertia.js SSR Error: “All Inertia requests must receive a valid Inertia response”. What is the cause?

1 Answer 1

0

If you ever find this topic and the same issue. For me it was that Laravel was pointing to http and not https. Seems legit in a development environment... but not for production.

So whats the solution? This: https://stackoverflow.com/a/61313133/4892914

Your AppServiceProvider.php, boot() function should look like this:

public function boot(): void
{
    Vite::prefetch(concurrency: 3); // optional ofc

    if (env('APP_ENV') === 'production') {
        \Illuminate\Support\Facades\URL::forceScheme('https');
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.