Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

browntown's avatar

Can't get Inertia SSR to work on a fresh Laravel 10 application

I am struggling to get Inertia SSR working in my application. I tested in a brand new Laravel application and I'm getting the same result, content doesn't seem to be rendering on the server side.

  1. I created a new Laravel application.
  2. I have followed all of the steps for implementing SSR.
  3. I ran npm run build
  4. I started ran php artisan inertia:start-ssr
  5. I refreshed my application and looked at the source code. I do not see any server rendered code.

resources/js/ssr.js

import { createSSRApp, h } from 'vue';
import { renderToString } from '@vue/server-renderer';
import { createInertiaApp } from '@inertiajs/vue3';
import createServer from '@inertiajs/vue3/server';
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
import { ZiggyVue } from '../../vendor/tightenco/ziggy/dist/vue.m';

const appName = import.meta.env.VITE_APP_NAME || 'Laravel';

createServer((page) =>
    createInertiaApp({
        page,
        render: renderToString,
        title: (title) => `${title} - ${appName}`,
        resolve: (name) => resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue')),
        setup({ App, props, plugin }) {
            return createSSRApp({ render: () => h(App, props) })
                .use(plugin)
                .use(ZiggyVue, {
                    ...page.props.ziggy,
                    location: new URL(page.props.ziggy.location),
                });
        },
    })
);

vite.config.js

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue';

export default defineConfig({
    plugins: [
        laravel({
            input: 'resources/js/app.js',
            ssr: 'resources/js/ssr.js',
            refresh: true,
        }),
        vue({
            template: {
                transformAssetUrls: {
                    base: null,
                    includeAbsolute: false,
                },
            },
        }),
    ],
});

package.json

{
    "private": true,
    "type": "module",
    "scripts": {
        "dev": "vite",
        "build": "vite build && vite build --ssr"
    },
    "devDependencies": {
        "@inertiajs/vue3": "^1.0.0",
        "@tailwindcss/forms": "^0.5.3",
        "@vitejs/plugin-vue": "^5.0.0",
        "@vue/server-renderer": "^3.4.0",
        "autoprefixer": "^10.4.12",
        "axios": "^1.6.4",
        "laravel-vite-plugin": "^1.0.0",
        "postcss": "^8.4.31",
        "tailwindcss": "^3.2.1",
        "vite": "^5.0.0",
        "vue": "^3.4.0"
    }
}

I am not seeing any changes that would indicate SSR is running, no error messages, no change of the code, nothing.

Does anyone have any suggestions?

0 likes
16 replies
LaryAI's avatar
Level 58

Based on the information provided, it seems like you've set up the basics for Inertia SSR correctly. However, there are a few things we can check to ensure that SSR is working as expected:

  1. Ensure SSR is enabled in your environment: Make sure that SSR is enabled in your .env file by setting INERTIA_SSR_ENABLED=true.

  2. Check the server logs: When you run php artisan inertia:start-ssr, check the console for any errors or warnings that might indicate what's going wrong.

  3. Verify SSR output: After starting the SSR server, you should be able to see the server-rendered HTML when you view the page source in your browser. If you don't see this, SSR might not be functioning correctly.

  4. Inspect the network requests: Open your browser's developer tools and check the network tab to see if there are any failed requests or errors that could be preventing SSR from working.

  5. Check your routes: Ensure that your routes are set up to return Inertia responses. For example:

Route::get('/', function () {
    return Inertia::render('Welcome');
});
  1. Ensure ssr.js is built: Make sure that you've run npm run build and that it has successfully built the ssr.js file without errors.

  2. Check the ssr.js file: Ensure that the ssr.js file is correctly resolving your Vue components. The path in resolvePageComponent should match the actual location of your Vue files.

  3. Check for JavaScript errors: Sometimes, JavaScript errors can prevent SSR from rendering correctly. Check your browser's console for any errors.

  4. Verify middleware: Ensure that the HandleInertiaRequests middleware is included in your app/Http/Kernel.php file.

  5. Check for compatibility issues: Ensure that all packages and dependencies are compatible with SSR and that you're using the correct versions.

If you've checked all the above and still can't get SSR to work, you might want to create a minimal reproduction of the issue and seek further assistance from the Inertia.js community or the Laracasts forums.

Here's a minimal example of how your ssr.js should look:

import { createSSRApp, h } from 'vue';
import { renderToString } from '@vue/server-renderer';
import { createInertiaApp } from '@inertiajs/inertia-vue3';
import createServer from '@inertiajs/server';
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';

createServer(page => createInertiaApp({
  page,
  render: renderToString,
  resolve: name => resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue')),
  setup({ app, props, plugin }) {
    return createSSRApp({ render: () => h(app, props) }).use(plugin);
  },
}));

