inertiajs / inertia

Inertia.js lets you quickly build modern single-page React, Vue and Svelte apps using classic server-side routing and controllers.
https://inertiajs.com
MIT License
6.02k stars 405 forks source link

[1.1.0] Partial reload sets all $page props to undefined #1883

Closed fragkp closed 3 weeks ago

fragkp commented 1 month ago

Version:

Describe the problem:

When updating from 1.0.6 to 1.1.0 unexpectedly the behavior of $page props has changed. It will set all page props to undefined when a partial reload with only is called.

Steps to reproduce:

<template>
    <h1>{{ $page.props.user.name }}</h1>
</template>

<script setup>
    onMounted(() => {
        router.reload({
            only: ['some-prop'],
        });
    });
</script>

The user page prop is now undefined! It affects not only props in templates but also when usePage() is used.

reinink commented 1 month ago

Hey! I just tried to reproduce this issue and wasn't able to. Both the page props passed to the page component, as well as the $page.prop property and usePage() values were all still set after doing a partial reload.

You can see my test here:

https://github.com/inertiajs/inertia/blob/issue-1883/playgrounds/vue3/resources/js/Pages/Users.vue

We did recently make some changes to how partial reloads work (see #1876 and #1877), so it's entirely possible that there is some situation we didn't account for, but I am unable to reproduce it.

Are you able to provide a minimal reproduction of this issue using this Vue 3 playground?

fragkp commented 1 month ago

Will create a playground later today 😃

Thanks for your quick response!

reinink commented 1 month ago

Awesome, thanks!

fragkp commented 1 month ago

Unfortunately, I can't reproduce it on your playground (maybe, because we rely heavily on nested layouts with parameters?), but I found our mistake:

On our reload call

router.reload({ only: ['some-prop'] });

some-prop is not passed to the view:

inertia('Page', array_merge([], $active ? [
    'some-prop' => 'value',
] : [
    // missing
]))

On 1.0.6, when missing some-prop will be null. On 1.0.0 it completely wipes the page props for some reason.

I'm unsure if it is a bug in the new version if inertia or some weird hack on our codebase.

reinink commented 3 weeks ago

Hey I think we've fixed this now in v1.2.0 👍

fragkp commented 2 weeks ago

@reinink Testet it. Works as before. Thanks 😄