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:
-
Ensure SSR is enabled in your environment: Make sure that SSR is enabled in your
.envfile by settingINERTIA_SSR_ENABLED=true. -
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. -
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.
-
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.
-
Check your routes: Ensure that your routes are set up to return Inertia responses. For example:
Route::get('/', function () {
return Inertia::render('Welcome');
});
-
Ensure
ssr.jsis built: Make sure that you've runnpm run buildand that it has successfully built thessr.jsfile without errors. -
Check the
ssr.jsfile: Ensure that thessr.jsfile is correctly resolving your Vue components. The path inresolvePageComponentshould match the actual location of your Vue files. -
Check for JavaScript errors: Sometimes, JavaScript errors can prevent SSR from rendering correctly. Check your browser's console for any errors.
-
Verify middleware: Ensure that the
HandleInertiaRequestsmiddleware is included in yourapp/Http/Kernel.phpfile. -
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.