Skip to content

Commit

Permalink
setup ssr
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmajor committed Oct 10, 2024
1 parent 5458155 commit 01ed2c6
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/bootstrap/ssr
/node_modules
/public/build
/public/hot
Expand Down
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default [
},
{
ignores: [
'bootstrap/ssr',
'public',
'resources/js/helpers/ziggy.*',
],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "module",
"scripts": {
"dev": "vite dev",
"build": "vite build",
"build": "vite build && vite build --ssr",
"check": "php artisan ziggy:generate --types-only && svelte-check --tsconfig ./tsconfig.json --fail-on-warnings",
"check:watch": "php artisan ziggy:generate --types-only && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "eslint . --max-warnings 0",
Expand Down
3 changes: 2 additions & 1 deletion resources/js/Components/Images/ResponsiveImage.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import { tick, onMount } from 'svelte';
import { BROWSER } from 'esm-env';
import resizedImageUrl from '@/helpers/resizedImageUrl';
let {
Expand All @@ -23,7 +24,7 @@
let element: HTMLImageElement;
let mountedAt: number;
let isHidden = $state(true);
let isHidden = $state(BROWSER);
let transitionClass = $state(false);
onMount(() => {
Expand Down
11 changes: 8 additions & 3 deletions resources/js/browser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mount } from 'svelte';
import { mount, hydrate } from 'svelte';
import { createInertiaApp } from '@inertiajs/svelte';
import { resolve } from './common';

Expand All @@ -8,8 +8,13 @@ document.startViewTransition ??= (cb: () => void) => cb();
createInertiaApp({
resolve,
setup({ el, App, props }) {
// @ts-expect-error
mount(App, { target: el, props });
if (document.querySelector('[data-server-rendered]')) {
// @ts-expect-error
hydrate(App, { target: el, props });
} else {
// @ts-expect-error
mount(App, { target: el, props });
}
},
progress: {
color: '#ffcc00',
Expand Down
5 changes: 5 additions & 0 deletions resources/js/ssr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createInertiaApp } from '@inertiajs/svelte';
import createServer from '@inertiajs/svelte/server';
import { resolve } from './common';

createServer((page) => createInertiaApp({ page, resolve }));
1 change: 1 addition & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default defineConfig({
plugins: [
laravel({
input: ['resources/js/browser.ts', 'resources/css/style.css'],
ssr: 'resources/js/ssr.ts',
refresh: true,
}),
svelte({
Expand Down

0 comments on commit 01ed2c6

Please sign in to comment.