If I put a prop into Layer and this prop is not sent from the server, Intertia crashes and stops working. It crashes even if the default value is set in Svelte.
Laravel source code:
Laravel routes file ./routes/web.php:
<?php
use App\Http\Controllers\FormControler;
use Illuminate\Support\Facades\Route;
use Inertia\Inertia;
Route::inertia('/page1', 'PageOne');
Route::get('/page2', function () {
return Inertia::render('PageTwo', [
'user' => [
'name' => 'honza',
'email' => 'honza@example.com'
],
]);
});
<script>
export let user = {name:'unknown',email:'unknown'};
</script>
<header>
This is AppLayout, user: {user.name}
</header>
<main>
<slot />
</main>
Page one ./resources/js/Pages/PageOne.svelte:
<script context="module">
export { default as layout } from './AppLayout.svelte'
</script>
<script>
import { Link } from '@inertiajs/svelte'
</script>
<p>This is page one.</p>
<p>Go to <Link href="/page2">Page two</Link></p>
Page two ./resources/js/Pages/PageTwo.svelte:
<script context="module">
export { default as layout } from './AppLayout.svelte'
</script>
<script>
import { Link } from '@inertiajs/svelte'
</script>
<p>This is page two.</p>
<p>Go to <Link href="/page1">Page one</Link></p>
Steps to reproduce:
Run npm run dev or npm run build and php artisan serve
If I open page one in the browser /page1, everything works as expected. The user is marked as unknown.
Then I click on the link to page two. Everything also works correctly. The user is honza as expected.
After that I click on the link to page one and nothing happens. Inertia crashes.
I found that if a prop is not an object, but only a string Inertia will not crash.
Version:
@inertiajs/svelte
version: 1.0.15Describe the problem:
If I put a prop into Layer and this prop is not sent from the server, Intertia crashes and stops working. It crashes even if the default value is set in Svelte.
Laravel source code:
Laravel routes file
./routes/web.php
:Layout file
./resources/js/Pages/AppLayout.svelte
:Page one
./resources/js/Pages/PageOne.svelte
:Page two
./resources/js/Pages/PageTwo.svelte
:Steps to reproduce:
npm run dev
ornpm run build
andphp artisan serve
/page1
, everything works as expected. The user is marked as unknown.I found that if a prop is not an object, but only a string Inertia will not crash.