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

Issues with Svelte 4 #1621

Closed
punyflash opened this issue Jul 26, 2023 · 22 comments · Fixed by #1763
Closed

Issues with Svelte 4 #1621

punyflash opened this issue Jul 26, 2023 · 22 comments · Fixed by #1763
Assignees
Labels
svelte Related to the svelte adapter

Comments

@punyflash
Copy link
Contributor

Version:

  • @inertiajs/svelte version: 1.0.9
  • svelte version: 4

Describe the problem:

When using Svelte 4, props are not being populated on inertia router visits. Also when adding svelte-eslint to the project pages are completely empty after visit.

Steps to reproduce:

Just make a visit using inertia link or router to the route that requires any props

@punyflash punyflash added the svelte Related to the svelte adapter label Jul 26, 2023
@reinink
Copy link
Member

reinink commented Jul 28, 2023

Hey! I am not able to reproduce this issue. We actually have a Svelte playground included in the project, which is on Svelte 4.x, and I just tested it and it works fine:

https://github.com/inertiajs/inertia/tree/master/playgrounds/svelte

I am going to close this issue for now, but feel free to provide us with a minimal reproduction of the issue you're experiencing as a Git repo and we can have another look 👍

@reinink reinink closed this as completed Jul 28, 2023
@punyflash
Copy link
Contributor Author

@reinink here is an example repository: https://github.com/punyflash/inertia-test.

A bit detailed explanation

I created 2 pages: /page/1 and page/2 to show how it works. It seems like page is not being updated after persistent layout change

Page 1

<script lang="ts" context="module">
    // import LayoutInsideTag from "@/components/LayoutInsideTag.svelte";
    import LayoutOutsideTag from "@/components/LayoutOutsideTag.svelte";

    export const layout = [LayoutOutsideTag];
</script>

<script lang="ts">
    import { fade } from 'svelte/transition';
    import { inertia } from "@inertiajs/svelte";
    export let title = '';
    export let data = '';
</script>

<svelte:head>
    <title>{title}</title>
</svelte:head>

<section in:fade>
    <h1 class="text-3xl">{title}</h1>
    <div>{data}</div>
    <a href="/page/2" class="underline" use:inertia>Go to page 2</a>
</section>

Page 2

<script lang="ts" context="module">
    // import LayoutOutsideTag from "@/components/LayoutOutsideTag.svelte";
    import LayoutInsideTag from "@/components/LayoutInsideTag.svelte";

    export const layout = [LayoutInsideTag];
</script>

<script lang="ts">
    import { fade } from 'svelte/transition';
    import { inertia } from "@inertiajs/svelte";
    export let title = '';
    export let data = '';
</script>

<svelte:head>
    <title>{title}</title>
</svelte:head>

<section in:fade>
    <h1 class="text-3xl">{title}</h1>
    <div>{data}</div>
    <a href="/page/1" class="underline" use:inertia>Go to page 1</a>
</section>

Expected behavior (Svelte 3)

7AIMHyKTie

Actual (Svelte 4)

ufp6GbXL7f

@reinink
Copy link
Member

reinink commented Aug 29, 2023

@punyflash Thanks for sharing!

@bbauti
Copy link

bbauti commented Sep 13, 2023

Hey! any updates on this?

@pedroborges
Copy link
Collaborator

Hey @punyflash, thanks for reporting this bug. At my company we were upgrading to Svelte 4 and ran into the same issue with persistent layouts. My coworker found your issue and confirmed it using the Svelte playground.

I was able to identify that this issue started happening in Svelte v4.1.1. The solution for now is to force Svelte v4.1.0.

I won't have time to work on a fix in the next two weeks. When I get a chance I will try to determine if this is a bug on our side or Svelte's.

On our side it could be related to the key part of this each block 🤷‍♂️

cc/ @bbauti

@rkyoku
Copy link

rkyoku commented Oct 23, 2023

Hi there,

A nice fellow on Discord sent me here, kudos to him/her!

I can confirm the bug with both versions 4.1.1 and 4.1.0 of Svelte, although the behavior is different.

On version 4.1.1 the main <slot/> never gets updated after a redirect (login/logout), although the layout is updated (and so are the props used in the layout, e.g. my <h1> tag). I have to refresh (F5) the page for the main slot to be updated again.

On version 4.1.0 it works better, but still fails if I do the login from a page other than /, in which case the props are not passed to the template, and I get errors like "#each should only be used on iterables" things like that.

Downgrading to Svelte 4.0.0 works properly for me! I'll stick to version 4.0.0 until things are fixed on either side.

Good luck with this bug, and thanks for this great tool!

Best,

@Josefikos
Copy link

svelte v5 won't work too

@delordemm1
Copy link

svelte v5 won't work too

Damn, i thought it was from my end, battled this for hours 🥲

@punyflash
Copy link
Contributor Author

As it seems the package is dead and most of crucial PRs are hanging for almost a year (#1614, #1763, #1635), I created my own adapter for Svelte with typescript support and some issues fixed regarding styles and props loading. You are free to use it: https://github.com/westacks/inertia-svelte. You can natively replace the inertia adapter, and it will work as it is.

@vitalijalbu
Copy link

vitalijalbu commented Jan 30, 2024

Cool, what makes the maintainer of this library not update it anymore? At least can the public make pr?

@harryqt
Copy link

harryqt commented Feb 2, 2024

You are free to use it: https://github.com/westacks/inertia-svelte. You can natively replace the inertia adapter, and it will work as it is.

@punyflash How do I install it?

@punyflash
Copy link
Contributor Author

@punyflash How do I install it?

npm i @westacks/inertia-svelte

@punyflash
Copy link
Contributor Author

I am getting errors (not using TS).

Update package to 1.0.20, it should work now even if you don't use typescript

@harryqt
Copy link

harryqt commented Feb 4, 2024

Thank you, it works now. 👍

If you don't mind, can you take a look at issue #1785

@joshstobbs
Copy link

@Dibbyo456 I put in a PR over at the westacks repo that solves the unknown prop issue. Still trying to sort through the unexpected slot part but I'm not too sure where that's coming from, will keep this updated if I can figure it out.

@harryqt
Copy link

harryqt commented Feb 17, 2024

@joshstobbs thanks for the PR. FYI, when using Svelte 5 the warning do not appear.

@joshstobbs
Copy link

Oh that’s really cool @Dibbyo456! I haven’t actually been able to get Inertia to work with Svelte 5, any chance you have an example repo?

@harryqt
Copy link

harryqt commented Feb 20, 2024

Just follow this guide, unfortunately SSR is broken #1801 😕

@driesvints
Copy link
Contributor

Seems a PR was sent in for this: #1763. Let's see how it goes. Thanks all.

@reinink
Copy link
Member

reinink commented Apr 16, 2024

Hey folks! Just merged in #1763 — let's hope this is all resolved now. Will try and get a release out shortly 👍

@reinink
Copy link
Member

reinink commented Apr 16, 2024

This fix has been released as part of v1.0.16 👍

@nairboon
Copy link

nairboon commented Aug 3, 2024

Just follow this guide, unfortunately SSR is broken #1801 😕

This guide from @danmatthews seems to have moved to this url: https://danmatthews.me/posts/you-can-use-svelte-v5-with-inertiajs-really-easily-today-bf9de

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

Successfully merging a pull request may close this issue.