Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support SSR in Vite dev mode #2014

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

jrmajor
Copy link

@jrmajor jrmajor commented Oct 11, 2024

Laravel part handled in inertiajs/inertia-laravel#673.

Adding support for SSR in dev mode would enable developers to discover hydration mismatches/errors before they reach production.

User would need to create additional entrypoint (alongside app.ts and ssr.ts):

import { createInertiaApp } from '@inertiajs/svelte'
import type { AppCallback } from '@inertiajs/svelte/server'

const render: AppCallback = (page) =>
  createInertiaApp({
    page,
    resolve: (name) => import(`./Pages/${name}.svelte`),
  })

export default render

...and add Inertia plugin to Vite:

  import { svelte } from '@sveltejs/vite-plugin-svelte'
  import laravel from 'laravel-vite-plugin'
  import { defineConfig } from 'vite'
+ import inertia from '@inertiajs/core/vite';

 export default defineConfig({
    plugins: [
      laravel({
        input: ['resources/css/app.css', 'resources/js/app.ts'],
        ssr: 'resources/js/ssr.ts',
        refresh: true,
      }),
+     inertia('resources/js/viteSsr.ts'),
      svelte(),
    ],
  })

@jrmajor jrmajor force-pushed the dev-ssr branch 3 times, most recently from 76bf077 to 4fdff4b Compare October 11, 2024 10:13
@harryqt
Copy link

harryqt commented Oct 11, 2024

This was indeed needed. 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants