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

Add ability to handle deferred props #1617

Closed
wants to merge 1 commit into from

Conversation

adrum
Copy link

@adrum adrum commented Jul 23, 2023

This works in tandem with inertiajs/inertia-laravel#531. This is the client-side implementation of this feature. These deferred properties will only ever be loaded automatically after page loads/navigations. Otherwise, they behave just the same as Lazy props.

See the previously mentioned PR for more details.

@reinink
Copy link
Member

reinink commented May 27, 2024

Hey! Thanks so much for this contribution, and my apologies on not responding earlier.

We've been talking more about "deferred" props as an internals team lately, and while I really like the idea, I don't think this is quite the way to implement it. Here's the concern I shared:

Just thinking more about the "deferred" props which work basically the same as a lazy prop except they are automatically loaded instead of having to do a manual partial reload (correct me if I’m wrong on this definition @lepikhinb), but I actually don’t think we should use a regular inertia request for these.

All inertia request are synchronous — which is of course by design, they are meant to mimic classic browser page visits. Meaning if you’re making an Inertia visit, and then click during that visit to another page, the first request is cancelled and the second request takes over.

However, for a long time I’ve wanted to add some type of async requests to Inertia for special situations — in particular for polling. Right now if you do an Inertia visit in some type of setInterval you run the risk of visit stomping, where a user might click to go to another page, that request starts loading, but a polling request happens to get fired right after and it cancels the user initiated page visit.

You could just use fetch/ajax and a regular JSON endpoint to do the polling and avoid this whole issue. However, it's really nice to just use Inertia, since all your props automatically update (the whole beautiful thing of Inertia).

This is why I’d love to come up with a solution for asynchronous Inertia requests. Basically they would be normal Inertia requests, but they wouldn’t ever cancel other Inertia visits…plus they potentially would only ever be used for making requests to the same page component — need to work out some details here yet.

But, what I’m getting at with all this is that the deferred props should probably be loaded asynchronously. Which means we might need to build the async feature before building the deferred props feature.

So given all that I'm going to close this PR, just because I want to try and tackle it once we've added some type of support for async visits to Inertia.js.

Fortunately if you do want to implement this using router.reload() you can quite easily do this yourself by simply calling this when your page component first mounts:

<script setup>
import { router } from '@inertiajs/vue3'
import { onMounted } from 'vue'

defineProps({ users: Array })

onMounted(() => {
  router.reload({ only: ['users'] })
})
</script>

I hope that makes sense @adrum! I do like the idea of this feature 👍

@reinink reinink closed this May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants