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

Old page receives new page's props before swapping #2151

Open
mattwigham opened this issue Dec 24, 2024 · 3 comments
Open

Old page receives new page's props before swapping #2151

mattwigham opened this issue Dec 24, 2024 · 3 comments
Assignees
Labels
svelte Related to the svelte adapter

Comments

@mattwigham
Copy link

Version:

  • @inertiajs/svelte version: 2.0.0 and 1.3.0
  • svelte version: 5.16.0

Describe the problem:

When navigating from one page to another, the old page component is briefly updated with the new page's props before the new page component is swapped in. This causes undefined errors since the old page doesn't have its expected props any longer.

I'm not sure if this is expected behavior, or if it's specific to Svelte 5. This happens when using $props() and $page.props.

Steps to reproduce:

Create two pages link to each other and each receives unique props.

// One.svelte

<script>
  import { Link } from "@inertiajs/svelte";
  let { propOne } = $props(); // set to "prop-one-value" on the server
  $inspect("One", propOne);
</script>

<Link href="/two">Two</Link>
// Two.svelte

<script>
  import { Link } from "@inertiajs/svelte";
  let { propTwo } = $props(); // set to "prop-two-value" on the server
  $inspect("Two", propTwo);
</script>

<Link href="/one">One</Link>

In the browser, navigate using the links and you'll see the following in the console.

init One prop-one-value
update One undefined
init Two prop-two-value
update Two undefined
init One prop-one-value
...
@mattwigham mattwigham added the svelte Related to the svelte adapter label Dec 24, 2024
@youyoumu
Copy link

i bumped to this issue as well

@kre8or69
Copy link

I'm seeing this issue as well upgrading my app from pre 1.0 versions! Haven't been able to nail down which version has caused the bug though!

@kre8or69
Copy link

Was able to track down that the cause of this is indeed in the "@inertiajs/svelte": "1.3.0" release! I believe linked to this PR which changes things to support props being updated correctly when rendering the same component (allowing component reuse rather than re-rendering) #1969.

Seeing the same behavior where the props are updated and applied to the existing loaded component before the component is swapped to the new one causing an error upon re-render and skipping rendering the expected component all together.

Unsure how to test this further though as I'm not sure if its my setup is wrong or the changes just don't cover my use case!

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

No branches or pull requests

4 participants