Please note that the createServer import should be from @inertiajs/server and not @inertiajs/vue3/server. Also, make sure that the createInertiaApp import is from @inertiajs/inertia-vue3 and not @inertiajs/vue3.

If you've tried all these steps and are still facing issues, please provide more details about the steps you've taken and any error messages you're seeing so that the community can assist you further.

gych's avatar

In your source code the rendered code is in

<div id="app" data-page="HERE COMES THE RENDERED CODE">

Simple way to visibly test if ssr works:

  • start ssr
  • disable javascript in browser (this will disable client side rendering)
  • open your website, if the page is blank ssr is not working if the template is rendered ssr works
2 likes
browntown's avatar

@gych Thanks for the reply. SSR is definitely not working. I'm getting a blank page. I don't see any error messages when I run inertia:start-ssr. My ssr assets seem to build fine. I even checked to see if I'm getting an node errors, there were a few, I resolved those. I'm still only getting a blank page when I have javascript disabled.

Any other suggestions?

gych's avatar

@browntown Can you share the code of your app.js file? Then I can compare it to your ssr.js file that you've already added to your post.

browntown's avatar

@gych Absolutely. Thanks.

import './bootstrap';
import '../css/app.css';

import { createApp, h } from 'vue';
import { createInertiaApp } from '@inertiajs/vue3';
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
import { ZiggyVue } from '../../vendor/tightenco/ziggy/dist/vue.m';

const appName = import.meta.env.VITE_APP_NAME || 'Laravel';

createInertiaApp({
    title: (title) => `${title} - ${appName}`,
    resolve: (name) => resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue')),
    setup({ el, App, props, plugin }) {
        return createApp({ render: () => h(App, props) })
            .use(plugin)
            .use(ZiggyVue)
            .mount(el);
    },
    progress: {
        color: '#4B5563',
    },
});
gych's avatar

@browntown Looks good to me, very strange that it doesn't work for you Do you test ssr from your served dev environment or from your build in public folder?

browntown's avatar

@gych I've tested it in both, mainly in dev but have tested in production as well. Same results. Yeah, it's really driving me nuts. The fact that cant find anything in logs or any errors it really confusing me.

gych's avatar

@browntown Since its a fresh installation, have you already tried reinstalling everything? Maybe something went wrong during the initial installation.

browntown's avatar

@gych yeah, it's actually the second time I've tried starting with a blank slate. I'll do it a third time to confirm.

browntown's avatar

@gych Thanks for all the help. i really appreciate it.

The good news...I think we're getting somewhere. I just created a third application, followed the same steps with one difference...I started this one using artisan serve...the others were started with docker. When I don't use docker, I'm able to generate the SSR.

Now I just need to figure out what's going on with Docker.

browntown's avatar

@gych okay. I think I got it sorted.

I still don't know why it's not working on Docker...I'm sure that's going to take some more investigating on my end. As long as I know it's working in production...that's good enough for me now.

Here's what I found out:

  1. I wasn't passing any ziggy routes in the page props that the ssr.js file was looking for. I fixed that.
  2. The ssr file that the breeze install was referencing page.props.ziggy.location. Ziggy was returning the url in a url field. I changed the location value to page.props.ziggy.url.

So this...

.use(ZiggyVue, {
                    ...page.props.ziggy,
                    location: new URL(page.props.ziggy.location),
                });

became this...

.use(ZiggyVue, {
                    ...page.props.ziggy,
                    location: new URL(page.props.ziggy.url),
                });

I really appreciate your engagement on this. You really helped me think through scenarios and helped fine the solution. Thanks again.

2 likes
gych's avatar

@browntown No problem, I'm glad you managed to figure it out to let it work on production! That's the most important, that it works for the production environment :)

I saw a post of someone that was having the same isssue with ziggy.location https://stackoverflow.com/questions/73951392/laravel-inertia-unable-to-implement-server-side-rendering-with-default-scaffo

Did not really think that its affecting more people, I've always used ziggy.location without issues

pixelsforhire's avatar

Just wanted to chime in here because it reminds me of a frustration that I experienced locally with Inertia SSR that turned out to be a facepalm moment for me. Not sure if it will help OP but might help someone finding this thread.

OP said:

I started ran php artisan inertia:start-ssr ... When I don't use docker, I'm able to generate the SSR. ... I still don't know why it's not working on Docker...

I too was having this issue and finally realized the problem was quite simple: I was running the command php artisan inertia:start-ssr but should have been running that command inside the Docker container, in my case via Laravel Sail as sail artisan inertia:start-ssr.

So, TLDR, if you're running Docker, Sail, etc. start the Inertia SSR inside the Docker container not locally.

THIS: sail artisan inertia:start-ssr

NOT THIS: php artisan inertia:start-ssr

Hope it helps save someone the frustration and expletives that it caused me.

Please or to participate in this conversation.